如何检查为 WSL Docker 分配的内存?

How to check allocated memory for WSL Docker?

我想增加为 WSL 分配的 RAM。我已经在我的根 /users/.wslconfig 中创建了。它看起来如何:

[wsl2]
memory=6GB
swap=0
localhostForwarding=true

我做了 wsl --shutdown,然后启动 WSL 以应用更改。 但我不知道如何检查分配的 RAM 是否已更改。如何查看?

一种检查方法是使用标准 Linux 命令从 WSL2 环境内部检查。在 Powershell: wslconfig /list 中通过 运行 查看您拥有的 WSL 环境,如果您正确配置了 WSL2,您还可以使用 wsl 访问 shell在权力shell.

$ free -mh
              total        used        free      shared  buff/cache   available
Mem:          7.8Gi       552Mi       5.9Gi       400Mi       1.3Gi       6.6Gi
Swap:         2.0Gi          0B       2.0Gi

我的机器上有 16GB RAM,我的 wsl2 配置是这样的:

[wsl2]
memory=8GB # Limits VM memory in WSL 2 to 8 GB

您还可以使用一些其他命令,包括:

# print memory usage statistics
$ vmstat -s

# print top processes with memory information
$ top

# fancy top
$ htop

在 Docker 桌面 CLI 中,您可以键入 cat /proc/meminfo 来检查 Docker 内存使用情况。