From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: "Maíra Canal" <mcanal@igalia.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Hugh Dickins" <hughd@google.com>,
"Barry Song" <baohua@kernel.org>,
"David Hildenbrand" <david@redhat.com>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Lance Yang" <ioworker0@gmail.com>
Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [PATCH 2/3] mm: shmem: control THP support through the kernel command line
Date: Mon, 28 Oct 2024 11:31:33 +0800 [thread overview]
Message-ID: <0d33f2c1-5433-486a-8faa-b85265ecc855@linux.alibaba.com> (raw)
In-Reply-To: <20241027175743.1056710-3-mcanal@igalia.com>
On 2024/10/28 01:36, Maíra Canal wrote:
> Add a new kernel command line to control the hugepage allocation policy
> for the internal shmem mount, ``transparent_hugepage_shmem``. The
> parameter is similar to ``transparent_hugepage`` and has the following
> format:
>
> transparent_hugepage_shmem=<policy>
>
> where ``<policy>`` is one of the seven valid policies available for
> shmem.
>
> By configuring the default hugepage allocation policy for the internal
> shmem mount, applications that use shmem, such as the DRM GEM objects,
> 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 | 7 ++++
> Documentation/admin-guide/mm/transhuge.rst | 6 +++
> mm/shmem.c | 38 ++++++++++++++++++-
> 3 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 1666576acc0e..acabb04d0dd4 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6926,6 +6926,13 @@
> See Documentation/admin-guide/mm/transhuge.rst
> for more details.
>
> + transparent_hugepage_shmem= [KNL]
> + Format: [always|within_size|advise|never|deny|force]
> + Can be used to control the hugepage allocation policy for
> + the internal shmem mount.
> + See Documentation/admin-guide/mm/transhuge.rst
> + for more details.
> +
> trusted.source= [KEYS]
> Format: <string>
> This parameter identifies the trust source as a backend
> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
> index 745055c3dc09..9b5b02c4d1ab 100644
> --- a/Documentation/admin-guide/mm/transhuge.rst
> +++ b/Documentation/admin-guide/mm/transhuge.rst
> @@ -326,6 +326,12 @@ 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``.
>
> +Similarly to ``transparent_hugepage``, you can control the hugepage
> +allocation policy for the internal shmem mount by using the kernel parameter
> +``transparent_hugepage_shmem=<policy>``, where ``<policy>`` is one of the
> +seven valid policies for shmem (``always``, ``within_size``, ``advise``,
> +``never``, ``deny``, and ``force``).
> +
> Hugepages in tmpfs/shmem
> ========================
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 44282a296c33..24cdeafd8260 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -582,7 +582,6 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
> }
> }
>
> -#if defined(CONFIG_SYSFS)
> static int shmem_parse_huge(const char *str)
> {
> if (!strcmp(str, "never"))
> @@ -599,7 +598,6 @@ static int shmem_parse_huge(const char *str)
> return SHMEM_HUGE_FORCE;
> return -EINVAL;
> }
> -#endif
>
> #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS)
> static const char *shmem_format_huge(int huge)
> @@ -5174,6 +5172,42 @@ struct kobj_attribute thpsize_shmem_enabled_attr =
> __ATTR(shmem_enabled, 0644, thpsize_shmem_enabled_show, thpsize_shmem_enabled_store);
> #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */
>
> +#if defined(CONFIG_TRANSPARENT_HUGEPAGE)
> +
> +static int __init setup_transparent_hugepage_shmem(char *str)
> +{
> + int huge, ret = 0;
> +
> + if (!str)
> + goto out;
> +
> + huge = shmem_parse_huge(str);
> + if (huge == -EINVAL)
> + goto out;
> +
> + if (!has_transparent_hugepage() &&
> + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + /* Do not override huge allocation policy with non-PMD sized mTHP */
> + if (huge == SHMEM_HUGE_FORCE &&
> + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + shmem_huge = huge;
The code is similar to shmem_enabled_store(). Could you factor out the
common parts into a helper function and reuse them?
> + return 1;
> +out:
> + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n");
> + return ret;
> +}
> +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem);
> +
> +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
> +
> #else /* !CONFIG_SHMEM */
>
> /*
next prev parent reply other threads:[~2024-10-28 3:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-27 17:36 [PATCH 0/3] mm: add more kernel parameters to control mTHP Maíra Canal
2024-10-27 17:36 ` [PATCH 1/3] mm: fix the format of the kernel parameter ``thp_anon=`` Maíra Canal
2024-10-27 19:52 ` Barry Song
2024-10-27 20:36 ` Maíra Canal
2024-10-27 21:46 ` Barry Song
2024-10-28 12:22 ` David Hildenbrand
2024-10-27 17:36 ` [PATCH 2/3] mm: shmem: control THP support through the kernel command line Maíra Canal
2024-10-28 3:31 ` Baolin Wang [this message]
2024-10-27 17:36 ` [PATCH 3/3] mm: shmem: override mTHP shmem default with a kernel parameter Maíra Canal
2024-10-27 21:54 ` Barry Song
2024-10-28 1:21 ` Lance Yang
2024-10-28 10:09 ` Maíra Canal
2024-10-28 11:09 ` Barry Song
2024-10-28 11:34 ` Maíra Canal
2024-10-28 22:35 ` Barry Song
2024-10-29 0:31 ` 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=0d33f2c1-5433-486a-8faa-b85265ecc855@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox