History

bpf: queue_stack_maps memory usage

A new helper is introduced to calculate queue_stack_maps memory usage. The result as follows, - before 20: queue name count_map flags 0x0 key 0B value 4B max_entries 65536 memlock 266240B 21: stack name count_map flags 0x0 key 0B value 4B max_entries 65536 memlock 266240B - after 20: queue name count_map flags 0x0 key 0B value 4B max_entries 65536 memlock 524288B 21: stack name count_map flags 0x0 key 0B value 4B max_entries 65536 memlock 524288B

Yafang Shao committed 3 years ago

Commit c6e66b41 parent fa5e83d1 file · +10 −0Browse files

Showing the changes to kernel/bpf/queue_stack_maps.c (1 of 1 file). Show all

Unified · Split

kernel/bpf/queue_stack_maps.c+10−0
@@ -246,6 +246,14 @@ static int queue_stack_map_get_next_key(struct bpf_map *map, void *key, · 245 unmodified lines
246 return -EINVAL;246 return -EINVAL;
247}247}
248 248
249static u64 queue_stack_map_mem_usage(const struct bpf_map *map)
250{
251 u64 usage = sizeof(struct bpf_queue_stack);
252
253 usage += ((u64)map->max_entries + 1) * map->value_size;
254 return usage;
255}
256
249BTF_ID_LIST_SINGLE(queue_map_btf_ids, struct, bpf_queue_stack)257BTF_ID_LIST_SINGLE(queue_map_btf_ids, struct, bpf_queue_stack)
250const struct bpf_map_ops queue_map_ops = {258const struct bpf_map_ops queue_map_ops = {
251 .map_meta_equal = bpf_map_meta_equal,259 .map_meta_equal = bpf_map_meta_equal,
@@ -259,6 +267,7 @@ const struct bpf_map_ops queue_map_ops = { · 7 unmodified lines
259 .map_pop_elem = queue_map_pop_elem,267 .map_pop_elem = queue_map_pop_elem,
260 .map_peek_elem = queue_map_peek_elem,268 .map_peek_elem = queue_map_peek_elem,
261 .map_get_next_key = queue_stack_map_get_next_key,269 .map_get_next_key = queue_stack_map_get_next_key,
270 .map_mem_usage = queue_stack_map_mem_usage,
262 .map_btf_id = &queue_map_btf_ids[0],271 .map_btf_id = &queue_map_btf_ids[0],
263};272};
264 273
@@ -274,5 +283,6 @@ const struct bpf_map_ops stack_map_ops = { · 9 unmodified lines
274 .map_pop_elem = stack_map_pop_elem,283 .map_pop_elem = stack_map_pop_elem,
275 .map_peek_elem = stack_map_peek_elem,284 .map_peek_elem = stack_map_peek_elem,
276 .map_get_next_key = queue_stack_map_get_next_key,285 .map_get_next_key = queue_stack_map_get_next_key,
286 .map_mem_usage = queue_stack_map_mem_usage,
277 .map_btf_id = &queue_map_btf_ids[0],287 .map_btf_id = &queue_map_btf_ids[0],
278};288};