物理机的内存是64G,在wsl2安装完Ubuntu20.04后,输入命令:
free -g
发现只有32G,原因是默认只能获得物理机一半的内存:
WSL 中的高级设置配置 | Microsoft Learn
因此可手动修改为与物理机同等大小:
1)关闭Ubuntu系统,在 windows 目录:C:\Users\{用户名}\ ,新建一个txt文件,输入:
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory={你想要设定的内存}GB
2)保存,重命名为:.wslconfig
3)重新打开Ubuntu系统,可以看到内存已被修改。
注: