bpf: local_storage memory usage

Bugzilla: https://bugzilla.redhat.com/2221599

commit 2f536977d6f1481f0a149140c8311103ddebe36a
Author: Yafang Shao <laoar.shao@gmail.com>
Date:   Sun Mar 5 12:46:10 2023 +0000

    bpf: local_storage memory usage
    
    A new helper is introduced to calculate local_storage map memory usage.
    Currently the dynamically allocated elements are not counted, since it
    will take runtime overhead in the element update or delete path. So
    let's put it aside currently, and implement it in the future if the user
    really needs it.
    
    Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
    Link: https://lore.kernel.org/r/20230305124615.12358-14-laoar.shao@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
This commit is contained in:
Artem Savkov 2023-07-10 15:13:51 +02:00
parent ab26182cb8
commit eeb4084466
1 changed files with 7 additions and 0 deletions

View File

@ -446,6 +446,12 @@ static void cgroup_storage_seq_show_elem(struct bpf_map *map, void *key,
rcu_read_unlock();
}
static u64 cgroup_storage_map_usage(const struct bpf_map *map)
{
/* Currently the dynamically allocated elements are not counted. */
return sizeof(struct bpf_cgroup_storage_map);
}
BTF_ID_LIST_SINGLE(cgroup_storage_map_btf_ids, struct,
bpf_cgroup_storage_map)
const struct bpf_map_ops cgroup_storage_map_ops = {
@ -457,6 +463,7 @@ const struct bpf_map_ops cgroup_storage_map_ops = {
.map_delete_elem = cgroup_storage_delete_elem,
.map_check_btf = cgroup_storage_check_btf,
.map_seq_show_elem = cgroup_storage_seq_show_elem,
.map_mem_usage = cgroup_storage_map_usage,
.map_btf_id = &cgroup_storage_map_btf_ids[0],
};