From: Andrew Morton <akpm@linux-foundation.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>
Subject: Re: [PATCH v3 3/3] mm: page_counters: initialize usage using ATOMIC_LONG_INIT() macro
Date: Sun, 28 Jul 2024 13:54:47 -0700 [thread overview]
Message-ID: <20240728135447.bd5f7b44e1b7a583bfaaee36@linux-foundation.org> (raw)
In-Reply-To: <20240726231110.GF1702603@cmpxchg.org>
On Fri, 26 Jul 2024 19:11:10 -0400 Johannes Weiner <hannes@cmpxchg.org> wrote:
> On Fri, Jul 26, 2024 at 08:31:10PM +0000, Roman Gushchin wrote:
> > When a page_counter structure is initialized, there is no need to
> > use an atomic set operation to initialize the usage counter because
> > at this point the structure is not visible to anybody else.
> > ATOMIC_LONG_INIT() is what should be used in such cases.
> >
> > Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
> > ---
> > include/linux/page_counter.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h
> > index cf837d0f8ed1..5da11392b382 100644
> > --- a/include/linux/page_counter.h
> > +++ b/include/linux/page_counter.h
> > @@ -53,7 +53,7 @@ static inline void page_counter_init(struct page_counter *counter,
> > struct page_counter *parent,
> > bool protection_support)
> > {
> > - atomic_long_set(&counter->usage, 0);
> > + counter->usage = (atomic_long_t)ATOMIC_LONG_INIT(0);
>
> Pretty cool that ATOMIC_LONG_INIT() return value needs a cast to
> atomic_long_t! ^_^
That's because this wicked patch passed in an `int'.
counter->usage = ATOMIC_LONG_INIT((atomic_long_t)0);
prev parent reply other threads:[~2024-07-28 20:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 20:31 [PATCH v3 0/3] mm: memcg: page counters optimizations Roman Gushchin
2024-07-26 20:31 ` [PATCH v3 1/3] mm: memcg: don't call propagate_protected_usage() needlessly Roman Gushchin
2024-07-26 23:08 ` Johannes Weiner
2024-07-26 20:31 ` [PATCH v3 2/3] mm: page_counters: put page_counter_calculate_protection() under CONFIG_MEMCG Roman Gushchin
2024-07-26 23:09 ` Johannes Weiner
2024-07-26 20:31 ` [PATCH v3 3/3] mm: page_counters: initialize usage using ATOMIC_LONG_INIT() macro Roman Gushchin
2024-07-26 21:37 ` Shakeel Butt
2024-07-26 23:11 ` Johannes Weiner
2024-07-28 20:54 ` Andrew Morton [this message]
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=20240728135447.bd5f7b44e1b7a583bfaaee36@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
/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