diff options
author | Yafang Shao <laoar.shao@gmail.com> | 2023-02-10 15:47:33 +0000 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-02-10 18:59:57 -0800 |
commit | ee53cbfb1ebf990de0d084a7cd6b67b05fe1f7ac (patch) | |
tree | 84caf90a458c9dbead8cb0c2fcdf0dc75d8a5a1f /include | |
parent | ddef81b5fd1da4d7c3cc8785d2043b73b72f38ef (diff) | |
download | linux-stable-ee53cbfb1ebf990de0d084a7cd6b67b05fe1f7ac.tar.gz linux-stable-ee53cbfb1ebf990de0d084a7cd6b67b05fe1f7ac.tar.bz2 linux-stable-ee53cbfb1ebf990de0d084a7cd6b67b05fe1f7ac.zip |
bpf: allow to disable bpf map memory accounting
We can simply set root memcg as the map's memcg to disable bpf memory
accounting. bpf_map_area_alloc is a little special as it gets the memcg
from current rather than from the map, so we need to disable GFP_ACCOUNT
specifically for it.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Link: https://lore.kernel.org/r/20230210154734.4416-4-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/bpf.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index fe0bf482fdf8..4385418118f6 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -28,6 +28,7 @@ #include <linux/btf.h> #include <linux/rcupdate_trace.h> #include <linux/static_call.h> +#include <linux/memcontrol.h> struct bpf_verifier_env; struct bpf_verifier_log; @@ -2933,4 +2934,11 @@ static inline bool type_is_alloc(u32 type) return type & MEM_ALLOC; } +static inline gfp_t bpf_memcg_flags(gfp_t flags) +{ + if (memcg_bpf_enabled()) + return flags | __GFP_ACCOUNT; + return flags; +} + #endif /* _LINUX_BPF_H */ |