aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/kernel/bpf/bpf_local_storage.c
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2023-03-05 12:46:11 +0000
committerAlexei Starovoitov <ast@kernel.org>2023-03-07 09:33:43 -0800
commit7490b7f1c02ef825ef98f7230662049d4a464a21 (patch)
treeb94f3d6e0f8a61e29a91a517dfd050f3df9ae6d9 /kernel/bpf/bpf_local_storage.c
parentbpf: local_storage memory usage (diff)
downloadwireguard-linux-7490b7f1c02ef825ef98f7230662049d4a464a21.tar.xz
wireguard-linux-7490b7f1c02ef825ef98f7230662049d4a464a21.zip
bpf, net: bpf_local_storage memory usage
A new helper is introduced into bpf_local_storage map to calculate the memory usage. This helper is also used by other maps like bpf_cgrp_storage, bpf_inode_storage, bpf_task_storage and etc. Note that currently the dynamically allocated storage elements are not counted in the usage, since it will take extra runtime overhead in the elements update or delete path. So let's put it aside now, and implement it in the future when someone really need it. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Link: https://lore.kernel.org/r/20230305124615.12358-15-laoar.shao@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/bpf_local_storage.c')
-rw-r--r--kernel/bpf/bpf_local_storage.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 3d320393a12c..d3ba3f2db640 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -685,6 +685,16 @@ bool bpf_local_storage_unlink_nolock(struct bpf_local_storage *local_storage)
return free_storage;
}
+u64 bpf_local_storage_map_mem_usage(const struct bpf_map *map)
+{
+ struct bpf_local_storage_map *smap = (struct bpf_local_storage_map *)map;
+ u64 usage = sizeof(*smap);
+
+ /* The dynamically callocated selems are not counted currently. */
+ usage += sizeof(*smap->buckets) * (1ULL << smap->bucket_log);
+ return usage;
+}
+
struct bpf_map *
bpf_local_storage_map_alloc(union bpf_attr *attr,
struct bpf_local_storage_cache *cache)