Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2194772pxb; Sun, 18 Apr 2021 22:44:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg8PHODhbkpW27AXROY1AV/d+2jk0x6ScBLBlH9WqFTgOp69XBST9uj2yvLY8DMf0kDFu2 X-Received: by 2002:a17:902:b68c:b029:eb:6c82:60da with SMTP id c12-20020a170902b68cb02900eb6c8260damr21748164pls.25.1618811085730; Sun, 18 Apr 2021 22:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618811085; cv=none; d=google.com; s=arc-20160816; b=BjrhIlzMTKSfw7sdl8N/YhaUZVMhc8LjjsR9SAK71tXsf5/9XwtPpAOQzG0QgsUGD0 xpYu1afblM4Ns7d2m70+rRLOje1Xp0KX4SE32aa8cgFX1Bc6dVv2QFaPaSMkdvTnCEZc /tXjMXdyDYfMAO1e6ftYi6R1W//GaS5mXTlTL9Tbu4oD5NSC6rd/eqedQ05g7cl6lKV1 P5eeMX1s40RFJm1FVo8cVWsDUTwJ96uncDq7+gZ46renWOi1sDHB3QTTjDemySz6vKnK WBgmIQyRfh0sFP1gBPKG21K3kStFw2ldSkI5DSvHZzhpq9I+3rbugFX/bOFT2yfcxCh1 gbUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wofL3xF/9+g7yzfxVlI1YDQz2itFegg5gGdxwCuMYAE=; b=DSlHeZ6JqhOm28f13H7iAkIemYGvvAa7cN8XHDHxL5LdUjppnvd4DgRg4ggGM6EtS5 GQi+T/ikZANaGsIJVlH3qCMvf4vDJGw4HfNTd5Abnjm3BELSIPZuOWmCwylT+IDnxNFj 95iFzoyTlPo79bCq904ntleXXnT2csOE9x+eb42l6IGp5O1xeHROvy2JfzH/aXpIhBrX QjaaGJ9rUELlzsooU0F8FQXJFu412BFrz/N7SGAHI+dYTrGgsKJHJYb8140Mcj8Nwei7 w9/pmvpyTYZuwrUz6H28Dw0EsenF2YmYJIyMVn6Z995CsaoCc3R42tXeE1TeWQLHoW1m Ktaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=p3cfQPwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si16215988pjm.38.2021.04.18.22.44.31; Sun, 18 Apr 2021 22:44:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=p3cfQPwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbhDSFiT (ORCPT + 99 others); Mon, 19 Apr 2021 01:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbhDSFiS (ORCPT ); Mon, 19 Apr 2021 01:38:18 -0400 Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F61C06174A for ; Sun, 18 Apr 2021 22:37:49 -0700 (PDT) Received: by ozlabs.org (Postfix, from userid 1007) id 4FNwZM15p1z9vFP; Mon, 19 Apr 2021 15:37:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1618810667; bh=QTO/JmKonyWowSuB9ptog568D8fxSsKUTGolY+teoLw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=p3cfQPwGqHiIebmsm3t1zK9po09rMyOJ5XhAri8tMCywYbjZnmvwsuIVuS6H+RIe2 ec0NJn6aE1DXx8vlI/TLncnMzVc99JPrQMXaeko5Dp8YpM4NgYEaIFq/R8di1Sl/eo FLo9evkxzsb7fftYNHnTGJVeQXQvF5/nIsmCfDOM= Date: Mon, 19 Apr 2021 15:37:41 +1000 From: David Gibson To: Leonardo Bras Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Andrew Morton , Sandipan Das , "Aneesh Kumar K.V" , Logan Gunthorpe , Mike Rapoport , Bharata B Rao , Dan Williams , Nicholas Piggin , Nathan Lynch , David Hildenbrand , Laurent Dufour , Scott Cheloha , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] powerpc/mm/hash: Avoid multiple HPT resize-downs on memory hotunplug Message-ID: References: <20210312072940.598696-1-leobras.c@gmail.com> <20210312072940.598696-4-leobras.c@gmail.com> <418f044aab385389681529b0b6057e75825b0e5f.camel@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cd90VBRJ04ikWx9V" Content-Disposition: inline In-Reply-To: <418f044aab385389681529b0b6057e75825b0e5f.camel@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --cd90VBRJ04ikWx9V Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 09, 2021 at 12:31:03AM -0300, Leonardo Bras wrote: > Hello David, thanks for commenting. >=20 > On Tue, 2021-03-23 at 10:45 +1100, David Gibson wrote: > > > @@ -805,6 +808,10 @@ static int resize_hpt_for_hotplug(unsigned long = new_mem_size, bool shrinking) > > > =A0 if (shrinking) { > > >=20 > > > + /* When batch removing entries, only resizes HPT at the end. */ > > > + if (atomic_read_acquire(&hpt_resize_disable)) > > > + return 0; > > > + > >=20 > > I'm not quite convinced by this locking. Couldn't hpt_resize_disable > > be set after this point, but while you're still inside > > resize_hpt_for_hotplug()? Probably better to use an explicit mutex > > (and mutex_trylock()) to make the critical sections clearer. >=20 > Sure, I can do that for v2. >=20 > > Except... do we even need the fancy mechanics to suppress the resizes > > in one place to do them elswhere. Couldn't we just replace the > > existing resize calls with the batched ones? >=20 > How do you think of having batched resizes-down in HPT? I think it's a good idea. We still have to have the loop to resize bigger if we can't fit everything into the smallest target size, but that still only makes the worst case as bad at the always-case is currently. > Other than the current approach, I could only think of a way that would > touch a lot of generic code, and/or duplicate some functions, as > dlpar_add_lmb() does a lot of other stuff. >=20 > > > +void hash_memory_batch_shrink_end(void) > > > +{ > > > + unsigned long newsize; > > > + > > > + /* Re-enables HPT resize-down after hot-unplug */ > > > + atomic_set_release(&hpt_resize_disable, 0); > > > + > > > + newsize =3D memblock_phys_mem_size(); > > > + /* Resize to smallest SHIFT possible */ > > > + while (resize_hpt_for_hotplug(newsize, true) =3D=3D -ENOSPC) { > > > + newsize *=3D 2; > >=20 > > As noted earlier, doing this without an explicit cap on the new hpt > > size (of the existing size) this makes me nervous.=A0 > >=20 >=20 > I can add a stop in v2. >=20 > > Less so, but doing > > the calculations on memory size, rather than explictly on HPT size / > > HPT order also seems kinda clunky. >=20 > Agree, but at this point, it would seem kind of a waste to find the > shift from newsize, then calculate (1 << shift) for each retry of > resize_hpt_for_hotplug() only to point that we are retrying the order > value. Yeah, I see your poiint. >=20 > But sure, if you think it looks better, I can change that.=20 >=20 > > > +void memory_batch_shrink_begin(void) > > > +{ > > > + if (!radix_enabled()) > > > + hash_memory_batch_shrink_begin(); > > > +} > > > + > > > +void memory_batch_shrink_end(void) > > > +{ > > > + if (!radix_enabled()) > > > + hash_memory_batch_shrink_end(); > > > +} > >=20 > > Again, these wrappers don't seem particularly useful to me. >=20 > Options would be add 'if (!radix_enabled())' to hotplug-memory.c > functions or to hash* functions, which look kind of wrong. I think the if !radix_enabled in hotplug-memory.c isn't too bad, in fact possibly helpful as a hint that this is HPT only logic. >=20 > > > + memory_batch_shrink_end(); > >=20 > > remove_by_index only removes a single LMB, so there's no real point to > > batching here. >=20 > Sure, will be fixed for v2. >=20 > > > @@ -700,6 +712,7 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_= add) > > > =A0 if (lmbs_added !=3D lmbs_to_add) { > > > =A0 pr_err("Memory hot-add failed, removing any added LMBs\n"); > > >=20 > > > + memory_batch_shrink_begin(); > >=20 > >=20 > > The effect of these on the memory grow path is far from clear. > >=20 >=20 > On hotplug, HPT is resized-up before adding LMBs. > On hotunplug, HPT is resized-down after removing LMBs. > And each one has it's own mechanism to batch HPT resizes... >=20 > I can't understand exactly how using it on hotplug fail path can be any > different than using it on hotunplug. > >=20 >=20 > Can you please help me understanding this? >=20 > Best regards, > Leonardo Bras >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --cd90VBRJ04ikWx9V Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmB9FyUACgkQbDjKyiDZ s5Jd8hAAgYd5VNaWzqV/Ubm2ANlWLkjy5xitcPE1T0TgOc5cC0lhocQGs+l+Pa/f Wf8GIzdddlJ61eS/SXSEPzVaw6cMAXfZ9SQ8XWOXOw/RGollDm8h4inGkWdnZ/o9 1P5VG4/F9lKzUtkEyqe9ztlqdy0bqmd1lts+BRfQSsEbuFUe8XSECpvM/COC7g85 w0EDiCGYYArIDNb/1tm3X2/glA89xmg0xt2Fv1d0uDrMDfDNhoR4Kx+UkvqPRbeO S7/Y8Av9o8wlIUk+oojpUaJdHWeIsBvRfFYmEZsQw1nGIJQsUn0NC5XV6/36AZkr lb2JPojicBDu/bsHixkQojtdxk8i+ibxPqco1CI3++Dhs+5GxHsxZkVnH1PC8cpW 7Oy/nK0VDSoGU5oxKlObv9eNCb9Wkepjkdtvl+6Bb1I/fJiklBivyVctGyC4enko XOH7fGJ11jFUgtozJGqdpWT5IC1bfPn0T8Unuk5IFvlueBiD2LMx17y9yTNe+x3Y 30GBg1Yc78juzklG2YcH9dRuHzhiDUtXdW+RnSz5l6gjyUh0Ow40mW+ltcSd+P+H NWzKtqvFzsws67JgE9b4BH29l0wxF0Y3qKZF1z+RL+mtrBQCJq54XTJNcuSHX/bL TizB/SolcPju36R48/V4iVCLQ5T1cKusyomknNWtqwWhzaHRvMQ= =OcHV -----END PGP SIGNATURE----- --cd90VBRJ04ikWx9V--