wsl2 卡顿、Tab补全卡顿问题解决

大杂烩1 min
#System#WSL
目录(3)

环境

宿主机OS: Win11 家庭版

wsl2 OS: Ubuntu 20.0.4.6 LTS

问题描述

在 Ubuntu 安装 Oh My ZSH, 及命令历史、命令高亮等插件后,使用 Tab,补全命令,可以明显感觉卡顿。

大段文字复制到终端后,也会有明显的卡顿,逐字出现不流畅。

解决方案

经过定位,排除宿主机性能问题 (3060 + 16G内存),推测是 wsl2 性能没有释放,查阅相关资料后找到了解决方案。

在指定目录添加配置文件。

// C:\Users<UserName>.wslconfig

## Settings apply across all Linux distros running on WSL 2
[wsl2]

## Limits VM memory in WSL 2GB, also can be set to other values
memory=12GB 

## Sets the VM to use two virtual processors
processors=6

## Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=6

## Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostForwarding=true

## Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx
swapfile=D:\\temp\\wsl-swap.vhdx

具体的配置说明建议参考官网文档按需调整。

WSL 中的高级设置配置 | Microsoft Learn