fix(procfs): drop stale /proc/<pid> entries after reap#1819
fix(procfs): drop stale /proc/<pid> entries after reap#1819jiuyue486 wants to merge 1 commit intoDragonOS-Community:masterfrom
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8924767e1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ProcessManager::find(pid).is_none() { | ||
| cached_children.remove(name); | ||
| return Err(SystemError::ENOENT); |
There was a problem hiding this comment.
Validate cached /proc/ entries before returning them
ProcDir::find returns a cached child immediately unless validate_child rejects it (see template/dir.rs), but RootDirOps still uses the default validator, so cached /proc/<pid> entries bypass this new existence check entirely. In practice, if a PID directory was cached before reap, later lookups can still resolve that stale inode without entering this lookup_child path, so /proc/<pid> may remain visible until a separate readdir triggers cache pruning.
Useful? React with 👍 / 👎.
| cached_children.retain(|name, _| { | ||
| if let Ok(pid) = name.parse::<RawPid>() { | ||
| pid_list.contains(&pid) |
There was a problem hiding this comment.
Avoid quadratic PID cache pruning in /proc readdir
This cache cleanup performs pid_list.contains(&pid) inside retain, making populate_children() O(number_of_cached_entries × number_of_pids). On systems with many tasks, each /proc directory listing can become disproportionately expensive while holding the cache write lock, causing avoidable latency spikes; converting pid_list to a set before retain would keep pruning linear.
Useful? React with 👍 / 👎.
概述
修复进程退出并被回收后,
/proc/<pid>目录项仍可能残留的问题。问题描述
当前 procfs 会缓存
/proc下的 pid 目录项。当进程已经退出并且被
waitpid()回收后,缓存中的/proc/<pid>目录项可能没有及时失效,导致/proc视图与实际进程状态不同步。修复内容
本次修改主要包括:
/proc根目录的populate_children()中先清理已经失效的 pid 目录缓存,再填充当前仍存在的进程目录lookup_child()中重新检查目标 pid 是否仍然存在;若进程已不存在,则删除缓存项并返回ENOENT/proc/[pid]目录实现中增加validate_child(),使进程消失后对应的 pid 子树条目能够正确失效修复效果
修复后,当进程被回收后,对应的
/proc/<pid>目录会正确消失,避免 procfs 中出现陈旧的 pid 目录项,使 procfs 行为与实际进程生命周期保持一致。说明
本次提交仅聚焦于修复 procfs 的 pid 目录同步问题,不包含额外测试或其他功能改动。