Skip to content

Commit b048533

Browse files
xingfeng2510dkruces
authored andcommitted
tools/cachestat,cachetop: Fix add_to_page_cache_lru/mark_page_accessed since kernel 5.16 (iovisor#5144)
For cachestat/cachetop tools, trace functions filemap_add_folio/folio_mark_accessed if available (>= 5.16 kernel).
1 parent 2962f6a commit b048533

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

tools/cachestat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# 13-Jan-2016 Allan McAleavy run pep8 against program
1818
# 02-Feb-2019 Brendan Gregg Column shuffle, bring back %ratio
1919
# 15-Feb-2023 Rong Tao Add writeback_dirty_{folio,page} tracepoints
20+
# 17-Nov-2024 Rocky Xing Added filemap_add_folio/folio_mark_accessed kprobes
2021

2122
from __future__ import print_function
2223
from bcc import BPF
@@ -118,8 +119,14 @@ def get_meminfo():
118119

119120
# load BPF program
120121
b = BPF(text=bpf_text)
121-
b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count_apcl")
122-
b.attach_kprobe(event="mark_page_accessed", fn_name="do_count_mpa")
122+
if BPF.get_kprobe_functions(b'filemap_add_folio'):
123+
b.attach_kprobe(event="filemap_add_folio", fn_name="do_count_apcl")
124+
else:
125+
b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count_apcl")
126+
if BPF.get_kprobe_functions(b'folio_mark_accessed'):
127+
b.attach_kprobe(event="folio_mark_accessed", fn_name="do_count_mpa")
128+
else:
129+
b.attach_kprobe(event="mark_page_accessed", fn_name="do_count_mpa")
123130

124131
# Function account_page_dirtied() is changed to folio_account_dirtied() in 5.15.
125132
# Both folio_account_dirtied() and account_page_dirtied() are

tools/cachetop.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# 13-Jul-2016 Emmanuel Bretelle first version
1414
# 17-Mar-2022 Rocky Xing Added PID filter support.
1515
# 15-Feb-2023 Rong Tao Add writeback_dirty_{folio,page} tracepoints
16+
# 17-Nov-2024 Rocky Xing Added filemap_add_folio/folio_mark_accessed kprobes
1617

1718
from __future__ import absolute_import
1819
from __future__ import division
@@ -206,8 +207,14 @@ def handle_loop(stdscr, args):
206207
bpf_text = bpf_text.replace('FILTER_PID', '0')
207208

208209
b = BPF(text=bpf_text)
209-
b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count_apcl")
210-
b.attach_kprobe(event="mark_page_accessed", fn_name="do_count_mpa")
210+
if BPF.get_kprobe_functions(b'filemap_add_folio'):
211+
b.attach_kprobe(event="filemap_add_folio", fn_name="do_count_apcl")
212+
else:
213+
b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count_apcl")
214+
if BPF.get_kprobe_functions(b'folio_mark_accessed'):
215+
b.attach_kprobe(event="folio_mark_accessed", fn_name="do_count_mpa")
216+
else:
217+
b.attach_kprobe(event="mark_page_accessed", fn_name="do_count_mpa")
211218
b.attach_kprobe(event="mark_buffer_dirty", fn_name="do_count_mbd")
212219

213220
# Function account_page_dirtied() is changed to folio_account_dirtied() in 5.15.

0 commit comments

Comments
 (0)