fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim, observability#1995
fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim, observability#1995sparkzky wants to merge 4 commits into
Conversation
…, observability Phase 1 (bug fixes + observability): - Fix wait_until_recoverable generation guard dead code (Some(_) => true) - Add OOM kill counter (OOM_KILL_COUNT atomic) wired to /proc/vmstat oom_kill - Add /proc/[pid]/oom_score read-only file (normalized [0,1000]) - Fix hardcoded order:1 → order:0 in pagefault OOM context Phase 2 (victim forward-progress guarantee, prevents OOM livelock): - Add ProcessFlags::OOM_VICTIM (equivalent to Linux TIF_MEMDIE) - Mark all tasks sharing victim mm with OOM_VICTIM before SIGKILL delivery - Clear OOM_VICTIM in exit path via exit_oom_victim() - Skip already-marked victims in should_skip_candidate() Phase 3 (direct reclaim before kill): - Insert PageReclaimer::shrink_list(64) before pagefault_out_of_memory() (matching Linux try_to_free_pages before out_of_memory) - Use tried_direct_reclaim flag to bound to one reclaim attempt per fault Test: - Add test_proc_oom_score and test_vmstat_oom_kill_counter to user/apps/c_unitest/test_oom_killer.c Verified: nix develop -c make kernel + make fmt (cargo fmt + clippy) pass. Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff53205ed7
ℹ️ 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".
| pub fn current_is_oom_victim() -> bool { | ||
| ProcessManager::current_pcb() | ||
| .flags() | ||
| .contains(ProcessFlags::OOM_VICTIM) |
There was a problem hiding this comment.
| if !tried_direct_reclaim { | ||
| tried_direct_reclaim = true; | ||
| drop(space_guard); | ||
| crate::mm::page::PageReclaimer::shrink_list( | ||
| <crate::mm::allocator::page_frame::PageFrameCount>::new(64), | ||
| ); | ||
| flags |= FaultFlags::FAULT_FLAG_TRIED; | ||
| continue; |
There was a problem hiding this comment.
当 /proc/sys/vm/oom_fault_inject 配置为 fail_times=1(test_current_is_victim 和新增的 test_vmstat_oom_kill_counter 都这样用)时,第一次缺页会由 should_inject_fault_oom() 直接返回 VM_FAULT_OOM 并消耗唯一一次失败;这里先执行 direct reclaim 后 continue,第二次缺页不再 OOM,于是子进程会走到 _exit(3) 而不是 SIGKILL,oom_kill 也不会增加。需要让注入的 OOM 跳过这次 reclaim,或把测试注入次数调到经过 reclaim 后仍会触发 killer。
Useful? React with 👍 / 👎.
P1: Wire OOM_VICTIM into page-frame allocator (oom.rs:343 / page_frame.rs:349) - allocate_page_frames now retries up to 1000 times when the current task is an OOM victim, preventing livelock when the victim is stuck in an uninterruptible allocation during exit. - Also wakes the page reclaim thread to accelerate memory availability. - This eliminates the previous dead_code warning on current_is_oom_victim. P2: Skip direct reclaim for fault-injection OOM (fault.rs:521 / oom.rs:349) - Add is_fault_inject_target() to check if current task matches the oom_fault_inject config. - When true, skip the shrink_list(64) direct-reclaim step so the injection is consumed by the killer path rather than a reclaim-then-retry cycle. - Without this, fail_times=1 injections were consumed by reclaim, causing test_current_is_victim and test_vmstat_oom_kill_counter to fail. Verified: make kernel + make fmt (cargo fmt + clippy) pass, zero warnings. Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
…GENTS.md - Add Nix develop/yolo command pointer to '常见命令' section - Add WHERE TO LOOK table with 3 non-intuitive paths: - Running DragonOS -> docs/introduction/develop_nix.md - OOM Killer -> kernel/src/mm/oom.rs - Post-refactor process management -> state.rs / exit.rs (mod.rs split in DragonOS-Community#1993) Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
Phase 1 (bug fixes + observability):
Phase 2 (victim forward-progress guarantee, prevents OOM livelock):
Phase 3 (direct reclaim before kill):
Test:
Verified: nix develop -c make kernel + make fmt (cargo fmt + clippy) pass.
ref #1976