Giter VIP home page Giter VIP logo

wsl2-vmmem-fix's Introduction

wsl2-vmmem-fix

Helpful changes to fix vmmem eating up available physical memory and flooding your disk.
Systems with low amounts of physical RAM can benefit the most of these changes.

One reason why vmmem process uses so much memory..

ANSWER: IT IS THE FILE CACHING! :(

The high VM memory usage (in windows process vmmem) is because
linux caches files for better performance.

Most notable memory increase is because Docker images are also files (!) and are included into this cache!

To confirm this, try running some Docker containers and compare the memory usage before/after.

# linux 
free -mh (see "buff/cached" memory)

# windows
vmmem (see process memory usage)

The buff/cached memory is increased by the size of the docker image file being used!

Linux

Disable swappiness

"The swappiness in Linux is a rate in which the operating system tends to write data out of the RAM onto the disk drive (HDD or SSD)"

Letting VM to compensate lack of memory (RAM) by allowing it to flush to disk
will slow the host system down ALOT and burn trough your ssd/nvme disk also faster!

To avoid these problems disable swapiness in /etc/sysctl.conf:

vm.swappiness=0

Apply changes with sudo sysctl -p command.

NB! Increase your memory limit in .wslconfig if it is not enough for VM!

Forcing distro to release cached files memory

WSL distro kernel tries to re-claim small amounts of memory
back to host by running periodically (when CPU is idle):
echo 1 > /proc/sys/vm/compact_memory

This can be seen in dmesg -T logs:

villisco@blackbox:~$ dmesg -T
...
[Sun Oct  9 13:04:51 2022] WSL2: Performing memory compaction.
[Sun Oct  9 13:05:52 2022] WSL2: Performing memory compaction.
[Sun Oct  9 13:06:57 2022] WSL2: Performing memory compaction.

But this will not re-claim most of the files cached in memory space.

To force kernel to clear caches use:

echo 1 > /proc/sys/vm/drop_caches

NB! This will free the memory but could slow down
the performance/speed when working with WSL distro.

Read more about the WSL memory reclaiming:
https://devblogs.microsoft.com/commandline/memory-reclaim-in-the-windows-subsystem-for-linux-2/

Windows

WSL limits

WSL resource usages can be limited by .wslconfig file.

Place this file in Windows:
C:/Users/{username}/.wslconfig

Read more about available .wslconfig settings:
https://learn.microsoft.com/en-us/windows/wsl/wsl-config

wsl2-vmmem-fix's People

Contributors

villisco avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.