From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: bpf <bpf@vger.kernel.org>, Andrii Nakryiko <andrii@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Sebastian Sewior <bigeasy@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Hou Tao <houtao1@huawei.com>,
Johannes Weiner <hannes@cmpxchg.org>,
shakeel.butt@linux.dev, Michal Hocko <mhocko@suse.com>,
Matthew Wilcox <willy@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>, Tejun Heo <tj@kernel.org>,
linux-mm <linux-mm@kvack.org>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v2 2/6] mm, bpf: Introduce free_pages_nolock()
Date: Wed, 11 Dec 2024 17:43:01 -0800 [thread overview]
Message-ID: <CAADnVQL2ys3zO2TncNXydC6_fbAQ-GrEJMiH3yx9My0AHr2=sA@mail.gmail.com> (raw)
In-Reply-To: <c9433086-04e3-4c58-a7b6-a64d986ab1e2@suse.cz>
On Wed, Dec 11, 2024 at 2:11 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 12/10/24 03:39, Alexei Starovoitov wrote:
> > From: Alexei Starovoitov <ast@kernel.org>
> >
> > Introduce free_pages_nolock() that can free a page without taking locks.
> > It relies on trylock only and can be called from any context.
> >
> > Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>
> <snip>
>
> > +/* Can be called while holding raw_spin_lock or from IRQ. RCU must be watching. */
> > +void free_pages_nolock(struct page *page, unsigned int order)
>
> What does "RCU must be watching" mean and why?
Meaning that rcu_is_watching() must be true.
Because pgalloc_tag_get() relies on RCU.
ree_unref_page() and things it calls doesn't use RCU directly,
but it calls tracepoints and they need RCU too.
Hence the comment to say that free_pages_nolock() cannot be
called in _any_ context. Some care needs to be taken.
bpf needs RCU, so we don't allow attach bpf to idle and notrace,
but, last I heard, notrace attr is not 100% reliable on some odd arch-es.
> > +{
> > + int head = PageHead(page);
> > + struct alloc_tag *tag = pgalloc_tag_get(page);
> > +
> > + if (put_page_testzero(page)) {
> > + __free_unref_page(page, order, FPI_TRYLOCK);
> > + } else if (!head) {
> > + pgalloc_tag_sub_pages(tag, (1 << order) - 1);
> > + while (order-- > 0)
> > + __free_unref_page(page + (1 << order), order, FPI_TRYLOCK);
>
> Not your fault for trying to support everything __free_pages did,
> specifically order > 0 pages that are not compound and thus needing this
> extra !head branch. We'd love to get rid of that eventually in
> __free_pages(), but at least I think we don't need to support it in a new
> API and instead any users switching to it should know it's not supported.
Great. Good to know.
> I suppose BFP doesn't need that, right?
Nope.
Initially I wrote above bit as:
void free_pages_nolock(struct page *page, unsigned int order)
{
if (put_page_testzero(page))
__free_unref_page(page, order, FPI_TRYLOCK);
}
but then I studied Matthew's commit
e320d3012d25 ("mm/page_alloc.c: fix freeing non-compound pages")
and couldn't convince myself that the race he described
+ get_page(page);
+ free_pages(addr, 3);
+ put_page(page);
will never happen.
It won't happen if bpf is the only user of this api,
but who knows what happens in the future.
So copy-pasted this part just in case.
Will be happy to drop it.
> Maybe if the function was taking a folio instead of page, it would be the
> best as that has to be order-0 or compound by definition. It also wouldn't
> need the order parameter. What do you think, Matthew?
For bpf there is no use case for folios.
All we need is a page order 0 and separately
later kmalloc_nolock() will call it from new_slab().
And I think new_slab() might need order >= 1.
So that's the reason to have order parameter.
next prev parent reply other threads:[~2024-12-12 1:43 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 2:39 [PATCH bpf-next v2 0/6] bpf, mm: Introduce __GFP_TRYLOCK Alexei Starovoitov
2024-12-10 2:39 ` [PATCH bpf-next v2 1/6] mm, bpf: Introduce __GFP_TRYLOCK for opportunistic page allocation Alexei Starovoitov
2024-12-10 5:31 ` Matthew Wilcox
2024-12-10 9:05 ` Michal Hocko
2024-12-10 20:25 ` Shakeel Butt
2024-12-11 10:08 ` Michal Hocko
2024-12-10 22:06 ` Alexei Starovoitov
2024-12-11 10:19 ` Michal Hocko
2024-12-12 15:07 ` Sebastian Sewior
2024-12-12 15:21 ` Michal Hocko
2024-12-12 15:35 ` Sebastian Sewior
2024-12-12 15:48 ` Steven Rostedt
2024-12-12 16:00 ` Sebastian Sewior
2024-12-13 17:44 ` Steven Rostedt
2024-12-13 18:44 ` Alexei Starovoitov
2024-12-13 18:57 ` Alexei Starovoitov
2024-12-13 20:09 ` Steven Rostedt
2024-12-13 21:00 ` Steven Rostedt
2024-12-13 22:02 ` Alexei Starovoitov
2024-12-12 21:57 ` Alexei Starovoitov
2024-12-10 21:42 ` Alexei Starovoitov
2024-12-10 9:01 ` Sebastian Andrzej Siewior
2024-12-10 21:53 ` Alexei Starovoitov
2024-12-11 8:38 ` Vlastimil Babka
2024-12-12 2:14 ` Alexei Starovoitov
2024-12-12 8:54 ` Vlastimil Babka
2024-12-10 18:39 ` Vlastimil Babka
2024-12-10 22:42 ` Alexei Starovoitov
2024-12-11 8:48 ` Vlastimil Babka
2024-12-10 2:39 ` [PATCH bpf-next v2 2/6] mm, bpf: Introduce free_pages_nolock() Alexei Starovoitov
2024-12-10 8:35 ` Sebastian Andrzej Siewior
2024-12-10 22:49 ` Alexei Starovoitov
2024-12-12 14:44 ` Sebastian Andrzej Siewior
2024-12-12 19:57 ` Alexei Starovoitov
2024-12-11 10:11 ` Vlastimil Babka
2024-12-12 1:43 ` Alexei Starovoitov [this message]
2024-12-10 2:39 ` [PATCH bpf-next v2 3/6] locking/local_lock: Introduce local_trylock_irqsave() Alexei Starovoitov
2024-12-11 10:53 ` Vlastimil Babka
2024-12-11 11:55 ` Vlastimil Babka
2024-12-12 2:49 ` Alexei Starovoitov
2024-12-12 9:15 ` Vlastimil Babka
2024-12-13 14:02 ` Vlastimil Babka
2024-12-12 15:15 ` Sebastian Andrzej Siewior
2024-12-12 19:59 ` Alexei Starovoitov
2024-12-10 2:39 ` [PATCH bpf-next v2 4/6] memcg: Add __GFP_TRYLOCK support Alexei Starovoitov
2024-12-11 23:47 ` kernel test robot
2024-12-10 2:39 ` [PATCH bpf-next v2 5/6] mm, bpf: Use __GFP_ACCOUNT in try_alloc_pages() Alexei Starovoitov
2024-12-11 12:05 ` Vlastimil Babka
2024-12-12 2:54 ` Alexei Starovoitov
2024-12-10 2:39 ` [PATCH bpf-next v2 6/6] bpf: Use try_alloc_pages() to allocate pages for bpf needs Alexei Starovoitov
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='CAADnVQL2ys3zO2TncNXydC6_fbAQ-GrEJMiH3yx9My0AHr2=sA@mail.gmail.com' \
--to=alexei.starovoitov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=houtao1@huawei.com \
--cc=kernel-team@fb.com \
--cc=linux-mm@kvack.org \
--cc=memxor@gmail.com \
--cc=mhocko@suse.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--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