Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions tools/readahead.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
bpf_text_kfunc_cache_alloc_ret_folio = """
KRETFUNC_PROBE(filemap_alloc_folio, gfp_t gfp, unsigned int order,
struct folio *retval)
"""
# In kernel commit b951aaff5035 ("mm: enable page allocation tagging"), add
# _noprof suffix to filemap_alloc_folio.
bpf_text_kfunc_cache_alloc_ret_folio_noprof = """
KRETFUNC_PROBE(filemap_alloc_folio_noprof, gfp_t gfp, unsigned int order,
struct folio *retval)
"""
bpf_text_kfunc_cache_alloc_ret_folio_func_body = """
{
u64 ts;
u32 zero = 0; // static key for accessing pages[0]
Expand Down Expand Up @@ -179,7 +187,14 @@
if BPF.get_kprobe_functions(b"__page_cache_alloc"):
bpf_text += bpf_text_kfunc_cache_alloc_ret_page
else:
bpf_text += bpf_text_kfunc_cache_alloc_ret_folio
if BPF.get_kprobe_functions(b"filemap_alloc_folio"):
bpf_text += bpf_text_kfunc_cache_alloc_ret_folio
elif BPF.get_kprobe_functions(b"filemap_alloc_folio_noprof"):
bpf_text += bpf_text_kfunc_cache_alloc_ret_folio_noprof
else:
print("ERROR: No cache alloc function found. Exiting.")
exit()
bpf_text += bpf_text_kfunc_cache_alloc_ret_folio_func_body
b = BPF(text=bpf_text)
else:
bpf_text += bpf_text_kprobe
Expand All @@ -196,8 +211,15 @@
cache_func = "__page_cache_alloc"
bpf_text = bpf_text.replace('GET_RETVAL_PAGE', 'PT_REGS_RC(ctx)')
else:
cache_func = "filemap_alloc_folio"
if BPF.get_kprobe_functions(b"filemap_alloc_folio"):
cache_func = "filemap_alloc_folio"
elif BPF.get_kprobe_functions(b"filemap_alloc_folio_noprof"):
cache_func = "filemap_alloc_folio_noprof"
else:
print("ERROR: No cache alloc function found. Exiting.")
exit()
bpf_text = bpf_text.replace('GET_RETVAL_PAGE', 'folio_page((struct folio *)PT_REGS_RC(ctx), 0)')

b = BPF(text=bpf_text)
b.attach_kprobe(event=ra_event, fn_name="entry__do_page_cache_readahead")
b.attach_kretprobe(event=ra_event, fn_name="exit__do_page_cache_readahead")
Expand Down