Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp391626pxy; Fri, 30 Apr 2021 07:37:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPLT0ebdAqlqfJvlIGStOkS5Dm2nIffFdHusLw4OveYfoVKhzPaSUwbBYQ4C4l3IRtsPKe X-Received: by 2002:a62:f90d:0:b029:250:5397:4658 with SMTP id o13-20020a62f90d0000b029025053974658mr5198688pfh.48.1619793460361; Fri, 30 Apr 2021 07:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619793460; cv=none; d=google.com; s=arc-20160816; b=ONBBpEKwUDdwNpb3mokfb46kAmPFVN/v0krfjycyEJC5Qs1tJGFoMvNbmqKlvzSgp8 PiF/mpiSlvDBsAncrYh14f2qCpmFqFhKHRKrLagV3b5fgZFJU+gF16H4X8SIEk5EjF7B RnFdYnRzhA1In5XdwI9btNvHIlLp64Pcgins69aZ0ghV94AEoKyhSxbRTiTmb+L89zIS +U7gnQ84cTeW42t4L96GDFx+b77ooPsuHQgHSTexP2EJ6VhfXglzbl6XTMCk1gaidM80 SAjlMObzm9oeEVnyBJ0ySHeQWRjrTsgkuOe0ArTxBLWAQKp9O9qFm+TL6KCu3v6wnbiv PvWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=alyS840WpTY55RdF+7Kqh/069+/rmbTaDiI+qnnTJwM=; b=gNtVZSOVxiHZC1Jqdqs4L4hklsYXZo2CdSzT4kcvq+q9es1ee9wRpb8sntVXukJE5p c48Dvk8zlJvNv0bVcwZOdkSpXEx1gYWnacPIwCSxsQE7QMLlrQVWgYIedt/6dSORr7Op rfZNN+fATRmlt6Z8ou3UaFq9d0o/f/lVAvsGRVjxEm3KSJAwmZ7nwgvuoiDMHr4ElM5I E79tJFAsmXQj+VKLTWxDA74zW85QjWg9kDSqB1T54N1+e+uW65UYAnxKH1xMgbkq/P+C 2sBMyXVVFF1D5eGJI54QK2TrfCEYBOAhgBrrNo1ywC1PMkBdGzvd1dWgjcmD56l5p1ls vg4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c8VZuzhH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si14429225pjg.166.2021.04.30.07.37.27; Fri, 30 Apr 2021 07:37:40 -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=@gmail.com header.s=20161025 header.b=c8VZuzhH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232885AbhD3Ohf (ORCPT + 99 others); Fri, 30 Apr 2021 10:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbhD3Ohe (ORCPT ); Fri, 30 Apr 2021 10:37:34 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22BBEC06174A for ; Fri, 30 Apr 2021 07:36:45 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id u20so38688819qku.10 for ; Fri, 30 Apr 2021 07:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=alyS840WpTY55RdF+7Kqh/069+/rmbTaDiI+qnnTJwM=; b=c8VZuzhHSyKUnoyRpry9HnofH2E3TKJSC5Dx7anszw68lOhGBhyzyGz7fRsk0Wtayy WQiWwi6GDC3A8SPS32rdvg9m3/o5XrwEKWzX/CDDrimzSD7zypjo2/Z7FkelKzlfbAQs 8M3hLf8iioo8MjzGBapd1TCJ0NOVNgOP3S0zyRZ5g/VCTnA4vncy/SvAB2IyoQqXwtXt I5THmLp/IHCjGsPhQ5CAouOFAh/v9u9lH9RyRTlupM+oJUsiOv8qAj7kqndH5y6fJuXf RCSbYfGJao1cVYHjKZ6QwWqu3SwbQDa6TfsmgDWLQ05xMRL79jsCiQ4a94wdGgfV3lbn C3CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=alyS840WpTY55RdF+7Kqh/069+/rmbTaDiI+qnnTJwM=; b=ZyBTNhtmLeJnqxq6QaIXsAuTYlQFgOeXKOuoDa5211KLSztHQefjVTQpKSusUJzYt+ RqAn4qpcDkYwzwIWlypKH+AlfPTK+RnOq6Y8HpVDechHaf4rnUy9EAsp9z3kMP9scS04 FCM+lQr7XyZyMMrVE+gNuXv/+G8x7vhvoVu9xFqycM+uL/4PpEUfGcmSOkmepfYkZ/yl d68CtYfasXVF8g8C1R5UTFRGXM+GYnqgB4LGEizerhqia6/hclgGitPhLNG/u07Svo2L JadGyTYRiZ0r/rQB06oJ8V6Iek8RfzfMXrujjSyMA/M5s31u0KB3VTokUvyO9zFwMKPx Y3mw== X-Gm-Message-State: AOAM533en16vyzcyoc9DC2Ca9eY2ZbuI9AIlFPG+QqwNJaWQd9Y78zWM yl10oJiLv6kkhDX606Orr0w= X-Received: by 2002:a37:688:: with SMTP id 130mr5759408qkg.499.1619793404447; Fri, 30 Apr 2021 07:36:44 -0700 (PDT) Received: from li-908e0a4c-2250-11b2-a85c-f027e903211b.ibm.com.com ([2804:14c:482:7b04::1001]) by smtp.gmail.com with ESMTPSA id 190sm1532560qki.115.2021.04.30.07.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 07:36:44 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Leonardo Bras , Sandipan Das , Mike Rapoport , Andrew Morton , "Aneesh Kumar K.V" , Nicholas Piggin , Nathan Lynch , David Hildenbrand , Scott Cheloha , Laurent Dufour Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] powerpc/mm/hash: Avoid resizing-down HPT on first memory hotplug Date: Fri, 30 Apr 2021 11:36:06 -0300 Message-Id: <20210430143607.135005-2-leobras.c@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430143607.135005-1-leobras.c@gmail.com> References: <20210430143607.135005-1-leobras.c@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because hypervisors may need to create HPTs without knowing the guest page size, the smallest used page-size (4k) may be chosen, resulting in a HPT that is possibly bigger than needed. On a guest with bigger page-sizes, the amount of entries for HTP may be too high, causing the guest to ask for a HPT resize-down on the first hotplug. This becomes a problem when HPT resize-down fails, and causes the HPT resize to be performed on every LMB added, until HPT size is compatible to guest memory size, causing a major slowdown. So, avoiding HPT resizing-down on hot-add significantly improves memory hotplug times. As an example, hotplugging 256GB on a 129GB guest took 710s without this patch, and 21s after applied. Signed-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/hash_utils.c | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 581b20a2feaf..608e4ed397a9 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -795,7 +795,7 @@ static unsigned long __init htab_get_table_size(void) } #ifdef CONFIG_MEMORY_HOTPLUG -static int resize_hpt_for_hotplug(unsigned long new_mem_size) +static int resize_hpt_for_hotplug(unsigned long new_mem_size, bool shrinking) { unsigned target_hpt_shift; @@ -804,19 +804,25 @@ static int resize_hpt_for_hotplug(unsigned long new_mem_size) target_hpt_shift = htab_shift_for_mem_size(new_mem_size); - /* - * To avoid lots of HPT resizes if memory size is fluctuating - * across a boundary, we deliberately have some hysterisis - * here: we immediately increase the HPT size if the target - * shift exceeds the current shift, but we won't attempt to - * reduce unless the target shift is at least 2 below the - * current shift - */ - if (target_hpt_shift > ppc64_pft_size || - target_hpt_shift < ppc64_pft_size - 1) - return mmu_hash_ops.resize_hpt(target_hpt_shift); + if (shrinking) { - return 0; + /* + * To avoid lots of HPT resizes if memory size is fluctuating + * across a boundary, we deliberately have some hysterisis + * here: we immediately increase the HPT size if the target + * shift exceeds the current shift, but we won't attempt to + * reduce unless the target shift is at least 2 below the + * current shift + */ + + if (target_hpt_shift >= ppc64_pft_size - 1) + return 0; + + } else if (target_hpt_shift <= ppc64_pft_size) { + return 0; + } + + return mmu_hash_ops.resize_hpt(target_hpt_shift); } int hash__create_section_mapping(unsigned long start, unsigned long end, @@ -829,7 +835,7 @@ int hash__create_section_mapping(unsigned long start, unsigned long end, return -1; } - resize_hpt_for_hotplug(memblock_phys_mem_size()); + resize_hpt_for_hotplug(memblock_phys_mem_size(), false); rc = htab_bolt_mapping(start, end, __pa(start), pgprot_val(prot), mmu_linear_psize, @@ -848,7 +854,7 @@ int hash__remove_section_mapping(unsigned long start, unsigned long end) int rc = htab_remove_mapping(start, end, mmu_linear_psize, mmu_kernel_ssize); - if (resize_hpt_for_hotplug(memblock_phys_mem_size()) == -ENOSPC) + if (resize_hpt_for_hotplug(memblock_phys_mem_size(), true) == -ENOSPC) pr_warn("Hash collision while resizing HPT\n"); return rc; -- 2.30.2