高端网站开发培训价格,安徽地区建设工程信息网,微商城免费开通,珠宝营销型网站我用的电脑一共有40G内存#xff0c;最近发现电脑重启后#xff0c;VmmemWSL 进程很快就会占用一多半的内存#xff08;20G#xff09;#xff0c;电脑中有多个停止运行的容器#xff0c;正常启动状态的只有一个 MySQL 服务#xff0c;通过 docker stats 查看占用内存也…我用的电脑一共有40G内存最近发现电脑重启后VmmemWSL 进程很快就会占用一多半的内存20G电脑中有多个停止运行的容器正常启动状态的只有一个 MySQL 服务通过 docker stats 查看占用内存也不多不知道为什么会占用这么多内存但是必须限制一下。
Docker Desktop 早期版本可以直接配置内存使用改成 WSL 方式后需要去调整 WSL 的资源使用参考官方文档中的示例 做了以下调整
# Settings apply across all Linux distros running on WSL 2
[wsl2]# Limits VM memory to use no more than 8 GB, this can be set as whole numbers using GB or MB
memory8GB # Sets the VM to use two virtual processors
processors4# Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6
kernelCommandLine vsyscallemulate# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap8GB# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReportingfalse# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwardingtrue# Disables nested virtualization
nestedVirtualizationfalse# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsoletrue# Enable experimental features
[experimental]
autoMemoryReclaimgradual
sparseVhdtrue将上面内容保存到 C:\Users\用户名\.wslconfig 文件中。
上面配置限制内存和交换内存都是 8G可以根据自己内存进行调整。配置autoMemoryReclaimgradual后还可以 检测空闲 CPU 使用率后自动释放缓存的内存。 设置为 gradual 以慢速释放设置为 dropcache 以立即释放缓存的内存。
修改配置后关闭 Docker关闭 WSLwsl --shutdown然后启动 WSL 和 Docker此后占用内存就很少了。