From: Yu Zhao <yuzhao@google.com>
To: David Hildenbrand <david@redhat.com>, Mateusz Guzik <mjguzik@gmail.com>
Cc: akpm@linux-foundation.org, willy@infradead.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm: remove an avoidable load of page refcount in page_ref_add_unless
Date: Mon, 6 Jan 2025 21:41:51 -0700 [thread overview]
Message-ID: <CAOUHufZrt_QKM7HnNAGkFwJk1x5J5FtfUdoaAHUPoWtvSMLjPA@mail.gmail.com> (raw)
In-Reply-To: <eedb527e-34f6-4982-a258-cc27db933371@redhat.com>
On Mon, Dec 9, 2024 at 7:46 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 09.12.24 15:30, Mateusz Guzik wrote:
> > On Mon, Dec 9, 2024 at 3:22 PM David Hildenbrand <david@redhat.com> wrote:
> >>
> >> On 09.12.24 13:33, Mateusz Guzik wrote:
> >>> That is to say I think this thread just about exhausted the time
> >>> warranted by this patch. No hard feelz if it gets dropped, but then I
> >>> do strongly suggest adding a justification to the extra load.
> >>
> >> Maybe it's sufficient for now to simply do your change with a comment:
> >>
> >> diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
> >> index 8c236c651d1d6..1efc992ad5687 100644
> >> --- a/include/linux/page_ref.h
> >> +++ b/include/linux/page_ref.h
> >> @@ -234,7 +234,13 @@ static inline bool page_ref_add_unless(struct page *page, int nr, int u)
> >>
> >> rcu_read_lock();
> >> /* avoid writing to the vmemmap area being remapped */
> >> - if (!page_is_fake_head(page) && page_ref_count(page) != u)
> >> + if (!page_is_fake_head(page))
> >> + /*
> >> + * atomic_add_unless() will currently never modify the value
> >> + * if it already is u. If that ever changes, we'd have to have
> >> + * a separate check here, such that we won't be writing to
> >> + * write-protected vmemmap areas.
> >> + */
> >> ret = atomic_add_unless(&page->_refcount, nr, u);
> >> rcu_read_unlock();
> >>
> >>
> >> It would bail out during testing ... hopefully, such that we can detect any such change.
> >>
> >
> > Not my call to make, but looks good. ;)
> >
> > fwiw I don't need any credit and I would be more than happy if you
> > just submitted the thing as your own without me being mentioned. *No*
> > cc would also be appreciated.
>
> Likely Andrew can add the comment as a fixup.
Sorry for not getting back to you sooner: the page_ref_count() test
actually is a must, however, I didn't do it in the right order.
I only realized my carelessness after Will asked me about it here [1]
-- I just posted a fix here [2], CC'ing both of you. If any of you
have concerns about it, please let me know in that thread. Otherwise
I'll ask Andew to drop this patch. Thank you.
[1] https://lore.kernel.org/linux-mm/20241128142028.GA3506@willie-the-truck/
[2] https://lore.kernel.org/linux-mm/20250107043505.351925-1-yuzhao@google.com/
prev parent reply other threads:[~2025-01-07 4:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-07 8:29 Mateusz Guzik
2024-12-09 9:28 ` David Hildenbrand
2024-12-09 10:25 ` Mateusz Guzik
2024-12-09 10:56 ` David Hildenbrand
2024-12-09 12:33 ` Mateusz Guzik
2024-12-09 14:22 ` David Hildenbrand
2024-12-09 14:30 ` Mateusz Guzik
2024-12-09 14:46 ` David Hildenbrand
2025-01-07 4:41 ` Yu Zhao [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=CAOUHufZrt_QKM7HnNAGkFwJk1x5J5FtfUdoaAHUPoWtvSMLjPA@mail.gmail.com \
--to=yuzhao@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mjguzik@gmail.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