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 9203CC52D7F for ; Wed, 14 Aug 2024 07:53:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F1E16B0089; Wed, 14 Aug 2024 03:53:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A1546B0098; Wed, 14 Aug 2024 03:53:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 169596B0099; Wed, 14 Aug 2024 03:53:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E9F0F6B0098 for ; Wed, 14 Aug 2024 03:53:48 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 79D10160CFA for ; Wed, 14 Aug 2024 07:53:48 +0000 (UTC) X-FDA: 82450086936.04.8F1906D Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf24.hostedemail.com (Postfix) with ESMTP id 872A5180012 for ; Wed, 14 Aug 2024 07:53:44 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Z3rSRNtU; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723621931; 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:dkim-signature; bh=+VSuOls8jaaOLJrgF/Ih4DIM6pl/q+nzh+7j/SW0fpc=; b=iED4wEKmk1dZMdH4YggK2CiUstWaArGTHcUxaIAI88gxygC4Bf/LULLoCheRMDw6NOfcYY 8EDAgr0Gz6jraOUr1jtdBCN4aiYqKPhxbZgC0hNLi0Gc4mM4n1ogtkMOeYz43PyMou6l/9 UJDv2CIEa6w7rkncFbo/16Vq/YIky0U= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Z3rSRNtU; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723621931; a=rsa-sha256; cv=none; b=r82NyMlbnHYB8obq+7VQSejV+hLSDX0ezWboPdj9qKCgybyRjykWu4extOUv23qnDEhMIm nt6ZKnpZPTs60NGOp0hhmYJcqg3QuTEN9D5H7XUdYzptFZWRjHdtwI2C07YF97COS02pdF 65mcelSBedh4PtiXiulK42qXab535ug= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723622017; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=+VSuOls8jaaOLJrgF/Ih4DIM6pl/q+nzh+7j/SW0fpc=; b=Z3rSRNtU+SM9J0iAFMuxA33Jb5QvRYArrwIlqDlmXu4FlCFV0VBgBQp/0evEPAdiTgErkDEsZKH+mnGWfDmSXW3tTyAeMIzeXzhtA8CsbTxB8aoiWEsdfbWGSOpVGFbjwmJkas7kdshDxLgfx+OUltgLU520uckZ403fuQGsYuM= Received: from 30.97.56.61(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCraQFC_1723622014) by smtp.aliyun-inc.com; Wed, 14 Aug 2024 15:53:35 +0800 Message-ID: Date: Wed, 14 Aug 2024 15:53:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] mm: Override mTHP "enabled" defaults at kernel cmdline To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: baohua@kernel.org, corbet@lwn.net, david@redhat.com, ioworker0@gmail.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, v-songbaohua@oppo.com References: <20240814020247.67297-1-21cnbao@gmail.com> From: Baolin Wang In-Reply-To: <20240814020247.67297-1-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 872A5180012 X-Stat-Signature: icxe4mgg8ap9b3indsrnua6bd79z93de X-Rspam-User: X-HE-Tag: 1723622024-924298 X-HE-Meta: U2FsdGVkX1/dSNIKSeizchHM0goDydGVk241irfC96SsK299QyQ11MAzAZAgbagcfC0wnzaq/LFV9XjM8nuXmiqEOLrLJkhafN6OMqbD47/BiU7s8EJpnypr0DZMVTpVwLsNGX0bhlIZT+h5dvqoPUMQbkqQ2RQtksBrOdfx5+j2fAegdbdvxF5i9glpjkJGgkj2CFtxZKCqMpAwShB1To37OL/ENaYAGW91xD9RhiSO9Zvd/GRFS6iHWJKbWKjC6hf5T8d3PFPPBRlBYkVTBkv8kTIVx5jANVHAvV2yI5JgkbuOnBg7eVetB0lgXtRVnU/kzhqn4GCgsTM9TtwhyCPVvkLgd8fYySFhipJO9JW6Uo6YdiMPnZ0zxA4LchdKpSrwOIN+Ioa5Cl9ULNExU6I29Gp0mIRIgTFS7OIUcXqRIZxxedvTT/j0efb4RX7ql3PlUgx0doyMvo8z/wDuP1UG4U4pj26UexCe/PWZ/B7y68RFwddgGqYR8A++LaDRf1hLBHih/HkcUH/VbQQG9vDCBe0Ogh0mzNs2/7Sfwu+/yd+OISQ3vylLiu4/PSldMiQqlFFHP5Qg/jlg24WMviY16yk0fEHJwb1adj4pRqybSjU42BZsDx/AQ8iT7dhscoWZkBxcxmUO4FLH3GQpjQB2fiPjU5NOU5GQclmLlI+UepXQnyzTufy/2NRDAwWvQPe/Vxn/+HAmOhQ71RF8DcdLWaJbBNk4iu6ziw7ut3syhTlrH4TLjgZl2rnJQKKzumQO4f8rZBUholahnmOPr5ZCPEFq3oXh1PXaVpUMuMFE2Bnh4kWfDEH66gWhAUvmFuvhAPEBKjgO1/nIDRqMj9wvPxUj39ysIMM33y/NsVBgeBYtn4y1K5N20pArBuq371d3q75ipvbrnEHP88fE6f1dkRoHjOT3SpPyV42PXtXWPPJ6oW9GrwYmSYO1shlvFTEijE2bIYU4E8SXO0o pbKjOz60 U2V/Rv3eWt7M/Nl2DbulIgECsTHckhRMHwjI1ogelMtv8Sa6ku8WorCV694hnOozRj6pgbRCS6/Qy/h4Ck1A+MBypITI9gK/2OdJmBveWzNwKezQBvk307Pd2t9oQmRskB+sJVTcKQvyBZVEjWJCA8iGlxzzUbxhihqzDTfDvGsTWNCqSyIO79XiaOTrMH5Q6U5THA7H9FEpeSKTcOsOBNkFk7pkHEHXtFhSxDxVG3yZLpzv4Bzso4seAk5bOW7megCOJf1TL+z9TvWB+K2ADwO+caYYV2wJrLgnwtLcutss/2E8jJE9Uwifj0hLLijqDrQ69XLTFwX/Uc3WOuMhEHU1and8+5feXngX/+iQhBo8qol6tlrXDWiHJSw== 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 2024/8/14 10:02, Barry Song wrote: > From: Ryan Roberts > > 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]:;-[KMG]: > > An example: > > thp_anon=16K-64K:always;128K,512K:inherit;256K:madvise;1M-2M:never > > 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 > Co-developed-by: Barry Song > Signed-off-by: Barry Song LGTM. Feel free to add: Reviewed-by: Baolin Wang Tested-by: Baolin Wang Just a small nit as below. > --- > -v4: > * use bitmap APIs to set and clear bits. thanks very much for > David's comment! > > .../admin-guide/kernel-parameters.txt | 9 ++ > Documentation/admin-guide/mm/transhuge.rst | 37 +++++-- > mm/huge_memory.c | 96 ++++++++++++++++++- > 3 files changed, 134 insertions(+), 8 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index f0057bac20fb..d0d141d50638 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -6629,6 +6629,15 @@ > : poll all this frequency > 0: no polling (default) > > + thp_anon= [KNL] > + Format: ,[KMG]:;-[KMG]: > + state is one of "always", "madvise", "never" or "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 7072469de8a8..528e1a19d63f 100644 > --- a/Documentation/admin-guide/mm/transhuge.rst > +++ b/Documentation/admin-guide/mm/transhuge.rst > @@ -284,13 +284,36 @@ that THP is shared. Exceeding the number would block the collapse:: > > A higher value may increase memory footprint for some workloads. > > -Boot parameter > -============== > - > -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. > +Boot parameters > +=============== > + > +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]:;-[KMG]:``, > +where ```` is the THP size and ```` is one of ``always``, > +``madvise``, ``never`` or ``inherit``. > + > +For example, the following will set 16K, 32K, 64K THP to ``always``, > +set 128K, 512K to ``inherit``, set 256K to ``madvise`` and 1M, 2M > +to ``never``:: > + > + thp_anon=16K-64K:always;128K,512K:inherit;256K:madvise;1M-2M:never > + > +``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``. > + > +``transparent_hugepage`` setting only affects the global toggle. If > +``thp_anon`` is not specified, PMD_ORDER THP will default to ``inherit``. > +However, if a valid ``thp_anon`` setting is provided by the user, the > +PMD_ORDER THP policy will be overridden. If the policy for PMD_ORDER > +is not defined within a valid ``thp_anon``, its policy will default to > +``never``. > > Hugepages in tmpfs/shmem > ======================== > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 1a12c011e2df..c5f4e97b49de 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -81,6 +81,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, > @@ -737,7 +738,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; > + } > > *hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj); > if (unlikely(!*hugepage_kobj)) { > @@ -922,6 +926,96 @@ static int __init setup_transparent_hugepage(char *str) > } > __setup("transparent_hugepage=", setup_transparent_hugepage); > > +static inline int get_order_from_str(const char *size_str) > +{ > + unsigned long size; > + char *endptr; > + int order; > + > + size = memparse(size_str, &endptr); > + order = fls(size >> PAGE_SHIFT) - 1; Nit: using get_order() seems more robust? > + if ((1 << order) & ~THP_ORDERS_ALL_ANON) { > + pr_err("invalid size %s(order %d) in thp_anon boot parameter\n", > + size_str, order); > + return -EINVAL; > + } > + > + return order; > +} [snip]