1Demonstration 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 5shows the performance of the read-ahead caching on the system under a given load to 6investigate 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 12Consider that you are developing a React Native application which performs aggressive 13reads while re-encoding a video in local-storage. Usually such an app would be multi- 14layered 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. 19 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 43In the example above, we recorded system-wide stats for 30 seconds. We can observe that 44while 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 52__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) 53__page_cache_alloc() 54mark_page_accessed() 55 56Since 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 58the 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. 61