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 6C5E4C3DA4A for ; Fri, 9 Aug 2024 07:58:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F21306B009E; Fri, 9 Aug 2024 03:58:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED1606B009F; Fri, 9 Aug 2024 03:58:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D722F6B00A0; Fri, 9 Aug 2024 03:58:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B90426B009E for ; Fri, 9 Aug 2024 03:58:35 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1D9E11A0A8C for ; Fri, 9 Aug 2024 07:58:35 +0000 (UTC) X-FDA: 82431954990.03.6535AD9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 4523F140008 for ; Fri, 9 Aug 2024 07:58:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.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=1723190240; 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=JexjqAbaHKvIcqrYLixp1xw2n0kCxMJZonHNdAC0ng4=; b=3NM4ic4by47fCVtDkVsQIoHvfHar8Zja4TpUWz0ZIDhmVjf8KePosFit/5kwSJJ3s9jH89 4h8vdrX154jK44wK1LG0vl+DliNH820qY1SsLK9YFxb2KtB1RT2LYhpW0tJ3Pt914+vuQw ocRMafDl8L8EPjzBgJp4gEi61dv/RiE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723190240; a=rsa-sha256; cv=none; b=buBjBzukXlWAhuZqonyZilIDNQKyEIlqJvE0+Xyt2rzk3+7Tt46pL6jvD1rcJ570QT7SYt kMQ+KNNyCsKtXdoKSt+CzoESQtd6I8QQE76Fw4SwGcIaH1d+TIxf628Ea/r5InvD+Soub1 C0qtOgX4nbZ7aZx1zJQnHGiESjrvUjE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf26.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com 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 4D6DFFEC; Fri, 9 Aug 2024 00:58:58 -0700 (PDT) Received: from [10.57.95.64] (unknown [10.57.95.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2754D3F6A8; Fri, 9 Aug 2024 00:58:31 -0700 (PDT) Message-ID: Date: Fri, 9 Aug 2024 08:58:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm: Override mTHP "enabled" defaults at kernel cmdline Content-Language: en-GB To: Barry Song Cc: Andrew Morton , Jonathan Corbet , David Hildenbrand , Lance Yang , Baolin Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240808101700.571701-1-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4523F140008 X-Stat-Signature: 436xsrwhjw5c8haztjzfyagj5wwganbn X-Rspam-User: X-HE-Tag: 1723190313-53109 X-HE-Meta: U2FsdGVkX1+rKPVFPCgrPVRXdpe0b7n02eGUAKRpUxjOtZA00nR20ILbJK1Oyeo0sueUkETEF9erM7FeRca/XbDGFH95bbxJYRAt/NqNALwmVEAn7gxk12vg3GU8g8CXLhZSLkIVGj45M4Luc/ABy93eqhnSV7VlC9dNo9OmsRGOEaL+znwV79RYrVfA/DkuP6Bwvskj3YLnq+LNNisDnrg3JntV6j55FzyfBJP2zO4KcIrOyvBRDo3ZgA5HwvQ2iMltZ1tOJd5Ua9yfRwwYuedVPcyxMO/seDV1qP6drRhSi6/TJqT9uaXBaMqTi8P1XCmyBS2gkWfFnv54072z+7lf4dEkwUup0+6pqX+1F99Hd9GrJhjqt59HIwWkBeeUHXDk6JPxjOY6fY2AZ7WjI+OyQXFwmdNdoT6ROb/e6JatjvreprWutJfz/DSQYEPrrVV+vgfVjOIJalZ+v8g5hc2ZhO1bayjOkq8sAFIu1IVJlGHoc9kc80y6m8yHF4qFwugODhgOjeK1S1VtG3DAAmaBByMewBj+W/jC/sRrLIv83djwrBfzhl03wcmXKDCwafJqo4KLBYK+UWidBJnjUEvVbthAlbL8q26PWdlFHi+ACOQV3W7vDbFgdJyIPqJ2LHG69C8rD1Q95I/P++pJlr9gJ9FdPDzfwVQkUra14zG1CDRcNbJ3eOvRLlhR8k1hL+FBxzQmPdTMzjdFWVIFPlU9gizhITqiPOZt0DwaPceG85qFOEuVbezUvldb9prOXjwi6T/QiH8xDYWvWmS9qG7fWgcpQAqHl4Fd+u0F2YkNaahsK7RBHMZbdkU9tKlB7Y4afYPlHscVpJZ9c9z8teQaD3LxJWKR2ugZA/IPslGnjbzsgVL8LvPYUqwjex5358gmRbhcYqz8AqzKbshtzcm7ggdMyICwkA2j5kOG7ee4D7TVRwIknS+ztxELrIb4d8JMPS1LViSx2GozBrY h+PEJPa5 6oWt6JwOfyWGNT8IbspBOwINwLaeh3GszlnfHPouyyZFtPgyB7J0uPcWtt58xJyY/mkhkthfrYof8BP8k+z6eWAPMt4ab2l9BkxvvOR/vh6ch8wPWhwhTb33YTJsqFLpYBR1Ing58n4NFgDuDGq0u8YcSvHxtC4bLhI1aQLyVrI3cbZItLTcbImU90qnC9oRTQN7FgFdMLoZIC5MR3H5Za/8DBL+4RJ3FogKZ 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: List-Subscribe: List-Unsubscribe: On 08/08/2024 22:17, Barry Song wrote: > On Thu, Aug 8, 2024 at 10:17 PM Ryan Roberts wrote: >> >> Add thp_anon= cmdline parameter to allow specifying the default >> enablement of each supported anon THP size. The parameter accepts the >> following format and can be provided multiple times to configure each >> size: >> >> thp_anon=[KMG]: >> >> See Documentation/admin-guide/mm/transhuge.rst for more details. >> >> Configuring the defaults at boot time is useful to allow early user >> space to take advantage of mTHP before its been configured through >> sysfs. >> >> Signed-off-by: Ryan Roberts >> --- >> >> Hi All, >> >> I've split this off from my RFC at [1] because Barry highlighted that he would >> benefit from it immediately [2]. There are no changes vs the version in that >> series. >> >> It applies against today's mm-unstable (275d686abcb59). (although I had to fix a >> minor build bug in stackdepot.c due to MIN() not being defined in this tree). >> >> Thanks, >> Ryan >> >> >> .../admin-guide/kernel-parameters.txt | 8 +++ >> Documentation/admin-guide/mm/transhuge.rst | 26 +++++++-- >> mm/huge_memory.c | 55 ++++++++++++++++++- >> 3 files changed, 82 insertions(+), 7 deletions(-) >> >> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt >> index bcdee8984e1f0..5c79b58c108ec 100644 >> --- a/Documentation/admin-guide/kernel-parameters.txt >> +++ b/Documentation/admin-guide/kernel-parameters.txt >> @@ -6631,6 +6631,14 @@ >> : poll all this frequency >> 0: no polling (default) >> >> + thp_anon= [KNL] >> + Format: [KMG]:always|madvise|never|inherit >> + Can be used to control the default behavior of the >> + system with respect to anonymous transparent hugepages. >> + Can be used multiple times for multiple anon THP sizes. >> + See Documentation/admin-guide/mm/transhuge.rst for more >> + details. >> + >> threadirqs [KNL,EARLY] >> Force threading of all interrupt handlers except those >> marked explicitly IRQF_NO_THREAD. >> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst >> index 24eec1c03ad88..f63b0717366c6 100644 >> --- a/Documentation/admin-guide/mm/transhuge.rst >> +++ b/Documentation/admin-guide/mm/transhuge.rst >> @@ -284,13 +284,27 @@ that THP is shared. Exceeding the number would block the collapse:: >> >> A higher value may increase memory footprint for some workloads. >> >> -Boot parameter >> -============== >> +Boot parameters >> +=============== >> >> -You can change the sysfs boot time defaults of Transparent Hugepage >> -Support by passing the parameter ``transparent_hugepage=always`` or >> -``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` >> -to the kernel command line. >> +You can change the sysfs boot time default for the top-level "enabled" >> +control by passing the parameter ``transparent_hugepage=always`` or >> +``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` to the >> +kernel command line. >> + >> +Alternatively, each supported anonymous THP size can be controlled by >> +passing ``thp_anon=[KMG]:``, where ```` is the THP size >> +and ```` is one of ``always``, ``madvise``, ``never`` or >> +``inherit``. >> + >> +For example, the following will set 64K THP to ``always``:: >> + >> + thp_anon=64K:always >> + >> +``thp_anon=`` may be specified multiple times to configure all THP sizes as >> +required. If ``thp_anon=`` is specified at least once, any anon THP sizes >> +not explicitly configured on the command line are implicitly set to >> +``never``. >> >> Hugepages in tmpfs/shmem >> ======================== >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 0c3075ee00012..c2c0da1eb94e6 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -82,6 +82,7 @@ unsigned long huge_zero_pfn __read_mostly = ~0UL; >> unsigned long huge_anon_orders_always __read_mostly; >> unsigned long huge_anon_orders_madvise __read_mostly; >> unsigned long huge_anon_orders_inherit __read_mostly; >> +static bool anon_orders_configured; >> >> unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, >> unsigned long vm_flags, >> @@ -672,7 +673,10 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj) >> * disable all other sizes. powerpc's PMD_ORDER isn't a compile-time >> * constant so we have to do this here. >> */ >> - huge_anon_orders_inherit = BIT(PMD_ORDER); >> + if (!anon_orders_configured) { >> + huge_anon_orders_inherit = BIT(PMD_ORDER); >> + anon_orders_configured = true; >> + } > > If a user configures 64KB and doesn't adjust anything for PMD_ORDER, > then PMD_ORDER will be set to "never", correct? This seems to change > the default behavior of PMD_ORDER. Could we instead achieve this by > checking if PMD_ORDER has been explicitly configured? Yes, that's how it's implemented in this patch, and the accompanying docs also state: If ``thp_anon=`` is specified at least once, any anon THP sizes not explicitly configured on the command line are implicitly set to ``never``. My initial approach did exactly as you suggest. But in the original series, I also had a similar patch to configure file thp with "thp_file=". And for file, all of the orders default to `always`. So if taking the same approach with that control, the user would have to explicitly opt-out of all supported orders rather than just opt-in to the orders they want. And I thought that could get tricky in future if support is added for more orders. I felt that was potentially very confusing so decided it was clearer to have the above rule and make both controls consistent. What do you think? > >> >> *hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj); >> if (unlikely(!*hugepage_kobj)) { >> @@ -857,6 +861,55 @@ static int __init setup_transparent_hugepage(char *str) >> } >> __setup("transparent_hugepage=", setup_transparent_hugepage); >> >> +static int __init setup_thp_anon(char *str) >> +{ >> + unsigned long size; >> + char *state; >> + int order; >> + int ret = 0; >> + >> + if (!str) >> + goto out; >> + >> + size = (unsigned long)memparse(str, &state); >> + order = ilog2(size >> PAGE_SHIFT); >> + if (*state != ':' || !is_power_of_2(size) || size <= PAGE_SIZE || >> + !(BIT(order) & THP_ORDERS_ALL_ANON)) >> + goto out; >> + >> + state++; >> + >> + if (!strcmp(state, "always")) { >> + clear_bit(order, &huge_anon_orders_inherit); >> + clear_bit(order, &huge_anon_orders_madvise); >> + set_bit(order, &huge_anon_orders_always); >> + ret = 1; >> + } else if (!strcmp(state, "inherit")) { >> + clear_bit(order, &huge_anon_orders_always); >> + clear_bit(order, &huge_anon_orders_madvise); >> + set_bit(order, &huge_anon_orders_inherit); >> + ret = 1; >> + } else if (!strcmp(state, "madvise")) { >> + clear_bit(order, &huge_anon_orders_always); >> + clear_bit(order, &huge_anon_orders_inherit); >> + set_bit(order, &huge_anon_orders_madvise); >> + ret = 1; >> + } else if (!strcmp(state, "never")) { >> + clear_bit(order, &huge_anon_orders_always); >> + clear_bit(order, &huge_anon_orders_inherit); >> + clear_bit(order, &huge_anon_orders_madvise); >> + ret = 1; >> + } >> + >> + if (ret) >> + anon_orders_configured = true; > > I mean: > > if (ret && order == PMD_ORDER) > anon_pmd_order_configured = true; > >> +out: >> + if (!ret) >> + pr_warn("thp_anon=%s: cannot parse, ignored\n", str); >> + return ret; >> +} >> +__setup("thp_anon=", setup_thp_anon); >> + >> pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) >> { >> if (likely(vma->vm_flags & VM_WRITE)) >> -- >> 2.43.0 >> > > Thanks > Barry