1*387f9dfdSAndroid Build Coastguard WorkerDemonstration of readahead, the Linux eBPF/bcc version 2*387f9dfdSAndroid Build Coastguard Worker 3*387f9dfdSAndroid Build Coastguard WorkerRead-ahead mechanism is used by operation sytems to optimize sequential operations 4*387f9dfdSAndroid Build Coastguard Workerby reading ahead some pages to avoid more expensive filesystem operations. This tool 5*387f9dfdSAndroid Build Coastguard Workershows the performance of the read-ahead caching on the system under a given load to 6*387f9dfdSAndroid Build Coastguard Workerinvestigate any caching issues. It shows a count for unused pages in the cache and 7*387f9dfdSAndroid Build Coastguard Workeralso prints a histogram showing how long they have remianed there. 8*387f9dfdSAndroid Build Coastguard Worker 9*387f9dfdSAndroid Build Coastguard WorkerUsage Scenario 10*387f9dfdSAndroid Build Coastguard Worker============== 11*387f9dfdSAndroid Build Coastguard Worker 12*387f9dfdSAndroid Build Coastguard WorkerConsider that you are developing a React Native application which performs aggressive 13*387f9dfdSAndroid Build Coastguard Workerreads while re-encoding a video in local-storage. Usually such an app would be multi- 14*387f9dfdSAndroid Build Coastguard Workerlayered and have transitional library dependencies. The actual read may be performed 15*387f9dfdSAndroid Build Coastguard Workerby some unknown native library which may or may not be using hints to the OS, such as 16*387f9dfdSAndroid Build Coastguard Workermadvise(p, LEN, MADV_SEQUENTIAL). If high IOPS is observed in such an app, running 17*387f9dfdSAndroid Build Coastguard Workerreadahead may pin the issue much faster in this case as the developer digs deeper 18*387f9dfdSAndroid Build Coastguard Workerinto what may be causing this. 19*387f9dfdSAndroid Build Coastguard Worker 20*387f9dfdSAndroid Build Coastguard WorkerAn example where such an issue can surface is: https://github.com/boltdb/bolt/issues/691 21*387f9dfdSAndroid Build Coastguard Worker 22*387f9dfdSAndroid Build Coastguard Worker# readahead -d 30 23*387f9dfdSAndroid Build Coastguard WorkerTracing... Hit Ctrl-C to end. 24*387f9dfdSAndroid Build Coastguard Worker^C 25*387f9dfdSAndroid Build Coastguard WorkerRead-ahead unused pages: 6765 26*387f9dfdSAndroid Build Coastguard WorkerHistogram of read-ahead used page age (ms): 27*387f9dfdSAndroid Build Coastguard Worker 28*387f9dfdSAndroid Build Coastguard Worker age (ms) : count distribution 29*387f9dfdSAndroid Build Coastguard Worker 0 -> 1 : 4236 |****************************************| 30*387f9dfdSAndroid Build Coastguard Worker 2 -> 3 : 394 |*** | 31*387f9dfdSAndroid Build Coastguard Worker 4 -> 7 : 1670 |*************** | 32*387f9dfdSAndroid Build Coastguard Worker 8 -> 15 : 2132 |******************** | 33*387f9dfdSAndroid Build Coastguard Worker 16 -> 31 : 401 |*** | 34*387f9dfdSAndroid Build Coastguard Worker 32 -> 63 : 1256 |*********** | 35*387f9dfdSAndroid Build Coastguard Worker 64 -> 127 : 2352 |********************** | 36*387f9dfdSAndroid Build Coastguard Worker 128 -> 255 : 357 |*** | 37*387f9dfdSAndroid Build Coastguard Worker 256 -> 511 : 369 |*** | 38*387f9dfdSAndroid Build Coastguard Worker 512 -> 1023 : 366 |*** | 39*387f9dfdSAndroid Build Coastguard Worker 1024 -> 2047 : 181 |* | 40*387f9dfdSAndroid Build Coastguard Worker 2048 -> 4095 : 439 |**** | 41*387f9dfdSAndroid Build Coastguard Worker 4096 -> 8191 : 188 |* | 42*387f9dfdSAndroid Build Coastguard Worker 43*387f9dfdSAndroid Build Coastguard WorkerIn the example above, we recorded system-wide stats for 30 seconds. We can observe that 44*387f9dfdSAndroid Build Coastguard Workerwhile most of the pages stayed in the readahead cache for quite less time, after 30 45*387f9dfdSAndroid Build Coastguard Workerseconds 6765 pages still remained in the cache, yet unaccessed. 46*387f9dfdSAndroid Build Coastguard Worker 47*387f9dfdSAndroid Build Coastguard WorkerNote on Kprobes Usage 48*387f9dfdSAndroid Build Coastguard Worker===================== 49*387f9dfdSAndroid Build Coastguard Worker 50*387f9dfdSAndroid Build Coastguard WorkerThis tool uses Kprobes on the following kernel functions: 51*387f9dfdSAndroid Build Coastguard Worker 52*387f9dfdSAndroid Build Coastguard Worker__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*387f9dfdSAndroid Build Coastguard Worker__page_cache_alloc() 54*387f9dfdSAndroid Build Coastguard Workermark_page_accessed() 55*387f9dfdSAndroid Build Coastguard Worker 56*387f9dfdSAndroid Build Coastguard WorkerSince the tool uses Kprobes, depending on your linux kernel's compilation, these 57*387f9dfdSAndroid Build Coastguard Workerfunctions may be inlined and hence not available for Kprobes. To see whether you have 58*387f9dfdSAndroid Build Coastguard Workerthe functions available, check vmlinux source and binary to confirm whether inlining is 59*387f9dfdSAndroid Build Coastguard Workerhappening or not. You can also check /proc/kallsyms on the host and verify if the target 60*387f9dfdSAndroid Build Coastguard Workerfunctions are present there before using this tool. 61