Skip to content

Commit 36b4010

Browse files
Rtoaxyonghong-song
authored andcommitted
tools/swapin: Support swap_read_folio()
kernel[0] commit c9bdf768dd93("mm: convert swap_readpage() to swap_read_folio()") convert swap_readpage() to swap_read_folio(). [0] https://github.com/torvalds/linux.git Signed-off-by: Xue Yuehua <2482887395@qq.com> Signed-off-by: Rong Tao <rongtao@cestc.cn>
1 parent 5596f67 commit 36b4010

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/swapin.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# When copying or porting, include this comment.
1414
#
1515
# 03-Jul-2019 Brendan Gregg Ported from bpftrace to BCC.
16+
# 31-May-2024 Rong Tao Support folio
1617

1718
from __future__ import print_function
1819
from bcc import BPF
@@ -46,7 +47,7 @@
4647
4748
BPF_HASH(counts, struct key_t, u64);
4849
49-
int kprobe__swap_readpage(struct pt_regs *ctx)
50+
int trace_swap_read(struct pt_regs *ctx)
5051
{
5152
u64 *val, zero = 0;
5253
u32 tgid = bpf_get_current_pid_tgid() >> 32;
@@ -66,6 +67,16 @@
6667
htab_batch_ops = True if BPF.kernel_struct_has_field(b'bpf_map_ops',
6768
b'map_lookup_and_delete_batch') == 1 else False
6869

70+
if b.get_kprobe_functions(b"swap_readpage"):
71+
b.attach_kprobe(event="swap_readpage", fn_name="trace_swap_read")
72+
elif b.get_kprobe_functions(b"swap_read_folio"):
73+
b.attach_kprobe(event="swap_read_folio", fn_name="trace_swap_read")
74+
else:
75+
print("ERROR: swap_readpage() and swap_read_folio() kernel function"
76+
" not found or traceable. "
77+
"The kernel might be too old or the the function has been inlined.")
78+
exit()
79+
6980
print("Counting swap ins. Ctrl-C to end.");
7081

7182
# output

0 commit comments

Comments
 (0)