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 80B92D2AB1F for ; Tue, 29 Oct 2024 11:14:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEFB78D0002; Tue, 29 Oct 2024 07:14:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9EF78D0001; Tue, 29 Oct 2024 07:14:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C17C68D0002; Tue, 29 Oct 2024 07:14:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A2B998D0001 for ; Tue, 29 Oct 2024 07:14:19 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 40F3E8107F for ; Tue, 29 Oct 2024 11:14:19 +0000 (UTC) X-FDA: 82726379820.01.3E2BAD6 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf07.hostedemail.com (Postfix) with ESMTP id 21ECD40006 for ; Tue, 29 Oct 2024 11:13:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icbbYhzs; spf=pass (imf07.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730200246; 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=AYysOSKmA73dsvmvXqLdUufvFFewPZvF2sm/O7lEFDE=; b=rFsYWYOrDq5Zov7NSP/2LwTng/eRz9UQvag4JEr6ALZQCUuHtfygw9ErM77Pwjicg5wXQE mS93zHi4nrouPvbqUKQJu5CaW7JvJsIOYTyGCIYUoGuNXkwr8EP5SKYETlMGesoGTCTrGI RhKUXMAmQNRaEu+l2x8GwAiF3H6nifc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icbbYhzs; spf=pass (imf07.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730200246; a=rsa-sha256; cv=none; b=CRNNex7pylfxrfQzqnw/ZD4Ou7AFQmorgMzgq7Qdwz9PXPZsG/vsFumSGy52x7d+QShFtU BQfG+ZMWi0eFOAiSrusv3G0VX0IOMCW8Z1qVo1xkyFPHybGW/Gix27DYz+e/XNiyUyItJK 65yof4WrV8BIXEe8xIPr292XHzWBpz0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AYysOSKmA73dsvmvXqLdUufvFFewPZvF2sm/O7lEFDE=; b=icbbYhzsA3CPDkrmDlPobvrASF TgWFZ+UPrdLjSqKdy4qnTyfO3dPdOBuz3wIoPYsDwA2dtN3u+U99rTYrFd8MTIxEZHSDVj0jN9ktp uh1BMem9i7tZfX4kbBB/lhVtVHEPC7sXJnCqYlgmPhHV+/9RCzGWwtevCld+qNMmhfodP2Jf3p/pI ZQ8ZNixTBHlnihJ83ah3aOIeGcHBM7EyENVvL6m1GPrsL6MkbUidSffJ+fu9pUVi8+ezVacCwMLXn 4TKEYYWaNWkyHjUOCfKBijLiq9Fbdmjj8cSd8wp84sBTY6rqFCQRayWCW5QfjbqLucqM/mF2rwCBZ lSWMyx3A==; Received: from [187.36.213.55] (helo=[192.168.1.103]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) id 1t5kAm-00Gb04-T9; Tue, 29 Oct 2024 12:14:05 +0100 Message-ID: Date: Tue, 29 Oct 2024 08:13:59 -0300 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: Baolin Wang , 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> <6044e56a-7747-45d4-82c9-7a070950ddd2@linux.alibaba.com> Content-Language: en-US From: =?UTF-8?Q?Ma=C3=ADra_Canal?= In-Reply-To: <6044e56a-7747-45d4-82c9-7a070950ddd2@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 21ECD40006 X-Stat-Signature: whpbp3hxdrr7zxe7zxp4bcfujgbm87ep X-Rspam-User: X-HE-Tag: 1730200422-667665 X-HE-Meta: U2FsdGVkX18CW2b9fqRvPsCp8DEh0kLenhad5lnwWNYjX6jUDWqdZIBkhXJrbXzyBcB5sXPRXVhhDRcPnQSqFPvQz51r3mxuAG/z3zt0J/itFjLSrs4/F/l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UQoGiSJO1ZSCrOAbwZAEBOlgOk3DmiZNom+Pnf6XcXhoOCF27mHdrt5sp51/MCyCXPSqWZMh+8Jznr1rl3h29ck8X/NVsN3yTQy/bTHbgICEHb608xRnlJf34ROpr2n1848W9egywObhGeNbXeqf+S2vy+Rk8K8hGnBVniE6u4uS4pFhl+sY0jADzwNV4tHf2JA2axSkAMwi/AJOoeBbkk/LYFZi6tmtt/rTVNT/5IhQ== 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: Hi Baolin, On 28/10/24 23:03, Baolin Wang wrote: > > > 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? I haven't yet benchmark mTHP with V3D (Raspberry Pi's GPU) and also I still need to find the ideal combination of huge pages' sizes. But the idea is to benefit from the Super Pages support that I recently implemented in V3D [1]. Currently, I'm using a separate tmpfs mountpoint to implement Super Pages. I'll apply your refactor suggestion in the next version. Thanks! [1] https://mairacanal.github.io/unleashing-power-enabling-super-pages-on-RPi/ Best Regards, - Maíra > >> 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 */ > >  /*