summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2023-03-05 15:45:58 +0300
committerAlexei Starovoitov <ast@kernel.org>2023-03-07 20:33:41 +0300
commit90a5527d7686d3ebe0dd2a831356a6c7d7dc31bc (patch)
tree37f414130d1410aa9020d189bfbffdd24d0e52a2 /kernel
parent2d5bcdcda8799cf21f9ab84598c946dd320207a2 (diff)
downloadlinux-90a5527d7686d3ebe0dd2a831356a6c7d7dc31bc.tar.xz
bpf: add new map ops ->map_mem_usage
Add a new map ops ->map_mem_usage to print the memory usage of a bpf map. This is a preparation for the followup change. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Link: https://lore.kernel.org/r/20230305124615.12358-2-laoar.shao@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/syscall.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index ede5f987484f..7c96e68859ec 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -771,16 +771,15 @@ static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
}
#ifdef CONFIG_PROC_FS
-/* Provides an approximation of the map's memory footprint.
- * Used only to provide a backward compatibility and display
- * a reasonable "memlock" info.
- */
-static unsigned long bpf_map_memory_footprint(const struct bpf_map *map)
+/* Show the memory usage of a bpf map */
+static u64 bpf_map_memory_usage(const struct bpf_map *map)
{
unsigned long size;
- size = round_up(map->key_size + bpf_map_value_size(map), 8);
+ if (map->ops->map_mem_usage)
+ return map->ops->map_mem_usage(map);
+ size = round_up(map->key_size + bpf_map_value_size(map), 8);
return round_up(map->max_entries * size, PAGE_SIZE);
}
@@ -803,7 +802,7 @@ static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp)
"max_entries:\t%u\n"
"map_flags:\t%#x\n"
"map_extra:\t%#llx\n"
- "memlock:\t%lu\n"
+ "memlock:\t%llu\n"
"map_id:\t%u\n"
"frozen:\t%u\n",
map->map_type,
@@ -812,7 +811,7 @@ static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp)
map->max_entries,
map->map_flags,
(unsigned long long)map->map_extra,
- bpf_map_memory_footprint(map),
+ bpf_map_memory_usage(map),
map->id,
READ_ONCE(map->frozen));
if (type) {