-
Notifications
You must be signed in to change notification settings - Fork 245
/
Copy pathcachestat.bpf.c
53 lines (44 loc) · 1.06 KB
/
cachestat.bpf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Use this version of cachestat when kernel version >= 5.16
// https://github.com/cloudflare/ebpf_exporter/issues/132
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
#include "maps.bpf.h"
enum pache_cache_op {
OP_CACHE_ACCESS,
OP_CACHE_WRITES,
OP_PAGE_ADD_LRU,
OP_PAGE_MARK_DIRTIES,
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 4);
__type(key, u8);
__type(value, u64);
} page_cache_ops_total SEC(".maps");
static int trace_event(enum pache_cache_op op)
{
increment_map(&page_cache_ops_total, &op, 1);
return 0;
}
SEC("fentry/mark_page_accessed")
int mark_page_accessed()
{
return trace_event(OP_CACHE_ACCESS);
}
SEC("fentry/mark_buffer_dirty")
int mark_buffer_dirty()
{
return trace_event(OP_CACHE_WRITES);
}
SEC("fentry/add_to_page_cache_lru")
int add_to_page_cache_lru()
{
return trace_event(OP_PAGE_ADD_LRU);
}
SEC("raw_tp/writeback_dirty_folio")
int writeback_dirty_folio()
{
return trace_event(OP_PAGE_MARK_DIRTIES);
}
char LICENSE[] SEC("license") = "GPL";