AlexiaChen/AlexiaChen.github.io

限制WSL2内存使用量

Opened this issue · 2 comments

发现用WSL2内存占用太大,Vmmem进程用久了就占用百分之90+%。最后命令行都打不出来。

解决方案:

  • 用wsl命令行重启WSL2 distro
  • 限制内存使用

%UserProfile%\.wslconfig创建一个文件,里面配置上:

[wsl2]
memory=10GB
swap=0

配置规范:

[wsl2]
kernel=<path>              # An absolute Windows path to a custom Linux kernel.
memory=<size>              # How much memory to assign to the WSL2 VM.
processors=<number>        # How many processors to assign to the WSL2 VM.
swap=<size>                # How much swap space to add to the WSL2 VM. 0 for no swap file.
swapFile=<path>            # An absolute Windows path to the swap vhd.
localhostForwarding=<bool> # Boolean specifying if ports bound to wildcard or localhost in the WSL2 VM should be connectable from the host via localhost:port (default true).

# <path> entries must be absolute Windows paths with escaped backslashes, for example C:\\Users\\Ben\\kernel
# <size> entries must be size followed by unit, for example 8GB or 512MB

注意: .wslconfig文件一定是UTF8的,不要带BOM,还有不要带空格什么的,不然配置文件不会起作用。

References:

我刚买的 windows,装不上 wsl2,只能 ws1, 好像版本太高咯

我刚买的 windows,装不上 wsl2,只能 ws1, 好像版本太高咯

@songtianyi 装不上?早就release了啊。不应该啊。我前年就开始用了。哈哈。