From: Muchun Song <songmuchun@bytedance.com>
To: Mike Kravetz <mike.kravetz@oracle.com>,
Mina Almasry <almasrymina@google.com>
Cc: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>, Miaohe Lin <linmiaohe@huawei.com>,
Oscar Salvador <osalvador@suse.de>,
Michal Hocko <mhocko@suse.com>,
David Rientjes <rientjes@google.com>,
Shakeel Butt <shakeelb@google.com>, Jue Wang <juew@google.com>,
Yang Yao <ygyao@google.com>, Joanna Li <joannali@google.com>,
Cannon Matthews <cannonmatthews@google.com>,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>,
linux-doc@vger.kernel.org
Subject: Re: [PATCH v7] hugetlb: Add hugetlb.*.numa_stat file
Date: Thu, 18 Nov 2021 11:54:37 +0800 [thread overview]
Message-ID: <CAMZfGtXgYPVOsGUE8OOzkx8K14BjHoMS1hLvxXX77+5cSycrPw@mail.gmail.com> (raw)
In-Reply-To: <86d3ba7a-3706-d66c-cbf7-d2c39ad2cd4c@oracle.com>
On Thu, Nov 18, 2021 at 8:13 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
> On 11/17/21 12:18, Mina Almasry wrote:
> ...
> > diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> ...
> > @@ -288,11 +317,21 @@ static void __hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
> > struct hugetlb_cgroup *h_cg,
> > struct page *page, bool rsvd)
> > {
> > + unsigned long *usage;
> > +
>
> I assume the use of a pointer is just to make the following WRITE_ONCE
> look better? I prefer the suggestion by Muchun:
>
> unsigned long usage = h_cg->nodeinfo[page_to_nid(page)]->usage[idx];
>
> usage += nr_pages;
> WRITE_ONCE(h_cg->nodeinfo[page_to_nid(page)]->usage[idx], usage);
>
> I had to think for just a second 'why are we using/passing a pointer?'.
> Not insisting we use Muchun's suggestion, it just caused me to think
> a little more than necessary.
At least I have the same question here. For me I think it's
unnecessary to use a pointer.
>
> In any case, I would move the variable usage inside the
> 'if (!rsvd)' block.
>
> > if (hugetlb_cgroup_disabled() || !h_cg)
> > return;
> >
> > __set_hugetlb_cgroup(page, h_cg, rsvd);
> > - return;
> > + if (!rsvd) {
> > + usage = &h_cg->nodeinfo[page_to_nid(page)]->usage[idx];
> > + /*
> > + * This write is not atomic due to fetching *usage and writing
> > + * to it, but that's fine because we call this with
> > + * hugetlb_lock held anyway.
> > + */
> > + WRITE_ONCE(*usage, *usage + nr_pages);
> > + }
> > }
> >
> > void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
> > @@ -316,6 +355,7 @@ static void __hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
> > struct page *page, bool rsvd)
> > {
> > struct hugetlb_cgroup *h_cg;
> > + unsigned long *usage;
>
> Same here.
>
> Otherwise, looks good to me.
> --
> Mike Kravetz
next prev parent reply other threads:[~2021-11-18 3:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 20:18 Mina Almasry
2021-11-18 0:12 ` Mike Kravetz
2021-11-18 3:54 ` Muchun Song [this message]
2021-11-18 4:15 ` Mina Almasry
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=CAMZfGtXgYPVOsGUE8OOzkx8K14BjHoMS1hLvxXX77+5cSycrPw@mail.gmail.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=almasrymina@google.com \
--cc=cannonmatthews@google.com \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=hannes@cmpxchg.org \
--cc=joannali@google.com \
--cc=juew@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@suse.com \
--cc=mike.kravetz@oracle.com \
--cc=osalvador@suse.de \
--cc=rientjes@google.com \
--cc=shakeelb@google.com \
--cc=shuah@kernel.org \
--cc=tj@kernel.org \
--cc=ygyao@google.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