All of lore.kernel.org
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: Muchun Song <songmuchun@bytedance.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Oscar Salvador <osalvador@suse.de>,
	Michal Hocko <mhocko@suse.com>,
	Barry Song <song.bao.hua@hisilicon.com>,
	David Hildenbrand <david@redhat.com>,
	Chen Huang <chenhuang5@huawei.com>,
	"Bodeddula, Balasubramaniam" <bodeddub@amazon.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Matthew Wilcox <willy@infradead.org>,
	Xiongchun duan <duanxiongchun@bytedance.com>,
	fam.zheng@bytedance.com, Muchun Song <smuchun@gmail.com>,
	Qi Zheng <zhengqi.arch@bytedance.com>,
	linux-doc@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>
Subject: Re: [PATCH v4 2/5] mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key
Date: Mon, 27 Sep 2021 09:13:27 +1300	[thread overview]
Message-ID: <CAGsJ_4yvSwtxR7yWjS=Nb8JwT7TiaCm4s4=0YKEQpqOZeZOdyA@mail.gmail.com> (raw)
In-Reply-To: <20210926031339.40043-3-songmuchun@bytedance.com>

On Sun, Sep 26, 2021 at 4:15 PM Muchun Song <songmuchun@bytedance.com> wrote:
>
> The page_head_if_fake() is used throughout memory management and the
> conditional check requires checking a global variable, although the
> overhead of this check may be small, it increases when the memory
> cache comes under pressure. Also, the global variable will not be
> modified after system boot, so it is very appropriate to use static
> key machanism.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>

Reviewed-by: Barry Song <song.bao.hua@hisilicon.com>

> ---
>  include/linux/hugetlb.h    |  6 ------
>  include/linux/page-flags.h | 18 +++++++++++++++---
>  mm/hugetlb_vmemmap.c       | 12 ++++++------
>  mm/memory_hotplug.c        |  2 +-
>  4 files changed, 22 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 3cbf60464398..a90cc88195da 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -1055,12 +1055,6 @@ static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr
>  }
>  #endif /* CONFIG_HUGETLB_PAGE */
>
> -#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP
> -extern bool hugetlb_free_vmemmap_enabled;
> -#else
> -#define hugetlb_free_vmemmap_enabled   false
> -#endif
> -
>  static inline spinlock_t *huge_pte_lock(struct hstate *h,
>                                         struct mm_struct *mm, pte_t *pte)
>  {
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index b49808e748ce..26e540fd3393 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -185,7 +185,14 @@ enum pageflags {
>  #ifndef __GENERATING_BOUNDS_H
>
>  #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP
> -extern bool hugetlb_free_vmemmap_enabled;
> +DECLARE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON,
> +                        hugetlb_free_vmemmap_enabled_key);
> +
> +static __always_inline bool hugetlb_free_vmemmap_enabled(void)
> +{
> +       return static_branch_maybe(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON,
> +                                  &hugetlb_free_vmemmap_enabled_key);
> +}
>
>  /*
>   * If the feature of freeing some vmemmap pages associated with each HugeTLB
> @@ -205,7 +212,7 @@ extern bool hugetlb_free_vmemmap_enabled;
>   */
>  static __always_inline const struct page *page_fixed_fake_head(const struct page *page)
>  {
> -       if (!hugetlb_free_vmemmap_enabled)
> +       if (!hugetlb_free_vmemmap_enabled())
>                 return page;
>
>         /*
> @@ -229,10 +236,15 @@ static __always_inline const struct page *page_fixed_fake_head(const struct page
>         return page;
>  }
>  #else
> -static __always_inline const struct page *page_fixed_fake_head(const struct page *page)
> +static inline const struct page *page_fixed_fake_head(const struct page *page)
>  {
>         return page;
>  }
> +
> +static inline bool hugetlb_free_vmemmap_enabled(void)
> +{
> +       return false;
> +}
>  #endif
>
>  static __always_inline int page_is_fake_head(struct page *page)
> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> index f4a8fca691ee..22ecb5e21686 100644
> --- a/mm/hugetlb_vmemmap.c
> +++ b/mm/hugetlb_vmemmap.c
> @@ -188,9 +188,9 @@
>  #define RESERVE_VMEMMAP_NR             1U
>  #define RESERVE_VMEMMAP_SIZE           (RESERVE_VMEMMAP_NR << PAGE_SHIFT)
>
> -bool hugetlb_free_vmemmap_enabled __read_mostly =
> -       IS_ENABLED(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON);
> -EXPORT_SYMBOL(hugetlb_free_vmemmap_enabled);
> +DEFINE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON,
> +                       hugetlb_free_vmemmap_enabled_key);
> +EXPORT_SYMBOL(hugetlb_free_vmemmap_enabled_key);
>
>  static int __init early_hugetlb_free_vmemmap_param(char *buf)
>  {
> @@ -204,9 +204,9 @@ static int __init early_hugetlb_free_vmemmap_param(char *buf)
>                 return -EINVAL;
>
>         if (!strcmp(buf, "on"))
> -               hugetlb_free_vmemmap_enabled = true;
> +               static_branch_enable(&hugetlb_free_vmemmap_enabled_key);
>         else if (!strcmp(buf, "off"))
> -               hugetlb_free_vmemmap_enabled = false;
> +               static_branch_disable(&hugetlb_free_vmemmap_enabled_key);
>         else
>                 return -EINVAL;
>
> @@ -284,7 +284,7 @@ void __init hugetlb_vmemmap_init(struct hstate *h)
>         BUILD_BUG_ON(__NR_USED_SUBPAGE >=
>                      RESERVE_VMEMMAP_SIZE / sizeof(struct page));
>
> -       if (!hugetlb_free_vmemmap_enabled)
> +       if (!hugetlb_free_vmemmap_enabled())
>                 return;
>
>         vmemmap_pages = (nr_pages * sizeof(struct page)) >> PAGE_SHIFT;
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 4ea91c3ff768..66eaa4e2e76f 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1341,7 +1341,7 @@ bool mhp_supports_memmap_on_memory(unsigned long size)
>          *       populate a single PMD.
>          */
>         return memmap_on_memory &&
> -              !hugetlb_free_vmemmap_enabled &&
> +              !hugetlb_free_vmemmap_enabled() &&
>                IS_ENABLED(CONFIG_MHP_MEMMAP_ON_MEMORY) &&
>                size == memory_block_size_bytes() &&
>                IS_ALIGNED(vmemmap_size, PMD_SIZE) &&
> --
> 2.11.0
>

  reply	other threads:[~2021-09-26 20:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-26  3:13 [PATCH v4 0/5] Free the 2nd vmemmap page associated with each HugeTLB page Muchun Song
2021-09-26  3:13 ` [PATCH v4 1/5] mm: hugetlb: free " Muchun Song
2021-09-26 20:24   ` Barry Song
2021-09-26 20:24     ` Barry Song
2021-09-28  2:42     ` Muchun Song
2021-09-28  2:42       ` Muchun Song
2021-09-26  3:13 ` [PATCH v4 2/5] mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key Muchun Song
2021-09-26 20:13   ` Barry Song [this message]
2021-09-26 20:13     ` Barry Song
2021-09-26  3:13 ` [PATCH v4 3/5] mm: sparsemem: use page table lock to protect kernel pmd operations Muchun Song
2021-09-26  3:13 ` [PATCH v4 4/5] selftests: vm: add a hugetlb test case Muchun Song
2021-09-26  3:13 ` [PATCH v4 5/5] mm: sparsemem: move vmemmap related to HugeTLB to CONFIG_HUGETLB_PAGE_FREE_VMEMMAP Muchun Song
2021-09-27  4:38   ` Barry Song
2021-09-27  4:38     ` Barry Song

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='CAGsJ_4yvSwtxR7yWjS=Nb8JwT7TiaCm4s4=0YKEQpqOZeZOdyA@mail.gmail.com' \
    --to=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bodeddub@amazon.com \
    --cc=chenhuang5@huawei.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=duanxiongchun@bytedance.com \
    --cc=fam.zheng@bytedance.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mike.kravetz@oracle.com \
    --cc=osalvador@suse.de \
    --cc=smuchun@gmail.com \
    --cc=song.bao.hua@hisilicon.com \
    --cc=songmuchun@bytedance.com \
    --cc=willy@infradead.org \
    --cc=zhengqi.arch@bytedance.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.