Skip to content

Commit d5299b6

Browse files
Roman GushchinAlexei Starovoitov
authored andcommitted
bpf: Memcg-based memory accounting for bpf maps
This patch enables memcg-based memory accounting for memory allocated by __bpf_map_area_alloc(), which is used by many types of bpf maps for large initial memory allocations. Please note, that __bpf_map_area_alloc() should not be used outside of map creation paths without setting the active memory cgroup to the map's memory cgroup. Following patches in the series will refine the accounting for some of the map types. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20201201215900.3569844-8-guro@fb.com
1 parent 48edc1f commit d5299b6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎kernel/bpf/syscall.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,
268268
return err;
269269
}
270270

271+
/* Please, do not use this function outside from the map creation path
272+
* (e.g. in map update path) without taking care of setting the active
273+
* memory cgroup (see at bpf_map_kmalloc_node() for example).
274+
*/
271275
static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable)
272276
{
273277
/* We really just want to fail instead of triggering OOM killer
@@ -280,7 +284,7 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable)
280284
* __GFP_RETRY_MAYFAIL to avoid such situations.
281285
*/
282286

283-
const gfp_t gfp = __GFP_NOWARN | __GFP_ZERO;
287+
const gfp_t gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_ACCOUNT;
284288
unsigned int flags = 0;
285289
unsigned long align = 1;
286290
void *area;

0 commit comments

Comments
 (0)