[WSL2] Ineffective POSIX_FADV_DONTNEED causes persistent page-cache growth and Windows host memory depletion despite autoMemoryReclaim=dropCache

Open
#42,123 18 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
8/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, linux

Research direction

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.

Written by the indexing model from the issue text.

Description

bydesign wsl2

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=dropCache behavior 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

Dominant language
C++
Stars
34.4k
Forks
1.9k
Avg merge
1d 23h
Merged PRs (30d)
166

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/WSL

All issues in microsoft/WSL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.