diff mbox series

[bpf-next,2/2] bpf: Use try_alloc_page() to allocate pages for bpf needs.

Message ID 20241116014854.55141-2-alexei.starovoitov@gmail.com (mailing list archive)
State New
Headers show
Series [bpf-next,1/2] mm, bpf: Introduce __GFP_TRYLOCK for opportunistic page allocation | expand

Commit Message

Alexei Starovoitov Nov. 16, 2024, 1:48 a.m. UTC
From: Alexei Starovoitov <ast@kernel.org>

Incomplete patch.

If the __GFP_TRYLOCK approach is acceptable the support
for memcg charging and async page freeing will follow.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/bpf/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 58190ca724a2..26e6cffb2fe9 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -581,12 +581,14 @@  int bpf_map_alloc_pages(const struct bpf_map *map, gfp_t gfp, int nid,
 	old_memcg = set_active_memcg(memcg);
 #endif
 	for (i = 0; i < nr_pages; i++) {
-		pg = alloc_pages_node(nid, gfp | __GFP_ACCOUNT, 0);
+		/* TODO: add async memcg charge */
+		pg = try_alloc_page(nid);
 
 		if (pg) {
 			pages[i] = pg;
 			continue;
 		}
+		/* TODO: add async page free */
 		for (j = 0; j < i; j++)
 			__free_page(pages[j]);
 		ret = -ENOMEM;