注意:这篇文章上次更新于381天前,文章内容可能已经过时。
This article was last updated381 days ago, the content may be outdated.
在Windows 11 与 WSL2 的深度学习训练性能对比的测试中,我发现 WSL2 确实不适合做系统级的开发。从我接触的 Linux 设备驱动的角度来说,WSL2 无法安装内核模块,想要实现能够安装内核模块就需要自己编译 WSL2 的内核 https://github.com/microsoft/WSL2-Linux-Kernel
然而,当使用自定义内核时,很多模块都没有默认加载,导致我的 Docker 都没有正常工作。
Windows 对我来说最大的优势就是玩游戏方便,但据说 Linux 上的 wine 也可以运行大部分 Windows 游戏。
于是,我决定放弃 WSL,转向『LSW』,即 Linux Subsystem for Windows。
什么是 LSW?
LSW 其实是我的一个戏称,它是一个在 Docker 里面运行 Windows 的项目。
https://github.com/dockur/windows
在 Ubuntu 主机上安装好 Docker 后,使用下面的 docker-compose.yml 文件即可运行 Windows。
关于更多配置和使用方法,请参考原项目 dockur/windows。
1 | services: |
启动 Docker 容器后,可以通过浏览器访问 http://localhost:8006 来使用 Windows。

容器内置了 RDP 服务,可以通过 RDP 客户端连接到 Windows 桌面。 Ubuntu 上可以使用 Remmina 或者其他 RDP 客户端。
整体的使用体验是延迟还在可以接受的范围内,在需要运行那些只有 Windows 支持的应用时,可以通过这个方式来运行。
⚠️ 如果你的 Windows 容器可能会暴露在公网,请务必设置 USER 和 PASS 环境变量来设置访问密码,否则任何人都可以访问你的 Windows 容器。
我感觉我的 Windows 容器就被人黑了: https://github.com/dockur/windows/issues/1321
但是玩游戏就不太行了,毕竟 Docker 的虚拟化吃不到 GPU 的性能。
但对于玩游戏,Linux 上有自己的解决方案。
Linux 的游戏性能
Steam 是有 Linux 版本的,很多 Steam 上的游戏都可以在 Linux 上运行。
但对于我这种玩盗版游戏的人来说,Steam 支持的再好我也用不上。
于是,我转向了 wine
Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linux,macOS 及 BSD 等)上运行 Windows 应用的兼容层。Wine 不是像虚拟机或者模拟器一样模仿内部的 Windows 逻辑,而是將 Windows API 调用翻译成为动态的 POSIX 调用,免除了性能和其他一些行为的内存占用,让你能够干净地集合 Windows 应用到你的桌面。
Ubuntu 上 Wine 的安装过程参考 Wine 官方文档,我就不做无脑搬运了。
个人推荐安装 Staging branch 的 Wine,它的性能和稳定性应该介于 Stable branch 和 Development branch 之间。
安装完成后,即可通过 wine xxx.exe 来运行 Windows 应用。第一次运行时会自动创建 Wine 的配置目录,通常在 ~/.wine 下。
使用 winecfg 可以打开 Wine 的配置界面,可以设置 Windows 版本、音频驱动等。
你可能会遇到一些字体相关的问题,我采用了以下方法来解决:
https://blog.csdn.net/hknaruto/article/details/1363384251
玩游戏时可能会遇到一些依赖库缺失的问题,可以通过 winetricks 来安装一些常用的 Windows 组件。
我都是把终端输出的错误信息复制到 AI,它让我安装什么我就安装什么。
最后我用两个最近在玩的游戏来测试了一下 Wine 的性能。
- 空洞骑士
Wine 玩空洞骑士这种级别的游戏是完全没问题的,性能和 Windows 上差不多。完全感觉不到有任何卡顿。
截图左上角可以看到我的显卡和显卡驱动信息。帧率也很高,基本上在 400 FPS 左右。

- 双影奇境
我的主机使用 Wine 玩双影奇境时,帧率波动较大,会出现卡顿现象。
我使用的是 4K 显示器 + 高画质设置,帧率大概在 120-140 FPS 之间。但在某些场景下FPS会骤降,造成明显的卡顿。
在 Windows11 上玩双影奇境时,我几乎也是这个画质设置,没有测过帧率,但从没有发生过卡顿。



Linux 深度学习训练性能
装了 Ubuntu 系统后,我又测试了一下原生 Linux 系统的深度学习训练性能。
我使用了和Windows 11 与 WSL2 的深度学习训练性能对比相同的测试脚本和数据集。
测试结果如下:
- Total training time for 50 epochs: 893.31 seconds
- Total training time for 1 epochs: 16.84 seconds
果然还是原生 Linux 系统的性能最好。
在上次的测试中,我观察到 GPU 的使用率在每个 epoch 结束时会下降,WSL2 的下降幅度和时间都比 Windows 11 短很多。
测试过程中我发现在 Windows 11 系统中,在每个 epoch 结束时,GPU 的使用率会下降到 0%,并且要等待较长一段时间(相比每个 batch 的时间)才会恢复到正常的使用率。
而在 WSL2 中,也有 GPU 使用率下降的情况,但下降的幅度和时间都比 Windows 11 短很多。
在这次测试中,我也留意了一下这个现象还有没有再发生,但是因为没有像 Windows 任务管理器那样直观的 GPU 使用率显示,所以我不太确定是否有类似的现象。
从 btop 的绘图来看,似乎 GPU 使用率也存在下降的情况,但这应该是因为每个 epoch 结束时,模型的训练过程中的一些额外计算或数据处理等造成的正常现象。

