I know most questions around WSL/2 are about reducing memory usage, but mine is a little different. I have 32 GB available in Windows, but WSL2 is only allowing me to use up to 24 of that. Is there anyway to make sure all the memory Windows has is also available in WSL? Or is that reserved for the system for a specific reason?
Windows Build:
PS C:\Users\dakot> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 19044 0wsl.conf does not exist in Ubuntu WSL instance:
dakota@DESKTOP-1KK3IBB:~$ cat /etc/wsl.conf
cat: /etc/wsl.conf: No such file or directory
dakota@DESKTOP-1KK3IBB:~$ ls /etc | grep wsl
dakota@DESKTOP-1KK3IBB:~$.wslconfig is not found in my %UserProfile% directory:
PS C:\Users\dakot> ls Directory: C:\Users\dakot
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 3/2/2022 9:46 AM .aws
d----- 3/2/2022 9:46 AM .azure
d----- 3/1/2022 8:22 AM .docker
d----- 2/28/2022 3:31 PM .dotnet
d----- 2/28/2022 2:50 PM .gnupg
d----- 3/1/2022 8:07 AM .vscode
d-r--- 2/28/2022 1:48 PM 3D Objects
d-r--- 2/28/2022 1:48 PM Contacts
d-r--- 3/1/2022 1:15 PM Desktop
d-r--- 3/1/2022 7:43 AM Documents
d-r--- 3/2/2022 11:29 AM Downloads
d-r--- 2/28/2022 1:48 PM Favorites
d-r--- 2/28/2022 1:48 PM Links
d-r--- 2/28/2022 1:48 PM Music
dar--- 3/1/2022 12:32 PM OneDrive
d-r--- 2/28/2022 1:49 PM Pictures
d----- 2/28/2022 2:35 PM Postman
d-r--- 2/28/2022 1:48 PM Saved Games
d-r--- 2/28/2022 1:49 PM Searches
d----- 3/1/2022 9:30 PM source
d-r--- 2/28/2022 3:05 PM Videos
d----- 3/1/2022 8:14 AM wkspaces
-a---- 2/28/2022 2:46 PM 144 .gitconfig
-a---- 2/27/2022 10:08 PM 780 id_ecdsaWSL is running Version 2:
PS C:\Users\dakot> wsl -l -v NAME STATE VERSION
* Ubuntu Running 2 docker-desktop-data Running 2 docker-desktop Running 2 12 1 Answer
Preface
Is there anyway to make sure all the memory Windows has is also available in WSL? Or is that reserved for the system for a specific reason?
"All" memory? No. Windows has to have something to run in, and it's not a lightweight OS by any means. 4GB is the minimum system requirement for Windows 11. It can probably get away with a little less than that, but it's not a good idea.
"Specific purpose"? There are many, really. Your desktop, taskbar, network stack, GPU (especially if integrated), dozens of services (see the "Services" plugin) such as the event log, etc. etc. etc.
Not to mention needing room left over for any applications such as your web browser.
However, if you really do need to increase the amount of memory available to WSL2, then read on.
Short answer:
First confirm the actual amount of memory currently available to WSL2 via top. Then, if you really do need to increase it:
Close WSL, then from PowerShell:
Write-Output "[wsl2]
memory=26GB" >> "${env:USERPROFILE}\.wslconfig"
wsl --shutdownAnd restart WSL. Note that this command will only work properly as long as you don't have an existing .wslconfig (which you have confirmed you don't). After running that command once, you'll need to manually edit the file to make future changes.
Explanation:
As noted in the doc that Ramhound linked in the comments, the amount of memory available to WSL2 can be adjusted through the use of a .wslconfig file. It can be either decreased (as you note is usually the case), or increased (as I have just confirmed on my system).
If your system is allowing 24GB of usage in WSL, then that may be a combination of system memory and swap.
You don't mention how you are checking the amount of memory, but the "easy way" is to just run the top command in WSL:
You'll see something like:
top - 20:08:13 up 0 min, 0 users, load average: 0.00, 0.00, 0.00
Tasks: 5 total, 1 running, 4 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 15955.3 total, 15581.8 free, 275.7 used, 97.8 buff/cache
MiB Swap: 4096.0 total, 4096.0 free, 0.0 used. 15469.9 avail MemI have a feeling that your WSL probably has 16GB by default, but I may be wrong.
After changing mine from 16GB to 24GB using the method noted about, I have the following:
top - 19:54:19 up 3 min, 0 users, load average: 0.00, 0.00, 0.00
Tasks: 9 total, 1 running, 8 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 24039.29+total, 23622.06+free, 291.879 used, 125.352 buff/cache
MiB Swap: 6144.000 total, 6144.000 free, 0.000 used. 23477.43+avail MemYou'll notice that the available swap also increased, since it is configured (by default) as 25% of the available memory. This can also be controlled through .wslconfig.