Skip to content

mm: memory pressure and reclaim for systemd-oomd, TEST-55-OOMD part 1 (#752) - #829

Merged
tamnd merged 8 commits into
mainfrom
rcl-oomd
Nov 23, 2026
Merged

tamnd merged 8 commits into
mainfrom
rcl-oomd

Conversation

@tamnd

@tamnd tamnd commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Part of #752, item 3. TEST-55-OOMD does not pass 3 times of 3 yet. See "What still fails".

What changes

  • The reclaim that a thread does for memory.high, for memory.max and for a system that is short of memory counts as a memory stall in the pressure (PSI) of its cgroup, as psi_memstall_enter of Linux. A read of a page back from swap at a fault counts too, as swap_read_folio of Linux. Before, the full avg10 of the workload slice stayed at 0 and systemd-oomd did not kill.
  • The reclaim of anonymous memory goes on from the page after the last page that it took, looks at the address space in steps of 2 MiB, and stops when it has enough pages, as walk_page_range of Linux. It skips for up to 1 second an address space that had no page to give at the last look.
  • A cgroup over memory.high takes back pages and makes its threads wait once for each batch of 64 pages that it charged over the limit (MEMCG_CHARGE_BATCH), and a thread takes back only the pages that its cgroup charged over the limit (memcg_nr_pages_over_high).
  • One read or write of the swap areas runs at a time, and the other tasks sleep until their turn, as a task of Linux sleeps in submit_bio_wait. Before, they spun on the lock of the disk driver.
  • A thread with a kill does not reclaim for memory.high at its return to user mode, and its fault does not reclaim or call the OOM killer, as Linux delivers the fatal signal before mem_cgroup_handle_over_high and out_of_memory gives true for a task in task_will_free_mem.

The causes of the failures

  1. systemd-oomd did not kill: the reclaim at memory.high did not count in memory.pressure.
  2. PID1 did not answer systemctl start for 25 seconds. The 10 workers of stress-ng --vm 10 --vm-bytes 200M were over memory.high, and each return to user mode walked all 200 MiB in the kernel. The kernel is not preemptive, so with 2 vCPUs PID1 did not get a CPU.
  3. testchill.service was killed after the kill of testmunch.service (exit 24 in testcase_preference_avoid and testcase_basic_user, exit 23 in testcase_duration_override). systemd-oomd waits 15 seconds after a kill and then looks at the pressure again. testbloat.service keeps the pressure of the workload slice high, so the test must see that testmunch stopped and then see testchill in less than these 15 seconds. The killed workers took 17 to 38 seconds to exit, because each return to user mode wrote at least 64 pages to swap and the swap writes spun on the disk lock. The changes above make this much shorter, but it is not always short enough: in a debug run the killed workers took 8 seconds to exit and a systemctl status took 20 seconds.

Tests

TEST-55-OOMD of systemd 257 on x86_64, release kernel, 2 vCPUs and 1 GiB of memory, on server1. A run counts only if the host load stays at 8 or less and MemAvailable stays at 1.5 GB or more. All runs are counted runs.

Kernel Run Result Max host load
reclaim, PSI and batch changes c1 all 5 test cases pass 2.40
reclaim, PSI and batch changes c2 basic_user and preference_avoid fail (exit 24) 2.41
reclaim, PSI and batch changes c3 preference_avoid fails (exit 24) 2.31
+ swap I/O turn e1 all 5 test cases pass 2.19
+ swap I/O turn e2 duration_override fails (exit 23) 2.05
+ swap I/O turn e3 preference_avoid fails (exit 24) 2.52
+ no reclaim after a kill (this PR) f1 duration_override fails (see below) 2.02
+ no reclaim after a kill (this PR) f2 all 5 test cases pass 2.57
+ no reclaim after a kill (this PR) f3 basic_user and preference_avoid fail (exit 24) 2.37

basic_system and duration_analyze pass in each run.

  • Unit tests on the host: rk-vfs 125 ok (with a new test for the turn of the swap I/O), rk-proc 60 ok, rk-mm 73 ok, rk-cgroup 41 ok. clippy gives no new warnings. rustfmt passes. The change for a thread with a kill runs only in the kernel, so TEST-55-OOMD tests it.

What still fails

The test cases pass in about 1 run of 3. The failures are races with time limits of the test, and the system is too slow under the load of stress-ng:

  • After the kill of testmunch, the test does not see testchill in the 15 seconds before the next kill of systemd-oomd (exit 24 or 23). The killed workers take up to 8 seconds to exit, and systemctl status takes up to 20 seconds, while the 10 workers of testbloat keep both vCPUs busy.
  • In f1, systemd-oomd killed testmunch for its own pressure (over 60% for 3 seconds) before the second oomctl of testcase_duration_override, so oomctl | grep -A 2 testmunch found nothing.

The next step is the latency of user tasks when 20 threads reclaim: the kernel is not preemptive, so a thread in the reclaim keeps its CPU, and there is no group scheduling of the CPU.

The full gate did not run.

…address spaces, and a swap read is a memory stall (#752)
…lt (#752)

Linux delivers the fatal signal before mem_cgroup_handle_over_high at the
return to user mode, and out_of_memory gives true for a task in
task_will_free_mem. Before, the killed workers of stress-ng in
TEST-55-OOMD wrote pages to swap before they ended.
@tamnd tamnd added kind/bug A crash, a hang or a wrong result. area/mm Memory: frames, folios, the slab, VMAs, faults and reclaim. area/testing The test tools, the fuzzers and the compat harness. labels Nov 23, 2026
@tamnd
tamnd merged commit 7ee2e22 into main Nov 23, 2026
6 of 7 checks passed
@tamnd
tamnd deleted the rcl-oomd branch November 23, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/mm Memory: frames, folios, the slab, VMAs, faults and reclaim. area/testing The test tools, the fuzzers and the compat harness. kind/bug A crash, a hang or a wrong result.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant