Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2 consume huge RAM and don't free them, also consume hug DISK I/O #9906

Open
1 of 2 tasks
dasoumao opened this issue Apr 4, 2023 · 22 comments
Open
1 of 2 tasks

WSL2 consume huge RAM and don't free them, also consume hug DISK I/O #9906

dasoumao opened this issue Apr 4, 2023 · 22 comments

Comments

@dasoumao
Copy link

dasoumao commented Apr 4, 2023

Windows Version

Microsoft Windows [版本 10.0.22621.1413]

WSL Version

1.1.6.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.90.1

Distro Version

Ubuntu-22.04

Other Software

Docker Desktop Version: 4.16.3 (96739)

Repro Steps

When Windows startup, after few minues, then wsl will auto consume a lot RAM.

Expected Behavior

Before I re-install this, it will keep about 4-5G memory. As the pic provied in #8725 it will also not use a lot I/O.

Actual Behavior

image
WSL will use about 20G memory and 700+ MB/s disk I/O. But from wsl, the memory is not actually used.
image

Addition: Memory can be released after few minues. But everytime start docker or wsl will result in hug memory consume.

Diagnostic Logs

Please tell me what log should I provide!

@benhillis
Copy link
Member

Seems like Docker is doing something inside the VM. Might be best to check with them first.

@dasoumao
Copy link
Author

dasoumao commented Apr 4, 2023

Seems like Docker is doing something inside the VM. Might be best to check with them first.

I use TOP inside the WSL, it shows Docker does not consume that CPU,I/O and RAM. This memroy is not in used, but is buff/cached, that seems just WSL use it for cache. I/O can only be find by iostat, pidstat -d can not detect any process consume disk I/O.

@dasoumao
Copy link
Author

dasoumao commented Apr 4, 2023

image

I use top inside WSL, but docker seems not consume too much RAM. Pidstat -d also cannot detect which process consume the disk I/O. And the RAM in fee is detected as buff/cache. So I guess is WSL consums the resouces.

@amegbor
Copy link

amegbor commented Apr 4, 2023

I have had similar issues on three occasions. I had to reinstall it to get back my storage space. The problem occurs when I run an analysis (resample of raster data). After the process- the size of the ext4.vdhx is over 500GB. Please fix this issue, it is very frustrating

@androiddisk
Copy link

This issue is highly expected to be noticed and resolved by the authorities

@Parneet-Raghuvanshi
Copy link

Parneet-Raghuvanshi commented Apr 12, 2023

Same issue maybe,

I am using windows 11 pro, latest updated by today 22H2, and now my mouse also dance like snake :)

In task manager->
image

but in top in ubuntu ->
image

I have 16 GB ram on my laptop and half is already used by WSL2,
and even when using IntelliJ with WSL2, sometimes it can't load maven projects.
image

WSL distro ->
image

also docker stats ->
image

any suggestions?

@jeserga
Copy link

jeserga commented Apr 14, 2023

Same problem here

@PeterHamfelt
Copy link

PeterHamfelt commented Apr 17, 2023

Same issue here. Solved by following this thread: https://support.itsolver.net/hc/en-au/articles/5742283229967-How-to-fix-vmmem-high-memory-usage-with-Docker-WSL2

@Parneet-Raghuvanshi
Copy link

Same issue here. Solved by following this thread: https://support.itsolver.net/hc/en-au/articles/5742283229967-How-to-fix-vmmem-high-memory-usage-with-Docker-WSL2

but still, this is a temporary solution :(
what if I run Kubernetes pods and IntelliJ Indexing, then this memory limitation should be extended, but if I extend then again docker will eat all memory.

@Yovach
Copy link

Yovach commented Apr 26, 2023

I'm facing the same issue… VmmemWSL consumes 500 MB/s while I'm programming and it's annoying

EDIT:
I added kernelCommandLine="sysctl.vm.swappiness=10" to the end of %userprofile%\.wslconfig file and it seems to work.
(source #9383)

@Oyami-Srk
Copy link

To solve the high mem usage. Could try freeing disk cache by corn regularly using command echo 3 > /proc/sys/vm/drop_caches.

This is more flexiable than limit the total memory of WSL2 instance.

This issue have been presented since the day of WSL2 coming out. And could be ultimately solved by making WSL2 kernel using Windows Page Cache. But that solution may be too hard to be implemented and too invasive and may lead to more bugs.

And that's why I dislike WSL2.

@DarkPhoenix2704
Copy link

WSL2 Disk & Memory Usage

WSL_disk.usage.mp4

@thesalmonidae
Copy link

Yeah this is very bad. I have 128 GB ram and I really need like 90 GB for my workload – sometimes, but WSL2 just spends it and keeps it.

This is completely unacceptable.

@megabayt
Copy link

megabayt commented Feb 9, 2024

Same here, have to do --shutdown each time I need something heavy on my host

@sharon8811
Copy link

sharon8811 commented Feb 22, 2024

If you want a workaround you can log into the VM (type wsl in powershell)
and in the VM shell enter:
sudo sync; echo 3 > /proc/sys/vm/drop_caches

it will release all the not used memory

@aleeraser
Copy link

sudo sync; echo 3 > /proc/sys/vm/drop_caches

You probably want to change this to

sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

@eboraks
Copy link

eboraks commented Apr 10, 2024

@aleeraser solution works beautifully. In my case, it took several minutes for the cache to clear; be patient.

@visitsb
Copy link

visitsb commented Jun 10, 2024

What @megabayt was facing can be elegantly solved by suggestion from @sharon8811 (and @aleeraser).

Same here, have to do --shutdown each time I need something heavy on my host

sudo sync; echo 3 > /proc/sys/vm/drop_caches

You probably want to change this to

sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

Simply execute those commands inside your VM and notice the memory getting released. I am using Windows 10 with WSL2, Ubuntu-24.04-LTS. I was originally doing what @megabayt did, but this command just did the trick to free up VM memory rightaway.

Just for the curious, sync will synchronize cached writes to persistent storage, and echo 3 | sudo tee /proc/sys/vm/drop_caches comes from sysctl files in /proc/sys/vm used to tune the operation of the virtual memory (VM) subsystem of the Linux kernel and the writeout of dirty data to disk (you can read more here).

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes.  Once dropped, their
memory becomes free.

To free pagecache:
	echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
	echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
	echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches.  This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.

This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...)  These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems.  Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use.  Because of this,
use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is
used:

	cat (1234): drop_caches: 3

These are informational only.  They do not mean that anything is wrong
with your system.  To disable them, echo 4 (bit 2) into drop_caches.

@Saya47
Copy link

Saya47 commented Jul 17, 2024

sudo sync; echo 3 > /proc/sys/vm/drop_caches

You probably want to change this to

sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

How to run this on Docker?

docker-desktop
docker-desktop-data

@presiden
Copy link

Same here.
I use Windows 11 Home Single Language version 23H2, RAM 32GB.
My WSL2 consumes a lot of memory, up to 8GB in task manager.
I only ran vuejs and spring boot application via vscode connect to WSL.

@Atry
Copy link

Atry commented Oct 9, 2024

What is interesting is that Nvidia GPU's VRAM on WSL2 is managed by Windows, therefore, WSL2's CUDA applications automatically share VRAM with Windows applications. You don't have to reserve VRAM for WSL2.

On the other hand, you must reserve CPU memory for WSL2, or the WSL2's disk cache will eat all your CPU memory and never return it.

@fagnerpereira
Copy link

[experimental]
autoMemoryReclaim=dropcache

ref: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#experimental-settings

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

No branches or pull requests