Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5599522rwp; Mon, 17 Jul 2023 06:49:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjUdfNHSue3uthzPI3SPSaoNvTtXvZHWM9zq+aS52mgt+HMBNLM9U05QrNZmZqXKk8jWAp X-Received: by 2002:a92:904:0:b0:347:73b4:9cf6 with SMTP id y4-20020a920904000000b0034773b49cf6mr11073408ilg.23.1689601751345; Mon, 17 Jul 2023 06:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689601751; cv=none; d=google.com; s=arc-20160816; b=VQj8frFLaY4Y12peswF7tR6cAP3KmeD9OlZ1pY4+vI3ZP8MHi1drf6u128YGU4mqaL +D+EZ6JlK+Tb98TGpDYYwBSERhxNQM3YaiVgeJ83n6aLAriAFV3S8gmcXUmdxuTzjI0j GR705OHfKh08jGKWvtfV5zKw3mxU1muJxKk1CUDeQgtc+JV4PgyiifGno0Qaj4PCwp6B b7XsDZXSOiq0XdLgvJ5AATHQ9whQCH67F61GE+x8Re35Tk2o9Z0OCZ1W6JfU4K+XE9M3 KyCgTFme/l2/dLhZ1/aGYMrf3GGBiLy1V/OGukyKU8jHYSUlWxnVS5J4m7YFLYjThxBa K6xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=wVl+SnEq1dRMDhl+TSTNaTHmTkNUdQiSLaiPdr8OJ6c=; fh=jfkW6LUtZoTJXCXRHyROpIaSMlpDOpdlTqhyICkIFAc=; b=QJF2DGb2F48g596im6un+ZD4lNkkxBsky9CuXcDS1BD3o75sPYaSv0Eo49iqiquEzs VpR966plo3ZgEx51TtTIvW0/Ys2jgczEC+3G2Oqjkfj7NcelI0Oj/uREkBfO7HZ0JHTP PLdiKrYwCJ7UAjarbI1f/rkJq4aZibf9/OdNrb9YbaRW6qSIcE0ff+BMzAtPWV+X1H9l 0udxfGswbnglHtP1yPVW1T/JquA24/2vhZLzTnemF7NJvKAsF8zZmfb/BMBpQTkNB+XP uYdW5EKx0M+0PxSx/uHedQ8eOW8Q+hfga9zd6sowNFlF8HhEenqXPq5TZoLF02ry4wM6 dTXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gm9-20020a17090b100900b0025e7ff46234si5727246pjb.57.2023.07.17.06.48.58; Mon, 17 Jul 2023 06:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbjGQNVl (ORCPT + 99 others); Mon, 17 Jul 2023 09:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbjGQNV2 (ORCPT ); Mon, 17 Jul 2023 09:21:28 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 273133C3B for ; Mon, 17 Jul 2023 06:20:36 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 36EE3C15; Mon, 17 Jul 2023 06:21:19 -0700 (PDT) Received: from [10.57.76.30] (unknown [10.57.76.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 050F73F67D; Mon, 17 Jul 2023 06:20:32 -0700 (PDT) Message-ID: <2c4b2a41-1c98-0782-ac30-80e65bdb2b0c@arm.com> Date: Mon, 17 Jul 2023 14:20:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v3 3/4] mm: FLEXIBLE_THP for improved performance To: David Hildenbrand , Yu Zhao Cc: Andrew Morton , Matthew Wilcox , "Kirill A. Shutemov" , Yin Fengwei , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230714160407.4142030-1-ryan.roberts@arm.com> <20230714161733.4144503-3-ryan.roberts@arm.com> <82c934af-a777-3437-8d87-ff453ad94bfd@redhat.com> From: Ryan Roberts In-Reply-To: <82c934af-a777-3437-8d87-ff453ad94bfd@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/07/2023 14:06, David Hildenbrand wrote: > On 14.07.23 19:17, Yu Zhao wrote: >> On Fri, Jul 14, 2023 at 10:17 AM Ryan Roberts wrote: >>> >>> Introduce FLEXIBLE_THP feature, which allows anonymous memory to be >>> allocated in large folios of a determined order. All pages of the large >>> folio are pte-mapped during the same page fault, significantly reducing >>> the number of page faults. The number of per-page operations (e.g. ref >>> counting, rmap management lru list management) are also significantly >>> reduced since those ops now become per-folio. >>> >>> The new behaviour is hidden behind the new FLEXIBLE_THP Kconfig, which >>> defaults to disabled for now; The long term aim is for this to defaut to >>> enabled, but there are some risks around internal fragmentation that >>> need to be better understood first. >>> >>> When enabled, the folio order is determined as such: For a vma, process >>> or system that has explicitly disabled THP, we continue to allocate >>> order-0. THP is most likely disabled to avoid any possible internal >>> fragmentation so we honour that request. >>> >>> Otherwise, the return value of arch_wants_pte_order() is used. For vmas >>> that have not explicitly opted-in to use transparent hugepages (e.g. >>> where thp=madvise and the vma does not have MADV_HUGEPAGE), then >>> arch_wants_pte_order() is limited by the new cmdline parameter, >>> `flexthp_unhinted_max`. This allows for a performance boost without >>> requiring any explicit opt-in from the workload while allowing the >>> sysadmin to tune between performance and internal fragmentation. >>> >>> arch_wants_pte_order() can be overridden by the architecture if desired. >>> Some architectures (e.g. arm64) can coalsece TLB entries if a contiguous >>> set of ptes map physically contigious, naturally aligned memory, so this >>> mechanism allows the architecture to optimize as required. >>> >>> If the preferred order can't be used (e.g. because the folio would >>> breach the bounds of the vma, or because ptes in the region are already >>> mapped) then we fall back to a suitable lower order; first >>> PAGE_ALLOC_COSTLY_ORDER, then order-0. >>> >>> Signed-off-by: Ryan Roberts >>> --- >>>   .../admin-guide/kernel-parameters.txt         |  10 + >>>   mm/Kconfig                                    |  10 + >>>   mm/memory.c                                   | 187 ++++++++++++++++-- >>>   3 files changed, 190 insertions(+), 17 deletions(-) >>> >>> diff --git a/Documentation/admin-guide/kernel-parameters.txt >>> b/Documentation/admin-guide/kernel-parameters.txt >>> index a1457995fd41..405d624e2191 100644 >>> --- a/Documentation/admin-guide/kernel-parameters.txt >>> +++ b/Documentation/admin-guide/kernel-parameters.txt >>> @@ -1497,6 +1497,16 @@ >>>                          See Documentation/admin-guide/sysctl/net.rst for >>>                          fb_tunnels_only_for_init_ns >>> >>> +       flexthp_unhinted_max= >>> +                       [KNL] Requires CONFIG_FLEXIBLE_THP enabled. The maximum >>> +                       folio size that will be allocated for an anonymous vma >>> +                       that has neither explicitly opted in nor out of using >>> +                       transparent hugepages. The size must be a power-of-2 in >>> +                       the range [PAGE_SIZE, PMD_SIZE). A larger size improves >>> +                       performance by reducing page faults, while a smaller >>> +                       size reduces internal fragmentation. Default: max(64K, >>> +                       PAGE_SIZE). Format: size[KMG]. >>> + >> >> Let's split this parameter into a separate patch. >> > > Just a general comment after stumbling over patch #2, let's not start splitting > patches into things that don't make any sense on their own; that just makes > review a lot harder. ACK > > For this case here, I'd suggest first adding the general infrastructure and then > adding tunables we want to have on top. OK, so 1 patch for the main infrastructure, then a patch to disable for MADV_NOHUGEPAGE and friends, then a further patch to set flexthp_unhinted_max via a sysctl? > > I agree that toggling that at runtime (for example via sysfs as raised by me > previously) would be nicer. OK, I clearly misunderstood, I thought you were requesting a boot parameter. What's the ABI compat guarrantee for sysctls? I assumed that for a boot parameter it would be easier to remove in future if we wanted, but for sysctl, its there forever? Also, how do you feel about the naming and behavior of the parameter? >