Skip to content

R5 memory reclaim: the reclaim counters and anonymous pages to swap, for systemd-oomd #752

Open

Description

@tamnd

Part of #14.

rukernel has swapon and swapoff, and it keeps the active swap areas, but it does not move pages to swap (core/rk-syscall/src/swap.rs). Memory reclaim takes back only clean page cache. A cgroup at memory.max first drops clean cache, and then the kernel kills a task (core/rk-cgroup). Anonymous memory never goes to swap, and the pgscan and pgsteal counters of memory.stat and /proc/vmstat stay at 0.

systemd-oomd needs these counters. It kills in a cgroup only when the pgscan rate of that cgroup is above 0 (oomd_kill_by_pgscan_rate and oomd_kill_by_swap_usage in src/oom/oomd-util.c). So in TEST-55-OOMD of the systemd boot test, oomd never kills, and stress-ng ends at its own timeout. A kill test case passes or fails only by timing. See #536, item 2.

Scope

Activity

  1. added
    kind/feature
    area/mm
    on Nov 15, 2026
  2. tamnd commented on Nov 16, 2026

    @tamnd
    OwnerAuthor

    Item 1 (the reclaim counters) is in #765. memory.stat gives pgscan, pgsteal and the kswapd and direct counts of the subtree. /proc/vmstat gives pgscan_* and pgsteal_*. A cgroup over memory.high now reclaims its page cache at the return to user mode, and a write of memory.max reclaims before the OOM kill. The reclaim covers only the page cache. Anonymous pages to swap (item 2) come next, in the parts of the plan.

  3. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    Item 2, part 1 of 4 is in #771: the slots of a swap area, the I/O of a page to swap and back, /proc/swaps Used, SwapFree, and the new swap boot test. Nothing writes to swap yet, so item 2 stays open. Part 2 (swap entries in the page table, MADV_PAGEOUT and the read at a fault) comes next.

  4. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    Item 2, part 2 of 4 is in #780: swap entries in the page table, MADV_PAGEOUT writes private anonymous pages to swap, and a fault reads them back. fork, mremap and munmap keep or free the entries. pswpin, pswpout, VmSwap and smaps Swap have values. The swap boot test passes on x86_64, arm64 and corten x86_64. Item 2 stays open. Part 3 (the reclaim of anonymous pages for a memory cgroup, memory.swap.*, memory.reclaim) comes next.

  5. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    Item 2, part 3 of 4 is in #785: the reclaim of a memory cgroup writes anonymous pages to swap after the page cache, at memory.high, at memory.max, before the OOM killer, and for memory.reclaim, which now frees memory. memory.swap.current, memory.swap.peak, memory.swap.max, memory.swap.events, and pswpin and pswpout of memory.stat work. The swap boot test passes on x86_64, arm64 and corten x86_64. Item 2 stays open. Part 4 (swapoff with used pages reads them back) comes next.

  6. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    Item 2, part 4 of 4 is in #791: swapoff of an area with used pages reads the pages back into the processes that have them, as try_to_unuse of Linux. No new page goes to the area while it reads, and the call gives ENOMEM if the pages do not fit in the free memory. The swap boot test passes on x86_64, arm64 and corten x86_64. Item 2 is complete with #771, #780, #785 and #791.

  7. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    Item 2 stays open for now. The code of the four parts is merged (#771, #780, #785, #791), but two tests of the exit did not run yet:

    • The swap boot test does not fill more memory than the VM has with a swap file active. It uses a swap disk, MADV_PAGEOUT and the reclaim of a memory cgroup.
    • LTP swapon01 to swapon03, swapoff01 and swapoff02 passed on 2026-10-28 and 2026-10-29, before these parts. They did not run again after mm: swapoff of an area with used pages reads the pages back #791.

    The memcg_* scripts of LTP test cgroup v1, and they give TCONF because rukernel mounts the memory controller on cgroup v2 (tools/ltp/controllers.md). memcontrol01 to memcontrol04 (cgroup v2) pass. Item 2 gets the tick after the two tests above pass on x86_64 and arm64.

  8. tamnd commented on Nov 18, 2026

    @tamnd
    OwnerAuthor

    #800: the swap boot test fills more memory than the VM has, with a swap file active, and the data comes back. It passes on x86_64, on arm64 and with corten. A transparent huge page now goes to swap as 4 KiB pages. LTP swapon01 to swapon03, swapoff01 and swapoff02 pass on x86_64 and arm64 with the release kernel (load 7 to 13). Item 2 is complete now with #771, #780, #785, #791 and #800. The exception is the memcg_* tests of LTP: they need cgroup v1 and give TCONF.

  9. tamnd commented on Nov 23, 2026

    @tamnd
    OwnerAuthor

    Item 3 (TEST-55-OOMD), part 1: #829.

    What #829 fixes:

    • The reclaim for memory.high, memory.max and a short system, and the read of a page back from swap, count as memory stalls in memory.pressure. Before, systemd-oomd did not kill.
    • The reclaim of anonymous memory walks the address space in steps of 2 MiB from where it stopped, and stops when it has enough pages. Before, each return to user mode of a stress-ng worker walked all 200 MiB, and PID1 did not get a CPU for 25 s.
    • memory.high works in batches of 64 pages, and a thread takes back only the pages that its cgroup charged over the limit.
    • One swap I/O runs at a time, and the other tasks sleep. Before, they spun on the lock of the disk driver.
    • A thread with a kill does not reclaim and does not call the OOM killer.

    Counted runs on server1 (x86_64, release kernel, 2 vCPUs, 1 GiB) with the final kernel: f1 duration_override fails (load 2.02), f2 all 5 pass (load 2.57), f3 basic_user and preference_avoid fail with exit 24 (load 2.37). The runs with the earlier kernels also gave 1 pass of 3 (c1 to c3, load 2.31 to 2.41; e1 to e3, load 2.05 to 2.52).

    What still fails, so the item stays open:

    • systemd-oomd kills testmunch correctly, and 15 s later it looks at the pressure of the workload slice again. testbloat keeps that pressure high, so it then kills testchill (exit 24, or exit 23 in duration_override). The test must see that testmunch stopped and then see testchill in those 15 s. On rukernel the killed workers took up to 8 s to exit and one systemctl status took 20 s, while the 10 workers of testbloat kept both vCPUs busy.
    • In f1, systemd-oomd killed testmunch for its own pressure before the second oomctl of duration_override.

    The next step is the latency of user tasks when about 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mmkind/feature

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions