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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 kernel/bpf/syscall.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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;
-- 
2.17.1




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux