blob: 6d675c13baca19ad9e9051b6290ef26a68313e2e [file] [log] [blame]
Suchakra Sharma561a71e2020-09-24 08:27:15 -07001Demonstration of readahead, the Linux eBPF/bcc version
2
3Read-ahead mechanism is used by operation sytems to optimize sequential operations
4by reading ahead some pages to avoid more expensive filesystem operations. This tool
zcy97c20762021-06-25 10:16:53 +08005shows the performance of the read-ahead caching on the system under a given load to
Suchakra Sharma561a71e2020-09-24 08:27:15 -07006investigate any caching issues. It shows a count for unused pages in the cache and
7also prints a histogram showing how long they have remianed there.
8
9Usage Scenario
10==============
11
zcy97c20762021-06-25 10:16:53 +080012Consider that you are developing a React Native application which performs aggressive
Suchakra Sharma561a71e2020-09-24 08:27:15 -070013reads while re-encoding a video in local-storage. Usually such an app would be multi-
zcy97c20762021-06-25 10:16:53 +080014layered and have transitional library dependencies. The actual read may be performed
15by some unknown native library which may or may not be using hints to the OS, such as
16madvise(p, LEN, MADV_SEQUENTIAL). If high IOPS is observed in such an app, running
17readahead may pin the issue much faster in this case as the developer digs deeper
18into what may be causing this.
Suchakra Sharma561a71e2020-09-24 08:27:15 -070019
20An example where such an issue can surface is: https://github.com/boltdb/bolt/issues/691
21
22# readahead -d 30
23Tracing... Hit Ctrl-C to end.
24^C
25Read-ahead unused pages: 6765
26Histogram of read-ahead used page age (ms):
27
28 age (ms) : count distribution
29 0 -> 1 : 4236 |****************************************|
30 2 -> 3 : 394 |*** |
31 4 -> 7 : 1670 |*************** |
32 8 -> 15 : 2132 |******************** |
33 16 -> 31 : 401 |*** |
34 32 -> 63 : 1256 |*********** |
35 64 -> 127 : 2352 |********************** |
36 128 -> 255 : 357 |*** |
37 256 -> 511 : 369 |*** |
38 512 -> 1023 : 366 |*** |
39 1024 -> 2047 : 181 |* |
40 2048 -> 4095 : 439 |**** |
41 4096 -> 8191 : 188 |* |
42
zcy97c20762021-06-25 10:16:53 +080043In the example above, we recorded system-wide stats for 30 seconds. We can observe that
Suchakra Sharma561a71e2020-09-24 08:27:15 -070044while most of the pages stayed in the readahead cache for quite less time, after 30
45seconds 6765 pages still remained in the cache, yet unaccessed.
46
47Note on Kprobes Usage
48=====================
49
50This tool uses Kprobes on the following kernel functions:
51
zcy97c20762021-06-25 10:16:53 +080052__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)
Suchakra Sharma561a71e2020-09-24 08:27:15 -070053__page_cache_alloc()
54mark_page_accessed()
55
zcy97c20762021-06-25 10:16:53 +080056Since the tool uses Kprobes, depending on your linux kernel's compilation, these
57functions may be inlined and hence not available for Kprobes. To see whether you have
Suchakra Sharma561a71e2020-09-24 08:27:15 -070058the functions available, check vmlinux source and binary to confirm whether inlining is
59happening or not. You can also check /proc/kallsyms on the host and verify if the target
60functions are present there before using this tool.