[WSL2] Ineffective POSIX_FADV_DONTNEED causes persistent page-cache growth and Windows host memory depletion despite autoMemoryReclaim=dropCache
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 8/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- c, linux
- Ambito
- operating-systems
Direzione di ricerca
The reproducer cache_residency is standalone C and its source is not in the payload, so start by building it with the flags in step 2 and running the bounded --scenario shifted-128k command. Use mincore() output to confirm residency, then compare the 128 KiB and 8 MiB advice runs. The kernel-side question, whether large folios defeat POSIX_FADV_DONTNEED on sub-folio ranges, is maintainer-level work in WSL's kernel, so this is a poor first contribution.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
WslLogs-2026-10-31_19-26-34.tar.gz
Windows Version
Microsoft Windows [Version 10.0.26300.9818]
WSL Version
3.0.3.0
Are you using WSL 1, WSL 2, or WSLC?
- WSL 2
- WSL 1
- WSLC
Kernel Version
6.18.54.1-microsoft-standard-WSL2
Distro Version
Gentoo Linux (WSL2, native ext4)
Other Software
Standalone C page-cache residency reproducer (cache_residency), compiled using GCC 16.2.1 on Gentoo Linux.
No Docker or third-party applications are required.
WSL configuration (%USERPROFILE%.wslconfig):
[wsl2]
memory=28GB
swap=32GB
autoMemoryReclaim is not explicitly overridden and therefore uses the documented default, dropCache.
The test uses synthetic files on the native WSL2 ext4 filesystem, sequential read() calls, POSIX_FADV_DONTNEED, and mincore() to measure file-cache residency.
Repro Steps
1. Configure WSL2
Use WSL 3.0.3.0 with kernel 6.18.54.1-1 and the .wslconfig described above. Leave autoMemoryReclaim at its documented default (dropCache).
2. Build the reproducer
In Gentoo on native ext4:
cc -std=c11 -O2 -Wall -Wextra -Werror \
cache_residency.c -o cache_residency
The reproducer creates synthetic files, verifies their contents, checks initial cache residency, reads data sequentially, calls POSIX_FADV_DONTNEED on previously consumed ranges, and measures subsequent residency with mincore().
3. Run the bounded reproduction
./cache_residency \
--scenario shifted-128k \
--file-size 64MiB \
--total-size 1GiB \
--duration 90
The workload uses:
- 128 KiB read and advice cadence
- 4 KiB initial offset
- 128 KiB trailing window
- No backward overlap
- Page-aligned advice ranges
It records advice return codes, cache residency, Linux memory statistics and Windows host available memory.
4. Observe Linux and Windows memory
Inside Linux:
grep -E '^(MemAvailable|Cached|Dirty|Writeback):' /proc/meminfo
On Windows PowerShell:
Get-CimInstance Win32_OperatingSystem |
Select-Object FreePhysicalMemory
Observe that file-cache residency accumulates while Linux continues reporting abundant available memory, but Windows available physical memory declines.
5. Compare with larger advice ranges
Using the same 256 MiB test size and the same read size, prefix, trailing window and overlap, compare:
./cache_residency \
--scenario shifted-128k \
--file-size 256MiB \
--total-size 256MiB \
--duration 60
Against:
./cache_residency \
--scenario shifted-128k \
--file-size 256MiB \
--total-size 256MiB \
--duration 60 \
--advice-cadence 8MiB
Only the advice cadence changes.
6. Additional observation
An exploratory continuous run using 256 MiB synthetic files and 128 KiB advice accumulated over 10 GiB of resident cache and substantially depleted Windows available memory. The run was interrupted manually.
The larger run used an unbounded diagnostic override. Repeating it is not necessary to reproduce the core eviction issue, and the bounded reproducer is recommended for investigation.
Expected Behavior
POSIX_FADV_DONTNEED should provide a useful proactive mechanism for discarding clean file-cache pages that an application has finished processing.
Although the interface is advisory and does not guarantee eviction, successive page-aligned advice requests covering consumed file data should ideally avoid leaving virtually the entire file resident.
In WSL2, the default automatic memory-reclamation mechanism should also help prevent excessive retention of clean Linux page-cache memory from progressively depleting Windows host memory, particularly when the guest still reports substantial reclaimable memory.
At a minimum, Windows host-memory pressure should be considered independently of Linux guest-memory watermarks, so that the guest's unused clean cache does not unnecessarily starve Windows applications of physical memory.
Actual Behavior
1. Nearly complete failure of proactive eviction
Repeated 128 KiB, page-aligned POSIX_FADV_DONTNEED requests leave almost all previously read file data resident.
In a bounded 1 GiB test:
- Data read: 1,024 MiB
- Still resident after advice: 1,020 MiB
- Residency: 99.61%
In a larger exploratory test:
- Data read: 10,496 MiB (10.25 GiB)
- Still resident after advice: approximately 10,485.8 MiB
- Residency: approximately 99.90%
The retained cache increases almost linearly with the amount of data processed.
2. Windows host-memory depletion
During the exploratory continuous test, Windows available physical memory decreased from approximately 12.5 GiB to 2.7 GiB.
Meanwhile, Linux continued reporting abundant available memory, approximately 26–28 GiB in the observed configuration.
This creates a discrepancy between the guest and host:
- Linux considers the clean file cache reclaimable and does not experience equivalent memory pressure.
- Windows loses available physical memory as the WSL2 VM retains additional cached pages.
- The default
autoMemoryReclaim=dropCachebehavior did not prevent the observed accumulation during sustained workload activity.
No Windows OOM event or crash was demonstrated. The test was interrupted manually.
3. Controlled advice-cadence comparison
A 256 MiB controlled experiment produced:
| Metric | 128 KiB cadence | 8 MiB cadence |
|---|---|---|
| Resident after advice | 255.8 MiB | 62.0 MiB |
| Reclaimed pages under subsequent cgroup pressure | ~36,800 | 0 |
| OOM kills | 0 | 0 |
The other workload parameters were identical. The result was reproduced in reversed test order.
4. Pressure-driven reclamation still works
Under a 512 MiB memory-cgroup limit, Linux successfully reclaimed approximately 143 MiB of retained file cache to accommodate anonymous allocations, without OOM.
This demonstrates that the pages remain reclaimable when Linux experiences genuine memory pressure.
The concern is that Windows host-memory pressure does not necessarily create corresponding memory pressure inside the Linux guest.
5. Cross-workload impact
In a separate random-access cache-competition benchmark using a shared 320 MiB memory limit, five trials per advice cadence produced:
- 128 KiB advice: 172 victim working-set refaults.
- 8 MiB advice: zero victim refaults.
- 128 KiB advice: approximately 228,000–234,000 cumulative page-reclaim events per trial.
- 8 MiB advice: no corresponding reclamation activity.
There was no convincing sustained throughput or p99 latency regression in the victim workload.
6. Possible explanation
The ineffective eviction may result from large page-cache folios that extend beyond individual 128 KiB invalidation ranges.
Separately, WSL2's host/guest memory-pressure mismatch allows the retained cache to occupy increasingly large amounts of Windows physical memory during continuous activity.
Diagnostic Logs
No response
- Lingua principale
- C++
- Stelle
- 34.4k
- Fork
- 1.9k
- Merge medio
- 1g 23h
- PR unite (30g)
- 166
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/WSL
-
feature wsl2
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
microsoft/WSL#42306 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/WSL#42114 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feature kernel wsl2
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
microsoft/WSL#41107 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
feature kernel
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
microsoft/WSL#41054 · 9 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
feature GPU
Difficoltà 1/5 1-3 ore Idoneità per principianti 70/100
microsoft/WSL#13592 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/WSL
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
HarperFast/rocksdb-js#1131 ·
I maintainer di solito rispondono entro 1 giorno
-
area/daemon bug good first issue platform/linux priority/p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ToshiNamura/Deimos#5 ·
-
needs-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Niko1221/Strata#6251 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
[Bug]: NP 管理器文件编辑器里删除键无效Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
metasequoiaime/msime#11666 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
patrick-hudson/put.gd-desktop#1679 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno