mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/r/20230305124615.12358-12-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									fa5e83df17
								
							
						
					
					
						commit
						c6e66b42a3
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -246,6 +246,14 @@ static int queue_stack_map_get_next_key(struct bpf_map *map, void *key,
 | 
			
		|||
	return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static u64 queue_stack_map_mem_usage(const struct bpf_map *map)
 | 
			
		||||
{
 | 
			
		||||
	u64 usage = sizeof(struct bpf_queue_stack);
 | 
			
		||||
 | 
			
		||||
	usage += ((u64)map->max_entries + 1) * map->value_size;
 | 
			
		||||
	return usage;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BTF_ID_LIST_SINGLE(queue_map_btf_ids, struct, bpf_queue_stack)
 | 
			
		||||
const struct bpf_map_ops queue_map_ops = {
 | 
			
		||||
	.map_meta_equal = bpf_map_meta_equal,
 | 
			
		||||
| 
						 | 
				
			
			@ -259,6 +267,7 @@ const struct bpf_map_ops queue_map_ops = {
 | 
			
		|||
	.map_pop_elem = queue_map_pop_elem,
 | 
			
		||||
	.map_peek_elem = queue_map_peek_elem,
 | 
			
		||||
	.map_get_next_key = queue_stack_map_get_next_key,
 | 
			
		||||
	.map_mem_usage = queue_stack_map_mem_usage,
 | 
			
		||||
	.map_btf_id = &queue_map_btf_ids[0],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -274,5 +283,6 @@ const struct bpf_map_ops stack_map_ops = {
 | 
			
		|||
	.map_pop_elem = stack_map_pop_elem,
 | 
			
		||||
	.map_peek_elem = stack_map_peek_elem,
 | 
			
		||||
	.map_get_next_key = queue_stack_map_get_next_key,
 | 
			
		||||
	.map_mem_usage = queue_stack_map_mem_usage,
 | 
			
		||||
	.map_btf_id = &queue_map_btf_ids[0],
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue