From: Vlastimil Babka <vbabka@suse.cz>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Cc: andrii@kernel.org, memxor@gmail.com, akpm@linux-foundation.org,
peterz@infradead.org, bigeasy@linutronix.de, rostedt@goodmis.org,
houtao1@huawei.com, hannes@cmpxchg.org, shakeel.butt@linux.dev,
mhocko@suse.com, willy@infradead.org, tglx@linutronix.de,
tj@kernel.org, linux-mm@kvack.org, kernel-team@fb.com
Subject: Re: [PATCH bpf-next v2 5/6] mm, bpf: Use __GFP_ACCOUNT in try_alloc_pages().
Date: Wed, 11 Dec 2024 13:05:18 +0100 [thread overview]
Message-ID: <4233d087-4610-475e-bc79-14feaf2f7cfd@suse.cz> (raw)
In-Reply-To: <20241210023936.46871-6-alexei.starovoitov@gmail.com>
On 12/10/24 03:39, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> Unconditionally use __GFP_ACCOUNT in try_alloc_pages().
> The caller is responsible to setup memcg correctly.
> All BPF memory accounting is memcg based.
Hm I guess if there was later another user besides bpf that didn't want
memcg for some reason, a variant of the function (or a bool param, to avoid
passing full gfp param which would be thrown away besides __GFP_ACCOUNT)
could be easily created.
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> include/linux/gfp.h | 5 ++---
> mm/page_alloc.c | 5 ++++-
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index dcae733ed006..820c4938c9cd 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -356,18 +356,17 @@ static inline struct page *try_alloc_pages_noprof(int nid, unsigned int order)
> */
> if (preemptible() && !rcu_preempt_depth())
> return alloc_pages_node_noprof(nid,
> - GFP_NOWAIT | __GFP_ZERO,
> + GFP_NOWAIT | __GFP_ZERO | __GFP_ACCOUNT,
> order);
> /*
> * Best effort allocation from percpu free list.
> * If it's empty attempt to spin_trylock zone->lock.
> * Do not specify __GFP_KSWAPD_RECLAIM to avoid wakeup_kswapd
> * that may need to grab a lock.
> - * Do not specify __GFP_ACCOUNT to avoid local_lock.
> * Do not warn either.
> */
> return alloc_pages_node_noprof(nid,
> - __GFP_TRYLOCK | __GFP_NOWARN | __GFP_ZERO,
> + __GFP_TRYLOCK | __GFP_NOWARN | __GFP_ZERO | __GFP_ACCOUNT,
> order);
> }
> #define try_alloc_pages(...) alloc_hooks(try_alloc_pages_noprof(__VA_ARGS__))
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index a969a62ec0c3..1fada16b8a14 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -4818,7 +4818,10 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order,
> out:
> if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page &&
> unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) {
> - __free_pages(page, order);
> + if (unlikely(gfp & __GFP_TRYLOCK))
> + free_pages_nolock(page, order);
> + else
> + __free_pages(page, order);
> page = NULL;
> }
>
next prev parent reply other threads:[~2024-12-11 12:05 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
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 [this message]
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=4233d087-4610-475e-bc79-14feaf2f7cfd@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--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=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