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