tools/readahead compatible with kernel version >= 5.10 (#3507)
authorzcy <zcy.chenyue.zhou@gmail.com>
Fri, 25 Jun 2021 02:16:53 +0000 (10:16 +0800)
committerGitHub <noreply@github.com>
Fri, 25 Jun 2021 02:16:53 +0000 (19:16 -0700)
After kernel version 5.10, __do_page_cache_readahead() was renamed to do_page_cache_ra(),
let us try both in readahead.py.

tools/readahead.py
tools/readahead_example.txt

index 14182d5aca04579368e1ddd3aca41b0350409894..b338261fc78f54c9669a1c5d73050ad04a791456 100755 (executable)
@@ -20,7 +20,7 @@ import argparse
 
 # arguments
 examples = """examples:
-    ./readahead -d 20       # monitor for 10 seconds and generate stats 
+    ./readahead -d 20       # monitor for 20 seconds and generate stats
 """
 
 parser = argparse.ArgumentParser(
@@ -95,15 +95,19 @@ int entry_mark_page_accessed(struct pt_regs *ctx) {
 """
 
 b = BPF(text=program)
-b.attach_kprobe(event="__do_page_cache_readahead", fn_name="entry__do_page_cache_readahead")
-b.attach_kretprobe(event="__do_page_cache_readahead", fn_name="exit__do_page_cache_readahead")
+if BPF.get_kprobe_functions(b"__do_page_cache_readahead"):
+    ra_event = "__do_page_cache_readahead"
+else:
+    ra_event = "do_page_cache_ra"
+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")
 b.attach_kretprobe(event="__page_cache_alloc", fn_name="exit__page_cache_alloc")
 b.attach_kprobe(event="mark_page_accessed", fn_name="entry_mark_page_accessed")
 
 # header
 print("Tracing... Hit Ctrl-C to end.")
 
-# print 
+# print
 def print_stats():
     print()
     print("Read-ahead unused pages: %d" % (b["pages"][ct.c_ulong(0)].value))
index 079dbaae78900bb6391f3c52f14220fc7d5ec2c8..6d675c13baca19ad9e9051b6290ef26a68313e2e 100644 (file)
@@ -2,20 +2,20 @@ Demonstration of readahead, the Linux eBPF/bcc version
 
 Read-ahead mechanism is used by operation sytems to optimize sequential operations
 by reading ahead some pages to avoid more expensive filesystem operations. This tool
-shows the performance of the read-ahead caching on the system under a given load to 
+shows the performance of the read-ahead caching on the system under a given load to
 investigate any caching issues. It shows a count for unused pages in the cache and
 also prints a histogram showing how long they have remianed there.
 
 Usage Scenario
 ==============
 
-Consider that you are developing a React Native application which performs aggressive 
+Consider that you are developing a React Native application which performs aggressive
 reads while re-encoding a video in local-storage. Usually such an app would be multi-
-layered and have transitional library dependencies. The actual read may be performed 
-by some unknown native library which may or may not be using hints to the OS, such as  
-madvise(p, LEN, MADV_SEQUENTIAL). If high IOPS is observed in such an app, running 
-readahead may pin the issue much faster in this case as the developer digs deeper 
-into what may be causing this. 
+layered and have transitional library dependencies. The actual read may be performed
+by some unknown native library which may or may not be using hints to the OS, such as
+madvise(p, LEN, MADV_SEQUENTIAL). If high IOPS is observed in such an app, running
+readahead may pin the issue much faster in this case as the developer digs deeper
+into what may be causing this.
 
 An example where such an issue can surface is: https://github.com/boltdb/bolt/issues/691
 
@@ -40,7 +40,7 @@ Histogram of read-ahead used page age (ms):
       2048 -> 4095       : 439      |****                                    |
       4096 -> 8191       : 188      |*                                       |
 
-In the example above, we recorded system-wide stats for 30 seconds. We can observe that 
+In the example above, we recorded system-wide stats for 30 seconds. We can observe that
 while most of the pages stayed in the readahead cache for quite less time, after 30
 seconds 6765 pages still remained in the cache, yet unaccessed.
 
@@ -49,12 +49,12 @@ Note on Kprobes Usage
 
 This tool uses Kprobes on the following kernel functions:
 
-__do_page_cache_readahead()
+__do_page_cache_readahead()/do_page_cache_ra() (After kernel version 5.10 (include), __do_page_cache_readahead was renamed to do_page_cache_ra)
 __page_cache_alloc()
 mark_page_accessed()
 
-Since the tool uses Kprobes, depending on your linux kernel's compilation, these 
-functions may be inlined and hence not available for Kprobes. To see whether you have 
+Since the tool uses Kprobes, depending on your linux kernel's compilation, these
+functions may be inlined and hence not available for Kprobes. To see whether you have
 the functions available, check vmlinux source and binary to confirm whether inlining is
 happening or not. You can also check /proc/kallsyms on the host and verify if the target
 functions are present there before using this tool.