Reason

This afternoon, my computer was running very slowly. When I opened the task manager, I found that the process named Vmmem used nearly 7 GB of memory. This is a wsl2 process. I found a solution in this issues.

今天下午电脑突然非常卡,打开任务管理器,发现名为 vmmem 的进程占用了接近7个G的内存,查了一下,发现是 wsl2的 进程,检索到 WSL的官方 issues,里面提供了解决方法

How to limit the maximum memory usage of wsl2

Limiting the memory of WSL2 is very simple, just create the %UserProfile%/.wslconfig configuration file.

Steps:

  1. Press the shortcut key windows + r, type in the window: %UserProfile% and press Enter

  2. In the pop-up Explorer, create a .wslconfig file with the following content:

    1
    2
    3
    4
    
    [wsl2]
    memory=2GB
    swap=0
    localhostForwarding=true
  3. 使用命令 wsl -l -v 查看当前运行的 Linux 子系统

List all sub linux

  1. 使用命令 wsl -t Ubuntu-20.04, 停止 Linux 子系统

    • 需要修改 Ubuntu-20.04 为你实际的名字
  2. 使用命令 wsl -d Ubuntu-20.04 启动 Linux 子系统

  3. 对于 的更多配置,请参考官网文档

附上修改后的内存占用截图

修改之前的忘记截图了

Vmmem内存占用

英文装逼失败,哈哈,就这样吧,能看懂就行