• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2021 Wenbo Zhang
3 #include <vmlinux.h>
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 __s64 total = 0;	/* total cache accesses without counting dirties */
8 __s64 misses = 0;	/* total of add to lru because of read misses */
9 __u64 mbd = 0;  	/* total of mark_buffer_dirty events */
10 
11 SEC("fentry/add_to_page_cache_lru")
BPF_PROG(add_to_page_cache_lru)12 int BPF_PROG(add_to_page_cache_lru)
13 {
14 	__sync_fetch_and_add(&misses, 1);
15 	return 0;
16 }
17 
18 SEC("fentry/mark_page_accessed")
BPF_PROG(mark_page_accessed)19 int BPF_PROG(mark_page_accessed)
20 {
21 	__sync_fetch_and_add(&total, 1);
22 	return 0;
23 }
24 
25 SEC("fentry/account_page_dirtied")
BPF_PROG(account_page_dirtied)26 int BPF_PROG(account_page_dirtied)
27 {
28 	__sync_fetch_and_add(&misses, -1);
29 	return 0;
30 }
31 
32 SEC("fentry/mark_buffer_dirty")
BPF_PROG(mark_buffer_dirty)33 int BPF_PROG(mark_buffer_dirty)
34 {
35 	__sync_fetch_and_add(&total, -1);
36 	__sync_fetch_and_add(&mbd, 1);
37 	return 0;
38 }
39 
40 char LICENSE[] SEC("license") = "GPL";
41