All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: "Barry Song" <21cnbao@gmail.com>, "Maíra Canal" <mcanal@igalia.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hugh Dickins <hughd@google.com>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Lance Yang <ioworker0@gmail.com>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [PATCH v3 3/4] mm: shmem: override mTHP shmem default with a kernel parameter
Date: Thu, 31 Oct 2024 22:39:37 +0100	[thread overview]
Message-ID: <ec69b1ee-89f4-47d2-a223-f277b7aad76b@redhat.com> (raw)
In-Reply-To: <CAGsJ_4zObE7hsFangzmKK0c6wZ7xZS3fCEYdx5W6HkAHqcP20g@mail.gmail.com>

On 31.10.24 22:12, Barry Song wrote:
> On Fri, Nov 1, 2024 at 3:20 AM Maíra Canal <mcanal@igalia.com> wrote:
>>
>> On 31/10/24 10:33, David Hildenbrand wrote:
>>> On 31.10.24 14:24, Maíra Canal wrote:
>>>> Hi David,
>>>>
>>>> On 31/10/24 09:57, David Hildenbrand wrote:
>>>>> On 31.10.24 13:51, Maíra Canal wrote:
>>>>>> Hi David,
>>>>>>
>>>>>> On 31/10/24 09:37, David Hildenbrand wrote:
>>>>>>> On 30.10.24 13:58, Maíra Canal wrote:
>>>>>>>> Add the ``thp_shmem=`` kernel command line to allow specifying the
>>>>>>>> default policy of each supported shmem hugepage size. The kernel
>>>>>>>> parameter
>>>>>>>> accepts the following format:
>>>>>>>>
>>>>>>>> thp_shmem=<size>[KMG],<size>[KMG]:<policy>;<size>[KMG]-
>>>>>>>> <size>[KMG]:<policy>
>>>>>>>>
>>>>>>>> For example,
>>>>>>>>
>>>>>>>> thp_shmem=16K-64K:always;128K,512K:inherit;256K:advise;1M-2M:never;4M-8M:within_size
>>>>>>>>
>>>>>>>> By configuring the default policy of several shmem hugepages, the
>>>>>>>> user
>>>>>>>> can take advantage of mTHP before it's been configured through sysfs.
>>>>>>>>
>>>>>>>> Signed-off-by: Maíra Canal <mcanal@igalia.com>
>>>>>>>> ---
>>>>>>>>      .../admin-guide/kernel-parameters.txt         |  10 ++
>>>>>>>>      Documentation/admin-guide/mm/transhuge.rst    |  17 +++
>>>>>>>>      mm/shmem.c                                    | 109 +++++++++++++
>>>>>>>> ++++-
>>>>>>>>      3 files changed, 135 insertions(+), 1 deletion(-)
>>>>>>>>
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>>>> diff --git a/mm/shmem.c b/mm/shmem.c
>>>>>>>> index dfcc88ec6e34..c2299fa0b345 100644
>>>>>>>> --- a/mm/shmem.c
>>>>>>>> +++ b/mm/shmem.c
>>>>>>>> @@ -136,6 +136,7 @@ static unsigned long huge_shmem_orders_always
>>>>>>>> __read_mostly;
>>>>>>>>      static unsigned long huge_shmem_orders_madvise __read_mostly;
>>>>>>>>      static unsigned long huge_shmem_orders_inherit __read_mostly;
>>>>>>>>      static unsigned long huge_shmem_orders_within_size __read_mostly;
>>>>>>>> +static bool shmem_orders_configured __initdata;
>>>>>>>>      #endif
>>>>>>>>      #ifdef CONFIG_TMPFS
>>>>>>>> @@ -5027,7 +5028,8 @@ void __init shmem_init(void)
>>>>>>>>           * Default to setting PMD-sized THP to inherit the global
>>>>>>>> setting and
>>>>>>>>           * disable all other multi-size THPs.
>>>>>>>>           */
>>>>>>>> -    huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER);
>>>>>>>> +    if (!shmem_orders_configured)
>>>>>>>> +        huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER);
>>>>>>>>      #endif
>>>>>>>>          return;
>>>>>>>> @@ -5180,6 +5182,26 @@ struct kobj_attribute
>>>>>>>> thpsize_shmem_enabled_attr =
>>>>>>>>      #if defined(CONFIG_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);
>>>>>>>> +
>>>>>>>> +    if (!is_power_of_2(size))
>>>>>>>> +        goto err;
>>>>>>>> +    order = get_order(size);
>>>>>>>> +    if (BIT(order) & ~THP_ORDERS_ALL_FILE_DEFAULT)
>>>>>>>> +        goto err;
>>>>>>>> +
>>>>>>>> +    return order;
>>>>>>>> +err:
>>>>>>>> +    pr_err("invalid size %s in thp_shmem boot parameter\n",
>>>>>>>> size_str);
>>>>>>>> +    return -EINVAL;
>>>>>>>> +}
>>>>>>>
>>>>>>> Hm, mostly copy and paste. You could reuse existing
>>>>>>> get_order_from_str()
>>>>>>> simply by passing in the supported orders and moving error
>>>>>>> reporting to
>>>>>>> the caller.
>>>>>>>
>>>>>>
>>>>>> Can I use functions from mm/huge_memory.c here?
>>>>>
>>>>> Yes, that's the idea.
>>>>>
>>>>
>>>> Unfortunately, it isn't possible without adding the function to a
>>>> header.
>>>
>>> Well ... sure, what's the problem with that?
>>
>> David & Barry, how do you feel about adding `get_order_from_str()` to
>> lib/cmdline.c?
> 
> I'd vote to leave it as is. If, at some point, the controls for shared memory
> and anonymous memory are moved to a file, that would be the right time
> to call the same get_order_from_str() for both.
 > > This is too trivial to warrant being an exposed API in huge_memory.h
