Skip to content

fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim, observability#1995

Merged
fslongjin merged 8 commits into
DragonOS-Community:masterfrom
sparkzky:fix/oom-killer-staged-fixes
Jul 9, 2026
Merged

fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim, observability#1995
fslongjin merged 8 commits into
DragonOS-Community:masterfrom
sparkzky:fix/oom-killer-staged-fixes

Conversation

@sparkzky

@sparkzky sparkzky commented Jul 3, 2026

Copy link
Copy Markdown
Member

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.

ref #1976

@github-actions github-actions Bot added Bug fix A bug is fixed in this pull request test Unitest/User space test labels Jul 3, 2026
@sparkzky

sparkzky commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread kernel/src/mm/oom.rs Outdated
Comment thread kernel/src/arch/x86_64/mm/fault.rs Outdated
@sparkzky sparkzky changed the title fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim… fix(mm/oom): staged OOM killer fixes — victim marking, direct reclaim, observability Jul 3, 2026

@fslongjin fslongjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基于本地对 PR1995 的多 subagent 对抗性审查,下面是已结合 DragonOS 与 Linux 6.6.139 源码核实后的 inline comments。

Comment thread kernel/src/mm/oom.rs Outdated
Comment thread kernel/src/mm/oom.rs Outdated
Comment thread kernel/src/process/manager/exit.rs Outdated
Comment thread kernel/src/mm/oom.rs Outdated
Comment thread kernel/src/mm/allocator/page_frame.rs Outdated
Comment thread user/apps/c_unitest/test_oom_killer.c Outdated
@fslongjin fslongjin force-pushed the fix/oom-killer-staged-fixes branch from 0c2d636 to 38f0487 Compare July 9, 2026 12:14
@fslongjin

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38f0487438

ℹ️ 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".

Comment thread kernel/src/mm/oom.rs Outdated
Comment thread kernel/src/mm/oom.rs
sparkzky and others added 7 commits July 9, 2026 16:07
…, 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>
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>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin fslongjin force-pushed the fix/oom-killer-staged-fixes branch from 38f0487 to 225610f Compare July 9, 2026 16:13
@fslongjin

Copy link
Copy Markdown
Member

@codex review

Signed-off-by: longjin <longjin@dragonos.org>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 225610f345

ℹ️ 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".

@fslongjin fslongjin merged commit 124b227 into DragonOS-Community:master Jul 9, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request test Unitest/User space test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants