Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2994454pxj; Sun, 6 Jun 2021 22:26:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxc1X9tIlH9nySAD6adgqqE8TNIoV361XG2FAZPRWiDczYVPVLWJ7ZuM5DFv2zvmrfRvcZq X-Received: by 2002:a17:906:b748:: with SMTP id fx8mr16726813ejb.477.1623043615473; Sun, 06 Jun 2021 22:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623043615; cv=none; d=google.com; s=arc-20160816; b=t0Luvs2kGhyRbtKCjQU+ZG9MX+BjVj2XsE/HBMaruX1MzNzFdMmDVnE/puYYI3B3Dp 4T7Yg6Y0iD8TCnej1Kvrzz9351G8N3rJ2+YmFTCIri6DF9i8Gi9lAUq/IGyolHApXEqd DlLdfafzjSiXXZoYikEUj8k8nJREtwvCDPeduuzDOYhGoj5nXBF1dMnp4kQpgA00f1YJ d5ua+NcIOso/rg77FasKJaoNqG8+xba1K7NXjlgRxvqDG0tx3l27jGIRo33DAVjuQlRL oJFo8uVR7RsncF+Pqw1CQItg+TnPaP0aGXWIO1zVUiee4n5KFw8Mq3b4rsBPVSGTQE+n 9CnQ== 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=5MRPWvbKZE3GX3grOQTqDnKaCaY+jfWm++ZnVxVvmPo=; b=DF6Xd/JMWxppTBRQZTVvSHCqAmiBP13Q19ehA2Jw+R+OR4smL8W2sGXMX0dQDttOeg LQZDwyvQDpRzkpglzlbXqW6sWMSVIu6KpKhwSeBy52aDerPDqXP6TvzS7GBRqQJ4zIbj tk8wDIuzthEzPGGalXlpXTKzoqRZl2Ij08DUS6evxJNPLngsRz4yS54xm9VzIYzw6dFm DdtooI76LDEZFLHnuxssyGf+D5sbIdIHHuN/VGuS/mspNkiPKTT1AFk8CdhGyTNi4//K lI8ydlPHcfvH+0qAqUIrbXlJ23yS+OYEk5INNV6XzUPP9J9j0G2rE8KIL9G9JpDGouOr V8ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=XK4QdSXh; 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 w6si9477963edl.187.2021.06.06.22.26.33; Sun, 06 Jun 2021 22:26:55 -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=XK4QdSXh; 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 S230155AbhFGF0q (ORCPT + 99 others); Mon, 7 Jun 2021 01:26:46 -0400 Received: from ozlabs.org ([203.11.71.1]:47783 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbhFGF0q (ORCPT ); Mon, 7 Jun 2021 01:26:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4Fz1yt10WVz9sT6; Mon, 7 Jun 2021 15:24:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1623043494; bh=Q0ZAhkp7FWQOcYxPVObgHiqPp39qCkjQY7r+Qe59/6A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XK4QdSXh+s20cVuUWTtzi8COPKgAo/qyMsQvlJ+ez0bh/V5dMND5DAp4oiQwFwR2k ug/yiJ30A80nCG5Q8mHWJmA590AcTbbo9vJcoNcgQ3KZDjFiBMaNCYnLeKcIRhEJUG qffgrXCubOapMfwgHDHVG8L3+Yf2QaFPDbHPSBL4= Date: Mon, 7 Jun 2021 15:10:00 +1000 From: David Gibson To: Leonardo Bras Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Sandipan Das , Mike Rapoport , Andrew Morton , "Aneesh Kumar K.V" , Nicholas Piggin , Nathan Lynch , David Hildenbrand , Scott Cheloha , Laurent Dufour , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] powerpc/mm/hash: Avoid multiple HPT resize-ups on memory hotplug Message-ID: References: <20210430143607.135005-1-leobras.c@gmail.com> <20210430143607.135005-3-leobras.c@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+e3T6L8B4PjNfYWV" Content-Disposition: inline In-Reply-To: <20210430143607.135005-3-leobras.c@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --+e3T6L8B4PjNfYWV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 30, 2021 at 11:36:08AM -0300, Leonardo Bras wrote: > Every time a memory hotplug happens, and the memory limit crosses a 2^n > value, it may be necessary to perform HPT resizing-up, which can take > some time (over 100ms in my tests). >=20 > It usually is not an issue, but it can take some time if a lot of memory > is added to a guest with little starting memory: > Adding 256G to a 2GB guest, for example will require 8 HPT resizes. >=20 > Perform an HPT resize before memory hotplug, updating HPT to its > final size (considering a successful hotplug), taking the number of > HPT resizes to at most one per memory hotplug action. >=20 > Signed-off-by: Leonardo Bras Reviewed-by: David Gibson > --- > arch/powerpc/include/asm/book3s/64/hash.h | 2 ++ > arch/powerpc/mm/book3s64/hash_utils.c | 20 +++++++++++++++++++ > .../platforms/pseries/hotplug-memory.c | 9 +++++++++ > 3 files changed, 31 insertions(+) >=20 > diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/inc= lude/asm/book3s/64/hash.h > index d959b0195ad9..fad4af8b8543 100644 > --- a/arch/powerpc/include/asm/book3s/64/hash.h > +++ b/arch/powerpc/include/asm/book3s/64/hash.h > @@ -255,6 +255,8 @@ int hash__create_section_mapping(unsigned long start,= unsigned long end, > int nid, pgprot_t prot); > int hash__remove_section_mapping(unsigned long start, unsigned long end); > =20 > +void hash_batch_expand_prepare(unsigned long newsize); > + > #endif /* !__ASSEMBLY__ */ > #endif /* __KERNEL__ */ > #endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */ > diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book= 3s64/hash_utils.c > index 608e4ed397a9..3fa395b3fe57 100644 > --- a/arch/powerpc/mm/book3s64/hash_utils.c > +++ b/arch/powerpc/mm/book3s64/hash_utils.c > @@ -859,6 +859,26 @@ int hash__remove_section_mapping(unsigned long start= , unsigned long end) > =20 > return rc; > } > + > +void hash_batch_expand_prepare(unsigned long newsize) > +{ > + const u64 starting_size =3D ppc64_pft_size; > + > + /* > + * Resizing-up HPT should never fail, but there are some cases system s= tarts with higher > + * SHIFT than required, and we go through the funny case of resizing HP= T down while > + * adding memory > + */ > + > + while (resize_hpt_for_hotplug(newsize, false) =3D=3D -ENOSPC) { > + newsize *=3D 2; > + pr_warn("Hash collision while resizing HPT\n"); > + > + /* Do not try to resize to the starting size, or bigger value */ > + if (htab_shift_for_mem_size(newsize) >=3D starting_size) > + break; > + } > +} > #endif /* CONFIG_MEMORY_HOTPLUG */ > =20 > static void __init hash_init_partition_table(phys_addr_t hash_table, > diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/power= pc/platforms/pseries/hotplug-memory.c > index 8377f1f7c78e..48b2cfe4ce69 100644 > --- a/arch/powerpc/platforms/pseries/hotplug-memory.c > +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > =20 > #include > #include > @@ -671,6 +672,10 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add) > if (lmbs_available < lmbs_to_add) > return -EINVAL; > =20 > + if (!radix_enabled()) > + hash_batch_expand_prepare(memblock_phys_mem_size() + > + lmbs_to_add * drmem_lmb_size()); > + > for_each_drmem_lmb(lmb) { > if (lmb->flags & DRCONF_MEM_ASSIGNED) > continue; > @@ -788,6 +793,10 @@ static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u= 32 drc_index) > if (lmbs_available < lmbs_to_add) > return -EINVAL; > =20 > + if (!radix_enabled()) > + hash_batch_expand_prepare(memblock_phys_mem_size() + > + lmbs_to_add * drmem_lmb_size()); > + > for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { > if (lmb->flags & DRCONF_MEM_ASSIGNED) > continue; --=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 --+e3T6L8B4PjNfYWV Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmC9qicACgkQbDjKyiDZ s5Jdqw//RczgBrNyU1kIqVO7/FiFsNT63ohCuxllQ8p7j075vP50I4I/e3GUovQB DRLF2Zv3OOVxqhU7AEDxGAFj7wOzMoGrvuEAn8vRoilpL9SK1XzWzl71uVi6jE3W LfL+LVoP6rL/Aqp/LapU0E2GVDQWiBhckSFP7cEoy1eO1VlPZu/o2NbzIXo6rSf2 rLIV8lubVuJjx5EPvmwUUrZG/kfmCOeZ7Fu2ym1VzFoj54JZppHLs6BZoDE4oSUa d15AV4LtAMyIPbYzPFEw5q3QfYbo1tLdYJ7blPkFGlYYtERtmGidtqlDIf9+yu+D Zr04CtmgA3IB0aW8OHJkHCpgovqQ0xwvFHxnNx9Ta59J5+qgLV1wHPDM7JgrW5bW mI0KFgE1uKcVK+T00TGNK1r8qiuwbQEWBcx0GrtoC1/wYt5f7AlNUJHhEZsUKcaN jYUOw9roHR+m+ccnkGvLTQb/OCkshLld/xdj5NBhKyc479dFQ8w6Wonx/c01O+9S nkunjt22DOumTWONk01cSYAzRCmdsaMOktfNITqxp8XU26DNsJdBiyOCvwZG8ieu Gl+QFaQD4PO+AHxWCP6upQzlHedgxU9WoYyQN+VP8NX1kJVBsGfcuq9neMyqDcR+ obFfkY8ODfoFq8focOl3j9GZuA62bsCy7J5d7M/OqLkAtEX/z8s= =OPXK -----END PGP SIGNATURE----- --+e3T6L8B4PjNfYWV--