@DanielB does actually answer this perfectly correctly in the comments, but, as I said in my reply on another question, it probably needs an answer to fully explain it.
First, realize that there are (for the sake of this discussion) two parts to WSL2:
The Virtual Machine Platform where the actual WSL2 virtual machine is running. To my knowledge, there's no way for you to actually see or interact with this virtual machine.
The WSL2 distributions that you run. These aren't virtual machines themselves, but are instead separate containers created inside individual namespaces.
Each WSL2 distribution (I call them "instances") has its own individual:
- Users
- Mounts
- PID mapping
- And more
But it also shares some resources with the parent. As with a Docker container:
- The same kernel is being used for all WSL2 instances
- The same memory is being used for all WSL2 instances
- Of course, the same CPU
- The same device tree (
/dev
), which includes /dev/sdb
where the swap lives.
- And, most importantly for your question, the same Swap memory itself is being used for all instances.
This swap is handled by and mounted in the parent VM that you can't access. It's reported in /proc/swaps
, but that report comes from the parent VM kernel.
This is identical to the way that Docker containers handle swap. I just ran an Ubuntu Docker container on two different hosts (one virtual itself, the other physical). One reported:
$ cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 2097148 300288 -2
The other:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sdb partition 524284 780 -2
In the first case, /swapfile
does not exist within the container. On the second, /dev/sdb
is not mounted within the container.
will something be broken if I do it or add the corresponding line to /etc/fstab
?
I don't know the answer to that. In my previous answer that you linked to, I said it was "not recommended", but I do not know if there's any potential problem that could occur. It seems safe, but it certainly seems safer not to ;-).
/dev/sda
and see the file namedfile
there. So your comment says nothing linked to my questions to me.