> or cmdline.

I ... don't quite agree. cmdline.c is probably a bit excessive and I 
wouldn't suggest that at this point.

This seems like a reasonable helper function to have as inline in 
mm/internal.h.

... unless I am missing something important and the obvious code 
duplication is warranted.

-- 
Cheers,

David / dhildenb


  reply	other threads:[~2024-10-31 21:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 12:58 [PATCH v3 0/4] mm: add more kernel parameters to control mTHP Maíra Canal
2024-10-30 12:58 ` [PATCH v3 1/4] mm: fix docs for the kernel parameter ``thp_anon=`` Maíra Canal
2024-10-30 12:58 ` [PATCH v3 2/4] mm: shmem: control THP support through the kernel command line Maíra Canal
2024-10-31  3:53   ` Baolin Wang
2024-10-31 12:32   ` David Hildenbrand
2024-10-30 12:58 ` [PATCH v3 3/4] mm: shmem: override mTHP shmem default with a kernel parameter Maíra Canal
2024-10-31 12:37   ` David Hildenbrand
2024-10-31 12:51     ` Maíra Canal
2024-10-31 12:57       ` David Hildenbrand
2024-10-31 13:24         ` Maíra Canal
2024-10-31 13:33           ` David Hildenbrand
2024-10-31 14:19             ` Maíra Canal
2024-10-31 21:12               ` Barry Song
2024-10-31 21:12               ` Barry Song
2024-10-31 21:39                 ` David Hildenbrand [this message]
2024-10-31 22:16                   ` Barry Song
2024-10-30 12:58 ` [PATCH v3 4/4] mm: huge_memory: Use strscpy() instead of strcpy() Maíra Canal
2024-10-30 23:07   ` Barry Song
2024-10-31 10:55     ` Maíra Canal
2024-10-31 12:01       ` Barry Song
2024-10-31 12:11         ` Maíra Canal
2024-10-31 20:27           ` Barry Song
2024-10-31 20:31             ` Barry Song
2024-10-31  1:39   ` Lance Yang
2024-10-30 22:50 ` [PATCH v3 0/4] mm: add more kernel parameters to control mTHP Andrew Morton
2024-10-31 11:04   ` Maíra Canal
2024-11-01  1:12     ` Andrew Morton
2024-11-01 16:34       ` Maíra Canal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec69b1ee-89f4-47d2-a223-f277b7aad76b@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=corbet@lwn.net \
    --cc=hughd@google.com \
    --cc=ioworker0@gmail.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcanal@igalia.com \
    --cc=ryan.roberts@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.