Command hangs when autoMemoryReclaim=gradual with distro systemd enabled
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
### Windows Version
Microsoft Windows [Version 10.0.22621.2428]
### WSL Version
2.0.5.0
### Are you using WSL 1 or WSL 2?
- [X] WSL 2
- [ ] WSL 1
### Kernel Version
5.15.133.1-1
### Distro Version
Debian 12 + Arch Linux
### Other Software
Visual Studio Code (Latest version) with C# extension
.NET Core SDK 6.0/7.0
Docker Desktop 4.24.2 (124339)
### Repro Steps
1. Update to latest WSL pre-release version by running `wsl --update --pre-release`
2. Enable systemd support in wsl.conf
3. Set autoMemoryReclaim=gradual in .wslconfig
4. Restart WSL to apply settings
5. Do something such as updating packages or writing apps in WSL, or open Docker Desktop, then WSL will allocate a lot of `buff/cache` memory
6. After that, place WSL distro command line windows aside for several minutes, to avoid WSL terminating distro automatically, and to allow WSL reclaiming memory
7. Then, execute arbitrary of commands, such as `sudo pacman -Syu` `sudo apt update` `systemctl status`.
### Expected Behavior
This command will be executed instantly.
### Actual Behavior
You will find that this command may hangs for a very long time. After kernel re-allocating `buff/cache` memory, everything works again.
Disabling systemd support also works.
I think it is maybe a mechanism in Linux kernel.
Screenshots:


### Diagnostic Logs
[WslLogs-2023-10-25_16-30-50.zip](https://github.com/microsoft/WSL/files/13163519/WslLogs-2023-10-25_16-30-50.zip)
Contributor guide
Research direction
Start by reproducing the hang with systemd enabled and autoMemoryReclaim=gradual on the reported Debian 12 or Arch Linux setup, then inspect the attached WSL diagnostic logs. Verify the fix by repeating package updates, systemctl status, and other commands after memory reclamation without prolonged hangs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100