Skip to content

x86: restore swap and enable zram, MGLRU and PSI - #146

Merged
slp merged 3 commits into
libkrun:mainfrom
jmagder:enable-zram
Sep 22, 2026
Merged

slp merged 3 commits into
libkrun:mainfrom
jmagder:enable-zram

Conversation

@jmagder

@jmagder jmagder commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

CONFIG_SWAP (along with CONFIG_VM_EVENT_COUNTERS) was dropped from this config in b085fa0, while the other variants kept it. A guest whose working set exceeds its krun.ram_mib ceiling can only OOM-kill: there is no other swap path (no block devices are exposed through podman+krun, and virtiofs cannot host swapfiles), so zram is the only viable in-guest backend.

  • CONFIG_ZRAM + zstd backend: inert until guest userspace initialises the device (disksize starts at 0)
  • CONFIG_LRU_GEN (MGLRU): strictly-better reclaim under anon-heavy pressure; default on mainstream distro kernels
  • CONFIG_VM_EVENT_COUNTERS, CONFIG_PSI: restore memory telemetry (pswpin/pswpout in /proc/vmstat, /proc/pressure/*)

ZSMALLOC and CONFIG_ZRAM_DEF_COMP="zstd" materialise via make olddefconfig; ZSTD_COMPRESS/ZSTD_DECOMPRESS are already enabled.

Refs: #145

CONFIG_SWAP (along with CONFIG_VM_EVENT_COUNTERS) was dropped from
this config in b085fa0, while the other variants kept it. A guest
whose working set exceeds its krun.ram_mib ceiling can only OOM-kill:
there is no other swap path (no block devices are exposed through
podman+krun, and virtiofs cannot host swapfiles), so zram is the only
viable in-guest backend.

- CONFIG_ZRAM + zstd backend: inert until guest userspace initialises
  the device (disksize starts at 0)
- CONFIG_LRU_GEN (MGLRU): strictly-better reclaim under anon-heavy
  pressure; default on mainstream distro kernels
- CONFIG_VM_EVENT_COUNTERS, CONFIG_PSI: restore memory telemetry
  (pswpin/pswpout in /proc/vmstat, /proc/pressure/*)

ZSMALLOC and CONFIG_ZRAM_DEF_COMP="zstd" materialise via
make olddefconfig; ZSTD_COMPRESS/ZSTD_DECOMPRESS are already enabled.

Refs: libkrun#145
Signed-off-by: Jeffrey Magder <jeff.magder@gmail.com>
@slp

slp commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Sounds like a good idea, thanks @jmagder !

Could you please sync these changes with the aarch64 and riscv variants (we're leaving the tdx/sev aside for the moment)?

Sync the changes from the x86_64 config into the remaining
non-confidential variants, as requested in review. Both already
carry CONFIG_SWAP=y, CONFIG_ZSMALLOC=y, CONFIG_VM_EVENT_COUNTERS=y
and CONFIG_PSI=y, so reaching the same end state only requires
adding CONFIG_ZRAM with the zstd backend and CONFIG_LRU_GEN (MGLRU).

MGLRU is included with zram deliberately: with swap enabled, the
classic LRU can declare all_unreclaimable under anon-heavy pressure
while swap is still free (field-observed on x86_64), so shipping
the pair together avoids recreating that failure mode on these
variants.

The tdx and sev variants are left aside for now, per review.

Refs: libkrun#145
Signed-off-by: Jeffrey Magder <jeff.magder@gmail.com>
@jmagder

jmagder commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Sure thing @slp! I added a new commit with the requested changes: config: sync zram and MGLRU into aarch64 and riscv64 variants. Both variants already carried SWAP/ZSMALLOC/VM_EVENT_COUNTERS/PSI=y, so reaching the same end state as x86_64 only needed ZRAM (+ zstd backend) and LRU_GEN (MGLRU). I included MGLRU with zram deliberately — it's the second failure mode from #145 (classic LRU declares all_unreclaimable with swap still free), so shipping the pair avoids recreating it there. sev/tdx untouched as requested.

I cross-built both variants locally (make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-, ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-) and inspected the materialised .config — that caught that CONFIG_LRU_GEN_ENABLED is a bool with no default in 6.12, so LRU_GEN=y alone leaves MGLRU compiled but disabled at runtime. The third commit sets it explicitly on all three variants (matching distro kernels). Both variants build clean end-to-end.

CONFIG_LRU_GEN_ENABLED is a plain bool with no default in 6.12, so
CONFIG_LRU_GEN=y alone leaves the multi-gen LRU compiled in but
disabled at runtime (/sys/kernel/mm/lru_gen/enabled reads 0), and
make olddefconfig keeps it unset. Caught by building the riscv64
variant and inspecting the materialised .config.

Set it explicitly on all three variants that gained CONFIG_LRU_GEN,
matching mainstream distro kernels (MGLRU default-enabled since 6.1).

Refs: libkrun#145
Signed-off-by: Jeffrey Magder <jeff.magder@gmail.com>
@slp

slp commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jmagder !

@slp
slp merged commit 92368ed into libkrun:main Sep 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants