linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: linux-kernel@vger.kernel.org,
	Linux Memory Management List <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Muchun Song <songmuchun@bytedance.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Matthew Wilcox <willy@infradead.org>,
	Mina Almasry <almasrymina@google.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	minhquangbui99@gmail.com, aneesh.kumar@linux.ibm.com
Subject: Re: [PATCH v2 2/9] mm/hugetlb_cgroup: convert hugetlb_cgroup_from_page() to folios
Date: Wed, 2 Nov 2022 14:25:13 +0800	[thread overview]
Message-ID: <A90972E2-85A3-49B2-8434-A2FBE9BCFBF4@linux.dev> (raw)
In-Reply-To: <20221101223059.460937-3-sidhartha.kumar@oracle.com>



> On Nov 2, 2022, at 06:30, Sidhartha Kumar <sidhartha.kumar@oracle.com> wrote:
> 
> Introduce folios in __remove_hugetlb_page() by converting
> hugetlb_cgroup_from_page() to use folios.
> 
> Also gets rid of unsed hugetlb_cgroup_from_page_resv() function.
> 
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

A nit below.

> ---
> include/linux/hugetlb_cgroup.h | 39 +++++++++++++++++-----------------
> mm/hugetlb.c                   |  5 +++--
> mm/hugetlb_cgroup.c            | 13 +++++++-----
> 3 files changed, 31 insertions(+), 26 deletions(-)
> 
> diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgroup.h
> index 7576e9ed8afe..feb2edafc8b6 100644
> --- a/include/linux/hugetlb_cgroup.h
> +++ b/include/linux/hugetlb_cgroup.h
> @@ -67,27 +67,34 @@ struct hugetlb_cgroup {
> };
> 
> static inline struct hugetlb_cgroup *
> -__hugetlb_cgroup_from_page(struct page *page, bool rsvd)
> +__hugetlb_cgroup_from_folio(struct folio *folio, bool rsvd)
> {
> - VM_BUG_ON_PAGE(!PageHuge(page), page);
> + struct page *tail;
> 
> - if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
> + VM_BUG_ON_FOLIO(!folio_test_hugetlb(folio), folio);
> + if (folio_order(folio) < HUGETLB_CGROUP_MIN_ORDER)
> return NULL;
> - if (rsvd)
> - return (void *)page_private(page + SUBPAGE_INDEX_CGROUP_RSVD);
> - else
> - return (void *)page_private(page + SUBPAGE_INDEX_CGROUP);
> +
> + if (rsvd) {
> + tail = folio_page(folio, SUBPAGE_INDEX_CGROUP_RSVD);
> + return (void *)page_private(tail);
> + }
> +
> + else {
> + tail = folio_page(folio, SUBPAGE_INDEX_CGROUP);
> + return (void *)page_private(tail);
> + }

I suggest reworking the code here to the following (Looks simple for me).

int i = rsvd ? SUBPAGE_INDEX_CGROUP_RSVD : SUBPAGE_INDEX_CGROUP;

return (void *)page_private(folio_page(folio, i));

> }
> 
> -static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
> +static inline struct hugetlb_cgroup *hugetlb_cgroup_from_folio(struct folio *folio)
> {
> - return __hugetlb_cgroup_from_page(page, false);
> + return __hugetlb_cgroup_from_folio(folio, false);
> }
> 
> static inline struct hugetlb_cgroup *
> -hugetlb_cgroup_from_page_rsvd(struct page *page)
> +hugetlb_cgroup_from_folio_rsvd(struct folio *folio)
> {
> - return __hugetlb_cgroup_from_page(page, true);
> + return __hugetlb_cgroup_from_folio(folio, true);
> }
> 
> static inline void __set_hugetlb_cgroup(struct folio *folio,
> @@ -181,19 +188,13 @@ static inline void hugetlb_cgroup_uncharge_file_region(struct resv_map *resv,
> {
> }
> 
> -static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
> -{
> - return NULL;
> -}
> -
> -static inline struct hugetlb_cgroup *
> -hugetlb_cgroup_from_page_resv(struct page *page)
> +static inline struct hugetlb_cgroup *hugetlb_cgroup_from_folio(struct folio *folio)
> {
> return NULL;
> }
> 
> static inline struct hugetlb_cgroup *
> -hugetlb_cgroup_from_page_rsvd(struct page *page)
> +hugetlb_cgroup_from_folio_rsvd(struct folio *folio)
> {
> return NULL;
> }
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 518dfd0a7dbe..27b87dc85c48 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1434,9 +1434,10 @@ static void __remove_hugetlb_page(struct hstate *h, struct page *page,
> bool demote)
> {
> int nid = page_to_nid(page);
> + struct folio *folio = page_folio(page);
> 
> - VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page);
> - VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page);
> + VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio(folio), folio);
> + VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio_rsvd(folio), folio);
> 
> lockdep_assert_held(&hugetlb_lock);
> if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> index 81675f8f44e9..600c98560a0f 100644
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -191,8 +191,9 @@ static void hugetlb_cgroup_move_parent(int idx, struct hugetlb_cgroup *h_cg,
> struct page_counter *counter;
> struct hugetlb_cgroup *page_hcg;
> struct hugetlb_cgroup *parent = parent_hugetlb_cgroup(h_cg);
> + struct folio *folio = page_folio(page);
> 
> - page_hcg = hugetlb_cgroup_from_page(page);
> + page_hcg = hugetlb_cgroup_from_folio(folio);
> /*
> * We can have pages in active list without any cgroup
> * ie, hugepage with less than 3 pages. We can safely
> @@ -352,14 +353,15 @@ static void __hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
>   struct page *page, bool rsvd)
> {
> struct hugetlb_cgroup *h_cg;
> + struct folio *folio = page_folio(page);
> 
> if (hugetlb_cgroup_disabled())
> return;
> lockdep_assert_held(&hugetlb_lock);
> - h_cg = __hugetlb_cgroup_from_page(page, rsvd);
> + h_cg = __hugetlb_cgroup_from_folio(folio, rsvd);
> if (unlikely(!h_cg))
> return;
> - __set_hugetlb_cgroup(page_folio(page), NULL, rsvd);
> + __set_hugetlb_cgroup(folio, NULL, rsvd);
> 
> page_counter_uncharge(__hugetlb_cgroup_counter_from_cgroup(h_cg, idx,
>   rsvd),
> @@ -891,13 +893,14 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
> struct hugetlb_cgroup *h_cg;
> struct hugetlb_cgroup *h_cg_rsvd;
> struct hstate *h = page_hstate(oldhpage);
> + struct folio *old_folio = page_folio(oldhpage);
> 
> if (hugetlb_cgroup_disabled())
> return;
> 
> spin_lock_irq(&hugetlb_lock);
> - h_cg = hugetlb_cgroup_from_page(oldhpage);
> - h_cg_rsvd = hugetlb_cgroup_from_page_rsvd(oldhpage);
> + h_cg = hugetlb_cgroup_from_folio(old_folio);
> + h_cg_rsvd = hugetlb_cgroup_from_folio_rsvd(old_folio);
> set_hugetlb_cgroup(oldhpage, NULL);
> set_hugetlb_cgroup_rsvd(oldhpage, NULL);
> 
> -- 
> 2.31.1
> 
> 



  reply	other threads:[~2022-11-02  6:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 22:30 [PATCH v2 0/9] convert hugetlb_cgroup helper functions " Sidhartha Kumar
2022-11-01 22:30 ` [PATCH v2 1/9] mm/hugetlb_cgroup: convert __set_hugetlb_cgroup() " Sidhartha Kumar
2022-11-02  3:05   ` Muchun Song
2022-11-01 22:30 ` [PATCH v2 2/9] mm/hugetlb_cgroup: convert hugetlb_cgroup_from_page() " Sidhartha Kumar
2022-11-02  6:25   ` Muchun Song [this message]
2022-11-01 22:30 ` [PATCH v2 3/9] mm/hugetlb_cgroup: convert set_hugetlb_cgroup*() " Sidhartha Kumar
2022-11-02  6:45   ` Muchun Song
2022-11-10  0:20     ` Sidhartha Kumar
2022-11-10  7:34       ` Muchun Song
2022-11-10 19:08   ` Mike Kravetz
2022-11-01 22:30 ` [PATCH v2 4/9] mm/hugetlb_cgroup: convert hugetlb_cgroup_migrate " Sidhartha Kumar
2022-11-02  6:47   ` Muchun Song
2022-11-01 22:30 ` [PATCH v2 5/9] mm/hugetlb: convert isolate_or_dissolve_huge_page " Sidhartha Kumar
2022-11-02  6:48   ` Muchun Song
2023-06-12 17:41   ` Matthew Wilcox
2023-06-12 18:45     ` Sidhartha Kumar
2023-06-12 23:34     ` Mike Kravetz
2023-06-13 23:29       ` Mike Kravetz
2022-11-01 22:30 ` [PATCH v2 6/9] mm/hugetlb: convert free_huge_page " Sidhartha Kumar
2022-11-02  6:53   ` Muchun Song
2022-11-01 22:30 ` [PATCH v2 7/9] mm/hugetlb_cgroup: convert hugetlb_cgroup_uncharge_page() " Sidhartha Kumar
2022-11-02  6:56   ` Muchun Song
2022-11-01 22:30 ` [PATCH v2 8/9] mm/hugeltb_cgroup: convert hugetlb_cgroup_commit_charge*() " Sidhartha Kumar
2022-11-02  6:57   ` Muchun Song
2022-11-01 22:30 ` [PATCH v2 9/9] mm/hugetlb: convert move_hugetlb_state() " Sidhartha Kumar
2022-11-02  7:01   ` Muchun 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=A90972E2-85A3-49B2-8434-A2FBE9BCFBF4@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=minhquangbui99@gmail.com \
    --cc=sidhartha.kumar@oracle.com \
    --cc=songmuchun@bytedance.com \
    --cc=willy@infradead.org \
    /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