fix(lsof): start ringbuf consumer before iterator scan - #125
Open
yuKing123-king wants to merge 1 commit into
Open
fix(lsof): start ringbuf consumer before iterator scan#125yuKing123-king wants to merge 1 commit into
yuKing123-king wants to merge 1 commit into
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Signed-off-by: Wang Yu <wangyu6@uniontech.com>
yuKing123-king
force-pushed
the
fix/lsof-ringbuf-consume-timing
branch
from
August 17, 2026 06:27
ba47f8c to
0c8163f
Compare
Contributor
Author
|
/review 检视一下当前提交的PR,代码有无安全风险,和其他错误的地方 |
|
Preparing review... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本次修改主要是修复了ringbuffer消耗不及时这个问题
由于起tail和vma占用文件只能最多起大概3000左右个进程,但是在bpf程序中,logs map的最大条目数却是256 * 1024 远远大于进程数,所以体现不出来ringbuffer消耗不及时这个问题。我将logs map的最大条目数从256 * 1024改成2 * 1024后,当启动1500个占用文件的进程后,lsof这个工具就会出现丢统计的情况。如下所示:
一、现象
3.原lsof只统计到了0个vma进程占用文件,修复后的lsof统计到了1500个vma进程

二、作出的修改
出现统计不及时的原因是先
bpf_iter_create(bpf_link__fd(obj->links.vma_iterator))和bpf_iter_create(bpf_link__fd(obj->links.file_iterator)),后pthread_create(&t1, NULL, ringbuf_worker, NULL),这就导致了先进行统计生产后,再统一进行消费,如果同时有很多进程占用文件,超过logs map的最大条目数就会出现统计错误和报错。将
pthread_create(&t1, NULL, ringbuf_worker, NULL)放在bpf_iter_create(bpf_link__fd(obj->links.vma_iterator))和bpf_iter_create(bpf_link__fd(obj->links.file_iterator))之前启动这个线程,就可以边生产边消费。同时我将void *ringbuf_worker(void *)这个的退出条件,从if (err == 0 && iter_fd == -1)换成使用scan_done这个更明确的状态变更。