当前位置:网站首页>[WSL2]限制WSL2可访问的硬件资源(CPU/内存)
[WSL2]限制WSL2可访问的硬件资源(CPU/内存)
2022-06-13 01:25:00 【Ryan ZHENG】
WSL2理论上可用获取Windows系统内管理的所有CPU、内存资源;
但这带来一个问题,即:
有时候我们使用WSL2只是作为一个终端窗口使用,并不会使用太多CPU或内存,但由于Linux内核的内存管理机制,它会尽量缓存一些已经读取过的文件页,在很长一段时间内是不会释放的。并且这部分文件页也不会被Windows回收,导致WSL2占用过多内存,而Windows反而没有内存可用的情况;
针对这种场景,可以在%UserProfile%下创建一个.wslconfig文件来进行配置:
(%UserProfile%通常是C:\Users<$username>\)
[wsl2]
processors=4
memory=4GB
swap=4GB
- processors顾名思义就是限制CPU核心数(会体现在/proc/cpuinfo等节点上)
- memory则是可使用的内存总大小(会体现在/proc/meminfo等节点上)
- swap则是交换空间的总大小(会体现在/proc/meminfo等节点上)
保存修改后关闭WSL,并重新打开窗口启动:wsl --shutdown Ubuntu
查看各个节点,已生效:
ryan /mnt/c/Users/ryan $ cat /proc/cpuinfo | grep processors
ryan /mnt/c/Users/ryan $ cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
ryan /mnt/c/Users/ryan $ cat /proc/meminfo | grep Total
MemTotal: 4028148 kB
SwapTotal: 4194304 kB
VmallocTotal: 34359738367 kB
HugePages_Total: 0
边栏推荐
- Redis usage optimization summary learning
- [Stanford Jiwang cs144 project] lab1: streamreassembler
- 【斯坦福計網CS144項目】Lab1: StreamReassembler
- Network communication tcp/ip
- Tweets movement description and chart display
- [从零开始学习FPGA编程-21]:进阶篇 - 架构 - VerilogHDL编码规范
- Pytorch's leafnode understanding
- Database query user mailbox
- 在国企做软件测试工程师是一种什么样的体验:每天过的像打仗一样
- 軟件測試的幾種分類,一看就明了
猜你喜欢

Rasa对话机器人之HelpDesk (三)

leetcode 142. Circular linked list II

Alexnet实现Caltech101数据集图像分类(pytorch实现)

RSA encryption colloquial explanation

V-inline-date, similar to Ctrip, flying pig, time selection with price

What kind of experience is it to be a software test engineer in a state-owned enterprise: every day is like a war

Introduction to convolutional neural network

Plusieurs catégories de tests logiciels sont claires à première vue

Jenkins continuous integration operation

Network communication tcp/ip
随机推荐
Wal mechanism of MySQL
Rasa dialogue robot helpdesk (III)
Sliding window summary of TCP connections
Wikipedia API User Guide
Mysql database listening -canal
Leetcode 05 tree
Wangdao machine test - Chapter 6 - maximum common divisor GCD and minimum common multiple LCM
Leetcode question brushing 07 double pointer
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of vrsi, bbiboll, WR, bias and RSI indicators
Temporary objects and compilation optimization
MySQL performance analysis - explain
Several categories of software testing are clear at a glance
Leetcode 01 array
ES6 deconstruction assignment
The interviewer only asked me five questions and the interview was over
数学知识整理:极值&最值,驻点,拉格朗日乘子
Web Application & applet application deployment
H5 open the app. If the app is not downloaded, jump to the download page. If the app has been downloaded, wake up the app
ES6解构赋值
Happy string