[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200821150134.2581465-7-guro@fb.com>
Date: Fri, 21 Aug 2020 08:01:10 -0700
From: Roman Gushchin <guro@...com>
To: <bpf@...r.kernel.org>
CC: <netdev@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, <kernel-team@...com>,
<linux-kernel@...r.kernel.org>,
Johannes Weiner <hannes@...xchg.org>,
Shakeel Butt <shakeelb@...gle.com>, <linux-mm@...ck.org>,
Roman Gushchin <guro@...com>, Song Liu <songliubraving@...com>
Subject: [PATCH bpf-next v4 06/30] bpf: memcg-based memory accounting for cgroup storage maps
Account memory used by cgroup storage maps including the percpu memory
for the percpu flavor of cgroup storage and map metadata.
Signed-off-by: Roman Gushchin <guro@...com>
Acked-by: Song Liu <songliubraving@...com>
---
kernel/bpf/local_storage.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 571bb351ed3b..212d6dbbc39a 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -166,7 +166,8 @@ static int cgroup_storage_update_elem(struct bpf_map *map, void *key,
new = kmalloc_node(sizeof(struct bpf_storage_buffer) +
map->value_size,
- __GFP_ZERO | GFP_ATOMIC | __GFP_NOWARN,
+ __GFP_ZERO | GFP_ATOMIC | __GFP_NOWARN |
+ __GFP_ACCOUNT,
map->numa_node);
if (!new)
return -ENOMEM;
@@ -313,7 +314,7 @@ static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
return ERR_PTR(ret);
map = kmalloc_node(sizeof(struct bpf_cgroup_storage_map),
- __GFP_ZERO | GFP_USER, numa_node);
+ __GFP_ZERO | GFP_USER | __GFP_ACCOUNT, numa_node);
if (!map) {
bpf_map_charge_finish(&mem);
return ERR_PTR(-ENOMEM);
@@ -496,9 +497,9 @@ static size_t bpf_cgroup_storage_calculate_size(struct bpf_map *map, u32 *pages)
struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog,
enum bpf_cgroup_storage_type stype)
{
+ const gfp_t gfp = __GFP_ZERO | GFP_USER | __GFP_ACCOUNT;
struct bpf_cgroup_storage *storage;
struct bpf_map *map;
- gfp_t flags;
size_t size;
u32 pages;
@@ -511,20 +512,18 @@ struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog,
if (bpf_map_charge_memlock(map, pages))
return ERR_PTR(-EPERM);
- storage = kmalloc_node(sizeof(struct bpf_cgroup_storage),
- __GFP_ZERO | GFP_USER, map->numa_node);
+ storage = kmalloc_node(sizeof(struct bpf_cgroup_storage), gfp,
+ map->numa_node);
if (!storage)
goto enomem;
- flags = __GFP_ZERO | GFP_USER;
-
if (stype == BPF_CGROUP_STORAGE_SHARED) {
- storage->buf = kmalloc_node(size, flags, map->numa_node);
+ storage->buf = kmalloc_node(size, gfp, map->numa_node);
if (!storage->buf)
goto enomem;
check_and_init_map_lock(map, storage->buf->data);
} else {
- storage->percpu_buf = __alloc_percpu_gfp(size, 8, flags);
+ storage->percpu_buf = __alloc_percpu_gfp(size, 8, gfp);
if (!storage->percpu_buf)
goto enomem;
}
--
2.26.2
Powered by blists - more mailing lists