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 A518FC3DA4A for ; Fri, 9 Aug 2024 10:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AE806B007B; Fri, 9 Aug 2024 06:37:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 336D36B0083; Fri, 9 Aug 2024 06:37:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E1F86B008C; Fri, 9 Aug 2024 06:37:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F00096B007B for ; Fri, 9 Aug 2024 06:37:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5C9AB1A0CAF for ; Fri, 9 Aug 2024 10:37:33 +0000 (UTC) X-FDA: 82432355586.17.59D3B1A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 8FAA6C000D for ; Fri, 9 Aug 2024 10:37:31 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723199799; 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=uEC6rejYPv6bWlnMSrFGcxV9nJ6uQ6K3RnQL7D9yHeA=; b=jHoY9ZmsuUfVmwebEGXyhB8xghr9gn7ftrl7OrNLzSqVliEYyc8MQmMc2XKfUXSU2syXxp jtznC2vQ8OhcXluEbpGGRFDxFHIAph3yj8oMjz/lD0eEEIqtO83jpPVvDaROlUAZuaSKYc LiwlXZzoHdSNYbqFrM+PFstaOlTKONg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723199799; a=rsa-sha256; cv=none; b=098jGUQoWyNzflQvaAp0D0dXATRO9qNoapW6lmDfH+tT2TH376QwCucFm3xO8wztH02KZa 4l0t748YCu0QTB6LJn/365Rd4UmymFAKNuIV1rxDGjJocYUR4pc5UbVwemXYF8/ugkZAZt tNbk4g5fN3hGgm6OsnqbFKPN0wFwC0U= 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 A2D9613D5; Fri, 9 Aug 2024 03:37:56 -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 BBFA83F766; Fri, 9 Aug 2024 03:37:29 -0700 (PDT) Message-ID: <3c8f00ea-af28-46c7-9a5d-83c4b9462be3@arm.com> Date: Fri, 9 Aug 2024 11:37:28 +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: David Hildenbrand , Barry Song Cc: Andrew Morton , Jonathan Corbet , Lance Yang , Baolin Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240808101700.571701-1-ryan.roberts@arm.com> <99b78488-c524-4269-b1fb-a13eaa4f274c@redhat.com> <75eb6e75-8a6d-460a-8e96-7496ed1396b7@redhat.com> From: Ryan Roberts In-Reply-To: <75eb6e75-8a6d-460a-8e96-7496ed1396b7@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Stat-Signature: 77y7r9ahg3kdh6iomtf1sc1kdor57n5c X-Rspam-User: X-Rspamd-Queue-Id: 8FAA6C000D X-Rspamd-Server: rspam02 X-HE-Tag: 1723199851-385975 X-HE-Meta: U2FsdGVkX1//AZd4Ql0TLo/nh/soN/94LVUgErV1JorMxeKYniJV/VsEcK/IxosXEo9cLkzcCdVIMr8pJFBgXLEC51b6fjkhyxYh5w2DW60Qh1TcBw+drKqcUxY4GmnAMKfJuAVNzl+TTP6B6ChMg+Er6evSdTZNXtM9rzxl0iYRj/nc7kKzI9fXxhwx8yMe2v9lPTiK4KlZElQ61LmKXYT8I5LuOlwk55ZQAWreZ9xHELaimHhGPpu46VBp3uukhk7BhYDdWHawmufa2PfG83tsCGaDl8jI5boJQusAp5gyGwagz2T0ADE6E9aYrFO9YAHLyGib7hmEIY0e7p6eSinc+YllnUQIjQDkMw7o6wOZlbi1ezTDd+BPrps6CQchU0JT2mHMw8Zkl6MtStMpQglI4cc9lRBY8kDWlsd64djhiqbs3BsAS98CGP1tf8cNJtifmEtuPX3REacmbOwMcOViFEIIabNA+hJWXAw6iPpnLzxpmPcZ/jTwVnv5vE1OfR0XjL2vT5RHvpIYRgw2ZEzys5MSbSRT5N8Q4g/hf3sfy7Ok9Ihb5Cu6t81KrGUeuz7Xquh1K6gUrCx3vPf25aVKH7/S5rlVgs8VqpAPfa1h0yd2yvI0sl5grkyfNx9qwRGEfDFgfNYv4cxNfIjOgpObRaz687ze346DqPB2iHxq0jvMidClsWnQ4fE0/2gkQToY+dhtgVzOrS5njHKnLKJMtpU0SVKFXxxheZ0Mk2Z3JwCC1PuY9szDHSddN8+A+YNSv484JtwFDdOfgl2e1bUCRkYm8z8CWzbBcOXE5GwdPgliQKxJcLWiHbzW2vW3Tk6qeNwymTvY/OaJdJqgBALdFMuzVNBoGOWvUeca51nA8Sl4m6SxQJnOHoUcRIMPt9owYEjooyWZkrsoM/KUbOQjtrhYgyiPFlGsu/zvlV0UWrH4YIc6Jhkkw7fwr50kcnO40fLPauyq9bZmGPZ uZhswPtx viEEMiS5VUK8s2icpoV2dDa3SGm6/c/E5PMk3I6Ac8Dq62DAb7QFJkxhwIoTKU6lZp09/3QJU7CNVpTNjPgLJBCU4Wi6Vm9HMHQGinjExzsWpeNdb5pQnaqMdE8m3zgmn7nXDZtDMhrygD5aMFb63YbRphonC7cqui8Dj4VVUqvEWnyooresd+FTHt0AsjzxhYTY6y7gP/Yly4w0eTaNFz1SteVDtN7kDXcKdYKBLTKi2Gjz8gRRE2aSm29f09oyiRaIog2vtFXgl8Noho4ILE4b0hAPnhpQINYacXwxBRsNyNbWzHGc/uTf9JeeHfI5gHqxCMw4YTIFiq4E= 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 09/08/2024 10:32, David Hildenbrand wrote: > On 09.08.24 11:24, Barry Song wrote: >> On Fri, Aug 9, 2024 at 5:19 PM David Hildenbrand wrote: >>> >>> On 08.08.24 12:16, 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. >>> >>> I suspect a khugeapged enhancement and/or kernel-config-dependant >>> defaults and/or early system settings will also be able to mitigate that >>> without getting kernel cmdlines involved in the future. >>> >>>> >>>> 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``. >>> >>> I suggest documenting that "thp_anon=" will not effect the value of >>> "transparent_hugepage=", or any configured default. Did you see the previous conversation with Barry about whether or not to honour configured defaults when any thp_anon= is provided [1]? Sounds like you also think we should honour the PMD "inherit" default if not explicitly provided on the command line? (see link for justification for the approach I'm currently taking). [1] https://lore.kernel.org/linux-mm/CAGsJ_4x8ruPspuk_FQVggJMWcXLbRuZFq44gg-Dt7Ewt3ExqTw@mail.gmail.com/ >>> >>> Wondering if a syntax like >>> >>> thp_anon=16K,32K,64K:always;1048K,2048K:madvise Are there examples of that syntax already or have you just made it up? I found examples with the colon (:) but nothing this fancy. I guess that's not a reason not to do it though (other than the risk of screwing up the parser in a subtle way). >>> >>> (one could also support ranges, like "16K-64K") >>> >>> Would be even better. Then, maybe only allow a single instance. >>> >>> Maybe consider it if it's not too crazy to parse ;) I'll take a look. I'm going to be out for 3 weeks from end of Monday though, so probably won't get around to that until I'm back. I know Barry is keen to get this merged, so Barry, if you'd like to take it over that's fine by me (I'm sure you have enough on your plate though). >> >> I prefer the current approach because it effectively filters cases like this. >> >> [    0.000000] huge_memory: thp_anon=8K:inherit: cannot parse, ignored >> [    0.000000] Unknown kernel command line parameters >> "thp_anon=8K:inherit", will be passed to user space. >> >> if we put multiple sizes together, 8K,32K,64K:always >> >> We can't determine whether this command line is legal or illegal as it >> is partially legal and partially illegal. > > Besides: I wouldn't bother about this "user does something stupid" scenario that > much. > > But yes, once we support more sizes a cmdline might turn invalid on an older > kernel. > > However, I don't see the problem here. User passed a non-existant size. Ignore > that one but handle the others, like you would with multiple commands? Yep, the parser could emit a warning for the size and move on. > > It can be well defined and documented. The command line is legal, just one size > does not exist. > > The world will continue turning :) >