mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-11-07 23:18:24 +00:00
bpf: lpm_trie memory usage
trie_mem_usage() is introduced to calculate the lpm_trie memory usage.
Some small memory allocations are ignored. The inner node is also
ignored.
The result as follows,
- before
10: lpm_trie flags 0x1
key 8B value 8B max_entries 65536 memlock 1048576B
- after
10: lpm_trie flags 0x1
key 8B value 8B max_entries 65536 memlock 2291536B
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/r/20230305124615.12358-3-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
90a5527d76
commit
41d5941e7f
@ -720,6 +720,16 @@ static int trie_check_btf(const struct bpf_map *map,
|
|||||||
-EINVAL : 0;
|
-EINVAL : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u64 trie_mem_usage(const struct bpf_map *map)
|
||||||
|
{
|
||||||
|
struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
|
||||||
|
u64 elem_size;
|
||||||
|
|
||||||
|
elem_size = sizeof(struct lpm_trie_node) + trie->data_size +
|
||||||
|
trie->map.value_size;
|
||||||
|
return elem_size * READ_ONCE(trie->n_entries);
|
||||||
|
}
|
||||||
|
|
||||||
BTF_ID_LIST_SINGLE(trie_map_btf_ids, struct, lpm_trie)
|
BTF_ID_LIST_SINGLE(trie_map_btf_ids, struct, lpm_trie)
|
||||||
const struct bpf_map_ops trie_map_ops = {
|
const struct bpf_map_ops trie_map_ops = {
|
||||||
.map_meta_equal = bpf_map_meta_equal,
|
.map_meta_equal = bpf_map_meta_equal,
|
||||||
@ -733,5 +743,6 @@ const struct bpf_map_ops trie_map_ops = {
|
|||||||
.map_update_batch = generic_map_update_batch,
|
.map_update_batch = generic_map_update_batch,
|
||||||
.map_delete_batch = generic_map_delete_batch,
|
.map_delete_batch = generic_map_delete_batch,
|
||||||
.map_check_btf = trie_check_btf,
|
.map_check_btf = trie_check_btf,
|
||||||
|
.map_mem_usage = trie_mem_usage,
|
||||||
.map_btf_id = &trie_map_btf_ids[0],
|
.map_btf_id = &trie_map_btf_ids[0],
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user