diff mbox series

[06/14] bpf: Allow no charge for allocation not at map creation time

Message ID 20220319173036.23352-7-laoar.shao@gmail.com (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series bpf: Allow not to charge bpf memory | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Yafang Shao March 19, 2022, 5:30 p.m. UTC
Below three functions are used for memory allocation which is not at
map creation time,
  - bpf_map_kmalloc_node()
  - bpf_map_kzalloc()
  - bpf_map_alloc_percpu()

For this kind of path, we can get the no charge flag from bpf_map
struct we set before.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 kernel/bpf/syscall.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index add3b4045b4d..e84aeefa05f4 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -434,7 +434,8 @@  void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags,
 	void *ptr;
 
 	old_memcg = set_active_memcg(map->memcg);
-	ptr = kmalloc_node(size, flags | __GFP_ACCOUNT, node);
+	ptr = kmalloc_node(size, bpf_flags_no_charge(flags, map->no_charge),
+			node);
 	set_active_memcg(old_memcg);
 
 	return ptr;
@@ -446,7 +447,7 @@  void *bpf_map_kzalloc(const struct bpf_map *map, size_t size, gfp_t flags)
 	void *ptr;
 
 	old_memcg = set_active_memcg(map->memcg);
-	ptr = kzalloc(size, flags | __GFP_ACCOUNT);
+	ptr = kzalloc(size, bpf_flags_no_charge(flags, map->no_charge));
 	set_active_memcg(old_memcg);
 
 	return ptr;
@@ -459,7 +460,8 @@  void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size,
 	void __percpu *ptr;
 
 	old_memcg = set_active_memcg(map->memcg);
-	ptr = __alloc_percpu_gfp(size, align, flags | __GFP_ACCOUNT);
+	ptr = __alloc_percpu_gfp(size, align,
+			bpf_flags_no_charge(flags, map->no_charge));
 	set_active_memcg(old_memcg);
 
 	return ptr;