In the Windows 11 vs. WSL2 deep learning training performance comparison tests, I found that WSL2 really isn’t suitable for system-level development. From the perspective of my work on Linux device drivers, WSL2 can’t install kernel modules — to be able to install kernel modules, you’d need to compile your own WSL2 kernel https://github.com/microsoft/WSL2-Linux-Kernel
However, with a custom kernel, many modules aren’t loaded by default, which even broke my Docker.
For me, Windows’ biggest advantage is that it’s convenient for gaming, but they say Wine on Linux can run most Windows games too.
So I decided to abandon WSL and switch to “LSW”, i.e., Linux Subsystem for Windows.
What is LSW?
LSW is actually a nickname of mine — it’s a project that runs Windows inside Docker.
https://github.com/dockur/windows
After installing Docker on an Ubuntu host, you can run Windows using the docker-compose.yml below.
For more configuration and usage, refer to the original project dockur/windows.
1 | services: |
Once the Docker container is running, you can use Windows by visiting http://localhost:8006 in a browser.

The container has a built-in RDP service, so you can connect to the Windows desktop with an RDP client. On Ubuntu, you can use Remmina or other RDP clients.
Overall, the latency is within an acceptable range — this is a good way to run applications that only support Windows.
⚠️ If your Windows container might be exposed to the public internet, be sure to set the USER and PASS environment variables to set access passwords; otherwise anyone can access your Windows container.
I suspect my Windows container was actually hacked: https://github.com/dockur/windows/issues/1321
But gaming doesn’t work that well — after all, Docker virtualization can’t leverage GPU performance.
However, Linux has its own solutions for gaming.
Linux Gaming Performance
Steam has a Linux version, and many Steam games can run on Linux.
But for someone like me who plays pirated games, Steam’s great support doesn’t help.
So I turned to wine
Wine (recursive acronym for “Wine Is Not an Emulator”) is a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems, such as Linux, macOS, and BSD. Instead of simulating internal Windows logic like a virtual machine or emulator, Wine translates Windows API calls into dynamic POSIX calls, eliminating performance and memory penalties of other approaches, letting you cleanly integrate Windows applications into your desktop.
For installing Wine on Ubuntu, refer to the official Wine documentation — I won’t do a mindless copy-paste here.
I personally recommend installing Wine from the Staging branch — its performance and stability should sit between the Stable branch and the Development branch.
After installation, you can run Windows applications via wine xxx.exe. The first run automatically creates Wine’s configuration directory, usually under ~/.wine.
Use winecfg to open Wine’s configuration UI, where you can set the Windows version, audio driver, etc.
You may run into some font-related issues; here’s the method I used:
https://blog.csdn.net/hknaruto/article/details/1363384251
While gaming you might hit missing dependency library issues; you can use winetricks to install some common Windows components.
I just paste terminal error messages into AI, and install whatever it tells me to.
Finally, I tested Wine’s performance with two games I’ve been playing recently.
- Hollow Knight
Wine handles games at Hollow Knight’s level without any problem — performance is about the same as on Windows. I couldn’t feel any stutter at all.
In the top-left corner of the screenshot you can see my GPU and driver info. The frame rate is also high, basically around 400 FPS.

- Split Fiction
When playing Split Fiction via Wine on my desktop, the frame rate fluctuates a lot and stuttering occurs.
I use a 4K monitor with high graphics settings; the frame rate is roughly 120-140 FPS. But in some scenes the FPS drops sharply, causing obvious stuttering.
On Windows 11, I played Split Fiction with nearly the same graphics settings; I never measured the frame rate, but it never stuttered.



Linux Deep Learning Training Performance
After installing Ubuntu, I also tested the deep learning training performance of native Linux.
I used the same test script and dataset as in the Windows 11 vs. WSL2 deep learning training performance comparison.
Results:
- Total training time for 50 epochs: 893.31 seconds
- Total training time for 1 epochs: 16.84 seconds
As expected, native Linux delivers the best performance.
In the previous tests, I noticed GPU utilization drops at the end of each epoch, and WSL2’s drop was much smaller and shorter than Windows 11’s.
During testing I found that in Windows 11, at the end of each epoch, GPU utilization drops to 0% and takes a long time (compared to the per-batch time) to recover to normal utilization.
In WSL2, GPU utilization also drops, but the magnitude and duration are much smaller than Windows 11’s.
In this test I also kept an eye on whether this phenomenon still occurs, but without an intuitive GPU utilization display like Windows Task Manager, I’m not entirely sure whether something similar happens.
Looking at the btop plots, GPU utilization does seem to dip as well, but this should be a normal phenomenon caused by extra computation or data processing in the training process at the end of each epoch.



