| 1 |
|
| 2 |
|
| 3 |
#include "common.h" |
| 4 |
|
| 5 |
char __license[] SEC("license") = "Dual MIT/GPL"; |
| 6 |
|
| 7 |
struct { |
| 8 |
__uint(type, BPF_MAP_TYPE_ARRAY); |
| 9 |
__type(key, u32); |
| 10 |
__type(value, u64); |
| 11 |
__uint(max_entries, 1); |
| 12 |
} counting_map SEC(".maps"); |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
struct alloc_info { |
| 17 |
|
| 18 |
unsigned long pad; |
| 19 |
|
| 20 |
unsigned long pfn; |
| 21 |
unsigned int order; |
| 22 |
unsigned int gfp_flags; |
| 23 |
int migratetype; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
SEC("tracepoint/kmem/mm_page_alloc") |
| 29 |
int mm_page_alloc(struct alloc_info *info) { |
| 30 |
u32 key = 0; |
| 31 |
u64 initval = 1, *valp; |
| 32 |
|
| 33 |
valp = bpf_map_lookup_elem(&counting_map, &key); |
| 34 |
if (!valp) { |
| 35 |
bpf_map_update_elem(&counting_map, &key, &initval, BPF_ANY); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
__sync_fetch_and_add(valp, 1); |
| 39 |
return 0; |
| 40 |
} |