From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AA8DEB64DC for ; Tue, 27 Jun 2023 09:54:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83F688D0002; Tue, 27 Jun 2023 05:54:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EF798D0001; Tue, 27 Jun 2023 05:54:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DEA38D0002; Tue, 27 Jun 2023 05:54:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5FDFA8D0001 for ; Tue, 27 Jun 2023 05:54:15 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1AC9F140954 for ; Tue, 27 Jun 2023 09:54:15 +0000 (UTC) X-FDA: 80948067270.20.E336523 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 513CB180010 for ; Tue, 27 Jun 2023 09:54:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687859653; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MREUDm+2mo5QCYsvExVdrELgyzaG9V3RpO2t/CLJbaE=; b=H/JyuSSBtJFbIXYt3nRFEW9/BXKQrUIWqQSjZgR8qv9xMinIBdOU1EZQQMsdNudj2M9TT6 DzP572viLMFTC/Q6YR4tF5goyDxD57V/naudWWFiF5QimZkBcnhXm4l1PEtRqaLIhb5WoC Erqa4GVy9nLxruuLRH1Oa9UkfXVk/zg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687859653; a=rsa-sha256; cv=none; b=4Ufn4QylRqfJon+Gcu/rBw0h9GYXLGIbD+tS+1lTfea48i9e9B5z1OyI3yO16vW69S2urW SDHDXLP9EAhB1XDsC9MIRNQ4tIwhhgl+xwNy6897LhZ5RyE4tlDTV51dStfDeraHSa8liY rbu43ugRrxGIK0wYYB0qJUh/mwiZ3qw= 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 757662F4; Tue, 27 Jun 2023 02:54:56 -0700 (PDT) Received: from [10.1.30.74] (C02Z41KALVDN.cambridge.arm.com [10.1.30.74]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C2303F64C; Tue, 27 Jun 2023 02:54:09 -0700 (PDT) Message-ID: <6fc531bc-6b72-37bd-7380-0969622f08d4@arm.com> Date: Tue, 27 Jun 2023 10:54:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v1 08/10] mm: Kconfig hooks to determine max anon folio allocation order To: Yu Zhao Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.org References: <20230626171430.3167004-1-ryan.roberts@arm.com> <20230626171430.3167004-9-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 513CB180010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: s11p6zhyyc6h9dc9mtffpo7gbtc6xkzt X-HE-Tag: 1687859653-640778 X-HE-Meta: U2FsdGVkX19Y9YK2zkmBbJBUeloYJkunPlovoaskeHSd3NL8dXbKlQtl+fw8TX72lxsImCPKNU+dcBl+d+jtJCICq890Zhr8ccNwVEFXFYeH/yxqtvgV1tm9oREHkRRtwxEBm+ycVi3zteSfyfKy3h5yCKKbO+7MkWecxlGupLsKK/pXBFr1AQg8esFZvGlTHdWHthEcVERpQdAVbRfBDIKVL1DmFsHwKPZRIGUqusVrZhj+2CbsdhyPY/1MBLuetYz0Mheq4bQZxCJ6/kterbaN6Lo/1q/7kh5ZntMfa7j2a32q8dkiZQcurZJJhjq76UddokijI8O66zUw6R2IcKAve0jFMzPpAxFl4+O4tieRlnUA32ybbIaPHU1Y89ODVgJDJodHlgq+ExSY0PoAwnhqe+9SUhxdgoC7WURprab838uxZEoy8VhXQQJc0cvbYXyD1+lEC3vK9bpgp7NTDl+mI/MvOUwlCHD/i91+cxr/Sp2aAFugWITON5YlGcUFjauh5u0WtS77wjNac9Bvd5fC3tfLiAJ8RbxBuqrmkR3Kw4GaVs3SctgR3n9cyeyBz/V1QDkoTLRXywTp8o0or+gKnwNdVYqVj/7hrg0+cOny+8TvzZa+KTWcQm6RtAOKtpN+60rrCiYOau2Qe+13Yx63xJpAQdxuxDspDf9kuUNuhWE0wt8tz040H0EYg4bLMYCGS39R3AzvBgsVdjOiR41zbjjnB0RN6GOWeqJU+gP0MPbqBjuUoJLI//UTbmhnK7ZBZwEWaQkC6sLhbmoVdomgjVZxhyfXjIhomRLvHdM+aLFhExEn/+F/59xGIEvp2MEgFHqS3QznyFeFZ5Mt6EKebDeb6aisBGIfjz2LhvTMLr1xrEL7gQHT+v0P0lI3DjDFPfhrMEwnm+H8VhZolckBUOyTr94oPM0PgIUdghQPGfyafi7b4+6kwWEFLr/xZy+HeFQ8Cg9sitp0UIe rIVzCdRG ziWzRaHjxNdAqEnbQnlMoOdDl90AnpzhNC/ikj4T+AolTPbKIjgkN4/44YFwevQnQtp+MUnyr4naBnatNmLP7nWo36GN1hj+YbLUMUfZ4qpGxC4Hk7k9pk7TBym+zIZZdXBHsPTFbuD1gw2Xgwxdet/r4x0Sk25gkitem/stsQxuX8FE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 27/06/2023 03:47, Yu Zhao wrote: > On Mon, Jun 26, 2023 at 11:15 AM Ryan Roberts wrote: >> >> For variable-order anonymous folios, we need to determine the order that >> we will allocate. From a SW perspective, the higher the order we >> allocate, the less overhead we will have; fewer faults, fewer folios in >> lists, etc. But of course there will also be more memory wastage as the >> order increases. >> >> From a HW perspective, there are memory block sizes that can be >> beneficial to reducing TLB pressure. arm64, for example, has the ability >> to map "contpte" sized chunks (64K for a 4K base page, 2M for 16K and >> 64K base pages) such that one of these chunks only uses a single TLB >> entry. >> >> So we let the architecture specify the order of the maximally beneficial >> mapping unit when PTE-mapped. Furthermore, because in some cases, this >> order may be quite big (and therefore potentially wasteful of memory), >> allow the arch to specify 2 values; One is the max order for a mapping >> that _would not_ use THP if all size and alignment constraints were met, >> and the other is the max order for a mapping that _would_ use THP if all >> those constraints were met. >> >> Implement this with Kconfig by introducing some new options to allow the >> architecture to declare that it supports large anonymous folios along >> with these 2 preferred max order values. Then introduce a user-facing >> option, LARGE_ANON_FOLIO, which defaults to disabled and can only be >> enabled if the architecture has declared its support. When disabled, it >> forces the max order values, LARGE_ANON_FOLIO_NOTHP_ORDER_MAX and >> LARGE_ANON_FOLIO_THP_ORDER_MAX to 0, meaning only a single page is ever >> allocated. >> >> Signed-off-by: Ryan Roberts >> --- >> mm/Kconfig | 39 +++++++++++++++++++++++++++++++++++++++ >> mm/memory.c | 8 ++++++++ >> 2 files changed, 47 insertions(+) >> >> diff --git a/mm/Kconfig b/mm/Kconfig >> index 7672a22647b4..f4ba48c37b75 100644 >> --- a/mm/Kconfig >> +++ b/mm/Kconfig >> @@ -1208,4 +1208,43 @@ config PER_VMA_LOCK >> >> source "mm/damon/Kconfig" >> >> +config ARCH_SUPPORTS_LARGE_ANON_FOLIO >> + def_bool n >> + help >> + An arch should select this symbol if wants to allow LARGE_ANON_FOLIO >> + to be enabled. It must also set the following integer values: >> + - ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX >> + - ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX >> + >> +config ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX >> + int >> + help >> + The maximum size of folio to allocate for an anonymous VMA PTE-mapping >> + that does not have the MADV_HUGEPAGE hint set. >> + >> +config ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX >> + int >> + help >> + The maximum size of folio to allocate for an anonymous VMA PTE-mapping >> + that has the MADV_HUGEPAGE hint set. >> + >> +config LARGE_ANON_FOLIO >> + bool "Allocate large folios for anonymous memory" >> + depends on ARCH_SUPPORTS_LARGE_ANON_FOLIO >> + default n >> + help >> + Use large (bigger than order-0) folios to back anonymous memory where >> + possible. This reduces the number of page faults, as well as other >> + per-page overheads to improve performance for many workloads. >> + >> +config LARGE_ANON_FOLIO_NOTHP_ORDER_MAX >> + int >> + default 0 if !LARGE_ANON_FOLIO >> + default ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX >> + >> +config LARGE_ANON_FOLIO_THP_ORDER_MAX >> + int >> + default 0 if !LARGE_ANON_FOLIO >> + default ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX >> + >> endmenu > > I don't think an MVP should add this many Kconfigs. One Kconfig sounds > reasonable to me for now. If we move to arch_wants_pte_order() as you suggested (in your response to patch 3) then I agree we can remove most of these. I still think we might want 2 though. For an arch that does not implement arch_wants_pte_order() we wouldn't want LARGE_ANON_FOLIO to show up in menuconfig so we would still need ARCH_SUPPORTS_LARGE_ANON_FOLIO: config ARCH_SUPPORTS_LARGE_ANON_FOLIO def_bool n help An arch should select this symbol if wants to allow LARGE_ANON_FOLIO to be enabled. In this case, It must also define arch_wants_pte_order() config LARGE_ANON_FOLIO bool "Allocate large folios for anonymous memory" depends on ARCH_SUPPORTS_LARGE_ANON_FOLIO default n help Use large (bigger than order-0) folios to back anonymous memory where possible. This reduces the number of page faults, as well as other per-page overheads to improve performance for many workloads. What do you think?