diff --git a/src/51-tcp-quarantine/README.md b/src/51-tcp-quarantine/README.md index bd10035..dfa99da 100644 --- a/src/51-tcp-quarantine/README.md +++ b/src/51-tcp-quarantine/README.md @@ -14,7 +14,7 @@ This seemingly simple requirement is surprisingly difficult to achieve with trad What we need is a kernel-level mechanism that can identify and destroy specific sockets atomically, with no race window. This is exactly what Linux 6.5 introduced with the `bpf_sock_destroy` kernel function (kfunc). -This tutorial builds a command-line tool that uses a BPF iterator to walk the kernel's TCP socket table. A dry run lists every established connection matching a remote IPv4 address and port; apply mode additionally requires the selected local IPv4 address and port, then destroys only that complete 4-tuple. You will learn how BPF iterators provide safe, locked traversal of kernel data structures, and how kfuncs like `bpf_sock_destroy` expose kernel operations to BPF programs. +This tutorial builds a command-line tool that uses a BPF iterator to walk the kernel's TCP socket table, find established connections matching a specific IPv4 address and port, and destroy them on demand. You will learn how BPF iterators provide safe, locked traversal of kernel data structures, and how kfuncs like `bpf_sock_destroy` expose kernel operations to BPF programs. > Complete source code: diff --git a/src/51-tcp-quarantine/README.zh.md b/src/51-tcp-quarantine/README.zh.md index 7d82377..2a811f0 100644 --- a/src/51-tcp-quarantine/README.zh.md +++ b/src/51-tcp-quarantine/README.zh.md @@ -12,7 +12,7 @@ 我们需要的是一种内核级机制,能够原子地识别并销毁特定套接字,不存在竞态窗口。这正是 Linux 6.5 引入 `bpf_sock_destroy` 内核函数(kfunc)所提供的能力。 -本教程将构建一个命令行工具,使用 BPF 迭代器遍历内核的 TCP 套接字表。dry-run 列出所有匹配远端 IPv4 地址和端口的已建立连接;apply 模式还必须给出选中的本地 IPv4 地址和端口,因此只会销毁完整 4-tuple 对应的连接。你将学习 BPF 迭代器如何在持有锁的情况下安全遍历内核数据结构,以及 `bpf_sock_destroy` 这样的 kfunc 如何将内核操作暴露给 BPF 程序。 +本教程将构建一个命令行工具,使用 BPF 迭代器遍历内核的 TCP 套接字表,找出与指定 IPv4 地址和端口匹配的已建立连接,并按需销毁。你将学习 BPF 迭代器如何在持有锁的情况下安全遍历内核数据结构,以及 `bpf_sock_destroy` 这样的 kfunc 如何将内核操作暴露给 BPF 程序。 > 完整源码: diff --git a/src/52-fsession-latency/README.md b/src/52-fsession-latency/README.md index ad966cd..bcbf7e7 100644 --- a/src/52-fsession-latency/README.md +++ b/src/52-fsession-latency/README.md @@ -1,10 +1,8 @@ # eBPF Tutorial: Tracing Slow vfs_read Calls with fsession -When a file-backed service shows read-latency spikes, application-level timing tells you that requests slowed down, but it cannot distinguish whether the kernel spent time inside `vfs_read` or user-space logic took too long. The useful questions are: which thread issued the read, which VFS object was involved, how many bytes did it request, what did the call return, and how long did that single `vfs_read` invocation take? +When a file-backed service shows read-latency spikes, application-level timing tells you that requests slowed down, but it cannot distinguish whether the kernel blocked on I/O or user-space logic took too long. The useful questions are: which thread issued the read, how many bytes did it request, what did the call return, and how long did that single `vfs_read` invocation take? -This tutorial demonstrates how to measure `vfs_read` call latency using the **fsession** mechanism introduced in Linux 7.0. fsession is a new eBPF program type that runs once at function entry and once at return, with built-in per-invocation storage for correlating the two phases. The tool timestamps function entry, computes latency at return, filters by process and threshold, and reports the object type plus a `major:minor:inode` identity through a ring buffer. - -`vfs_read` is not limited to regular files: pipes, character devices, and other file-backed objects also pass through it. A slow event therefore identifies a slow `vfs_read` call, not necessarily slow storage. Use the reported `type` together with the `major:minor:inode` identity to distinguish regular-file reads from FIFOs and other VFS objects. +This tutorial demonstrates how to measure `vfs_read` call latency using the **fsession** mechanism introduced in Linux 7.0. fsession is a new eBPF program type that runs once at function entry and once at return, with built-in per-invocation storage for correlating the two phases. The tool we build timestamps function entry, computes latency at return, filters by process and threshold, and reports slow-read events through a ring buffer. > Complete source: diff --git a/src/52-fsession-latency/README.zh.md b/src/52-fsession-latency/README.zh.md index fad6fda..9646443 100644 --- a/src/52-fsession-latency/README.zh.md +++ b/src/52-fsession-latency/README.zh.md @@ -1,10 +1,8 @@ # eBPF 教程:使用 fsession 追踪慢速 vfs_read 调用 -当一个文件服务出现读延迟尖峰时,应用层计时只能告诉你请求变慢了,却无法区分是内核在 `vfs_read` 中耗时还是用户态逻辑耗时。真正有用的问题是:哪个线程发起了读操作、涉及哪个 VFS 对象、请求了多少字节、调用返回了什么、这一次 `vfs_read` 花了多长时间? +当一个文件服务出现读延迟尖峰时,应用层计时只能告诉你请求变慢了,却无法区分是内核在 I/O 上阻塞还是用户态逻辑耗时。真正有用的问题是:哪个线程发起了读操作、请求了多少字节、调用返回了什么、这一次 `vfs_read` 花了多长时间? -本教程展示如何使用 Linux 7.0 引入的 **fsession** 机制测量 `vfs_read` 调用延迟。fsession 是一种新的 eBPF 程序类型,它在函数进入时执行一次、返回时再执行一次,并提供内置的调用级存储来关联这两个阶段。工具会在函数进入时记录时间戳、返回时计算延迟,按进程和阈值过滤后,通过 ring buffer 上报对象类型和 `major:minor:inode` 身份。 - -`vfs_read` 不只处理普通文件,pipe、字符设备等文件对象也会经过它。因此慢事件表示某次 `vfs_read` 较慢,并不必然说明存储较慢。应结合输出中的 `type` 和 `major:minor:inode` 身份,区分普通文件读、FIFO 以及其他 VFS 对象。 +本教程展示如何使用 Linux 7.0 引入的 **fsession** 机制测量 `vfs_read` 调用延迟。fsession 是一种新的 eBPF 程序类型,它在函数进入时执行一次、返回时再执行一次,并提供内置的调用级存储来关联这两个阶段。我们构建的工具会在函数进入时记录时间戳、返回时计算延迟,按进程和阈值过滤后,通过 ring buffer 上报慢读事件。 > 完整源码: