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 5C185D5B840 for ; Tue, 29 Oct 2024 02:04:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71C336B00BF; Mon, 28 Oct 2024 22:04:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB866B00C0; Mon, 28 Oct 2024 22:04:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56C466B00C1; Mon, 28 Oct 2024 22:04:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 387D26B00BF for ; Mon, 28 Oct 2024 22:04:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E35D91C6828 for ; Tue, 29 Oct 2024 02:04:07 +0000 (UTC) X-FDA: 82724993358.13.E9F2971 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf07.hostedemail.com (Postfix) with ESMTP id A8B1540017 for ; Tue, 29 Oct 2024 02:03:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=ju1K9N7R; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730167391; a=rsa-sha256; cv=none; b=lBpcOjG5pyd4aZ0xouK1SdZ7ViBJbhtJvIBR5vwqBc/aj5xEWg10887zDgb1+Er5jr6Azu R8bvTSa2fIPjqh08mY1DT2Szmnuiyc+DDtkLdfmf7NDaBKCsWR3VLWGfy5cwGWhstIPybZ PBv7ZhsfaanVAhyOPV89q7d/ihEcKqM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=ju1K9N7R; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730167391; 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=cJLV2I3mm++zjsZzUs9QwwWBlESHcgMWR+goQ5ld/5c=; b=l8l1VOVSalCMSE7L4qrzTAJF/dP+732tnu6pxrM+wFe/7wZIOfCoHslYuiM/ZD+lQiNdR7 +XcAjwiE03m2zTjbAI2mybELxl+WDV6yGjr1kYWDWnTfI3ic91cVwoJN4jB7ACoS88Bog0 X3RY8XfaW/GCV+7vPEuP64rTAD1A6mQ= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1730167440; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=cJLV2I3mm++zjsZzUs9QwwWBlESHcgMWR+goQ5ld/5c=; b=ju1K9N7RJJJ+w3jgF1CRis4GaECwQBLcCvEEZEyEdeLb+FMpR26wfmnAM6/ngHMjjLa+v21tY/rY2RFqFBo5Y4pG4c/f6VQrDO21uVWzezSn//iWNbbUHm0WdiZ/A37hl+uhg2MvR89Q2sLwLrEq6Uwt8h4MmvGXkCQLJ/BDEbE= Received: from 30.74.144.128(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WI8M9ZI_1730167438 cluster:ay36) by smtp.aliyun-inc.com; Tue, 29 Oct 2024 10:03:59 +0800 Message-ID: <6044e56a-7747-45d4-82c9-7a070950ddd2@linux.alibaba.com> Date: Tue, 29 Oct 2024 10:03:58 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/4] mm: shmem: control THP support through the kernel command line To: =?UTF-8?Q?Ma=C3=ADra_Canal?= , Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Lance Yang Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com References: <20241029002324.1062723-1-mcanal@igalia.com> <20241029002324.1062723-3-mcanal@igalia.com> From: Baolin Wang In-Reply-To: <20241029002324.1062723-3-mcanal@igalia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: A8B1540017 X-Rspamd-Server: rspam01 X-Stat-Signature: k6s9mbnupgcyhky86smfomgm6ufuk7oc X-HE-Tag: 1730167411-116467 X-HE-Meta: U2FsdGVkX188UFsNbZ3VEKhAvZioJn8C0FsM3x/PzWCPHZOGILnkpwyVqS/5pBgV3T2ctyq+YoeOEnecjTQYArBvXbcH45N9bsr4LUSAIVfeCbR9ke9idKaO6lsM+2CB3zh4/Ce64KTvw52C2fYMB2H8Ss7wmcrsTeDasUmKGzcHuuJly6ZrwXPuYPH5AyzRu468OIbLg4pKdgmm08E6CKbcMXXsSfRgtQlYvzFIxJcbfLgX5ZWMcjFQV8jgX4w5nPwUA+upzK/A3k6IKghjH1XGWU0OI5nt30Zm5pFe+f+QNaSOhY+XmruvupPsXRJrxeCzSmgeVMi3jV/ufzstd3nycGno0G+XWs3G0Lf4pigfM9MgBs2D6OkZHAkcE1Ten0dkTRAbdoo72a95dXnITqczlf3W+HWgi2kQ8U8n4J5RLlH0bRgwcPJduW8q4iBDhncCO9jJRE1c/OcEkMO7DDtloCO7Z9Z53THy/Apyh8Ym4ezx8PquGKc288HSAwmaZ2KRM978h3mwsUhaLcyQf04wHc7SyadKIcxJB0YTQot5wAl5RRlT0o46tHFQPVRzgZRunFvWJLEPi/RJyyDXkEGrL31goeuAzY9FVkG7/APSdJNOuW7IMs4JyoFL+7Ov+ZZo3QLYpiF/7KrtoGAjdZZRxoycT46I5GhYGJ80gEL8fEo0sjZQeO7VmMjw2LBDg3cW+UR3k0jWYxka9XbV5ZGDDUiGQaqfaIIBpAhNgqGypij7ZgrhKUVl6lFZqsY7csrNjTO9xt/4JdJJZproSvFnoeWPH3rH/DAUNnK+ZJ6pYCT2nynG8X233vHZ+6BjS9PwvndZJyhV8NaUWK4TPr33gLk5KMXFskZXijKVCXTFJfwEWy2Ouj4hoGDDSO//9pYYKXto5rL/KtwzlxhnX5Ht5lPaR26oZBX8d3/bAOCN3yif5PQ9TeL/Zwaez8NxH/XLN2QWk1HsZvo2k0Q 4RDpP9wD 5FFIdWk5kawO3yOVHQpCG8r05gfKzekmmNide4PNNPRewaQ874HZQtfWsul9m6jIlTij7bpvxZwLx+gGJrn3K0WEWMFjBG9+pMvrKJJp61LgXqRxuLvHVaNBOF2N3Q/UTNZnJ1ernyFR1g1dBzh7mSV8/UBH0Wj8cDE/plxszjjmUDWGcrm7vGIwtjeX8CmLS8/csfxSg5qelGzq7oljwVOBca28JGv0ML77bAxrgj6YpQZ5Un6FOQRohT7Z238uMECErf5Ds6gkksbIEThWJL/JqyVbnyQVfhE79EEa+6izw8OYuPAYgq9e8caQCyNMJ8GbGpBdynQnIZ6SM0R3Wyu+Qyw== 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/10/29 08:13, 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= > > where ```` 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. Just out of curiosity, do you have any performance benefit data when using mTHP for DRM GEM objects? > Signed-off-by: Maíra Canal > --- > .../admin-guide/kernel-parameters.txt | 7 +++ > Documentation/admin-guide/mm/transhuge.rst | 6 +++ > mm/shmem.c | 53 +++++++++++++++---- > 3 files changed, 57 insertions(+), 9 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: > 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=``, where ```` 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..26c1eb1b4b1d 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) > @@ -624,6 +622,20 @@ static const char *shmem_format_huge(int huge) > } > #endif > > +static int shmem_valid_huge(int huge) > +{ > + if (!has_transparent_hugepage() && > + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) > + return -EINVAL; > + > + /* Do not override huge allocation policy with non-PMD sized mTHP */ > + if (huge == SHMEM_HUGE_FORCE && > + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) > + return -EINVAL; > + > + return 0; > +} > + > static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, > struct shrink_control *sc, unsigned long nr_to_free) > { > @@ -5070,14 +5082,10 @@ static ssize_t shmem_enabled_store(struct kobject *kobj, > huge = shmem_parse_huge(tmp); > if (huge == -EINVAL) > return -EINVAL; > - if (!has_transparent_hugepage() && > - huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) > - return -EINVAL; > > - /* Do not override huge allocation policy with non-PMD sized mTHP */ > - if (huge == SHMEM_HUGE_FORCE && > - huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) > - return -EINVAL; > + err = shmem_valid_huge(huge); > + if (err) > + return err; > > shmem_huge = huge; > if (shmem_huge > SHMEM_HUGE_DENY) > @@ -5174,6 +5182,33 @@ 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; Looks better. But shmem_parse_huge() is also a common part, and what I am thinking is below: diff --git a/mm/shmem.c b/mm/shmem.c index f8b8b1ad2631..646d8943950a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -629,24 +629,39 @@ static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index } } -#if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { + int huge; + + if (!str) + return -EINVAL; + if (!strcmp(str, "never")) - return SHMEM_HUGE_NEVER; - if (!strcmp(str, "always")) - return SHMEM_HUGE_ALWAYS; - if (!strcmp(str, "within_size")) - return SHMEM_HUGE_WITHIN_SIZE; - if (!strcmp(str, "advise")) - return SHMEM_HUGE_ADVISE; - if (!strcmp(str, "deny")) - return SHMEM_HUGE_DENY; - if (!strcmp(str, "force")) - return SHMEM_HUGE_FORCE; - return -EINVAL; + huge = SHMEM_HUGE_NEVER; + else if (!strcmp(str, "always")) + huge = SHMEM_HUGE_ALWAYS; + else if (!strcmp(str, "within_size")) + huge = SHMEM_HUGE_WITHIN_SIZE; + else if (!strcmp(str, "advise")) + huge = SHMEM_HUGE_ADVISE; + else if (!strcmp(str, "deny")) + huge = SHMEM_HUGE_DENY; + else if (!strcmp(str, "force")) + huge = SHMEM_HUGE_FORCE; + else + return -EINVAL; + + if (!has_transparent_hugepage() && + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) + return -EINVAL; + + /* Do not override huge allocation policy with non-PMD sized mTHP */ + if (huge == SHMEM_HUGE_FORCE && + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) + return -EINVAL; + + return huge; } -#endif #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS) static const char *shmem_format_huge(int huge) @@ -5104,16 +5119,8 @@ static ssize_t shmem_enabled_store(struct kobject *kobj, tmp[count - 1] = '\0'; huge = shmem_parse_huge(tmp); - if (huge == -EINVAL) - return -EINVAL; - if (!has_transparent_hugepage() && - huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) - return -EINVAL; - - /* Do not override huge allocation policy with non-PMD sized mTHP */ - if (huge == SHMEM_HUGE_FORCE && - huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) - return -EINVAL; + if (huge < 0) + return huge; shmem_huge = huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5210,6 +5217,25 @@ 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; + + huge = shmem_parse_huge(str); + if (huge < 0) { + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n"); + return 0; + } + + shmem_huge = huge; + return 1; +} +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ /*