Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL distro often boots up without a swap #9395

Closed
1 of 2 tasks
CComparon opened this issue Dec 24, 2022 · 19 comments
Closed
1 of 2 tasks

WSL distro often boots up without a swap #9395

CComparon opened this issue Dec 24, 2022 · 19 comments

Comments

@CComparon
Copy link

Version

Microsoft Windows [Version 10.0.19045.2364]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.79.1-microsoft-standard-WSL2

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

Quite often, my distro starts without a swap (as shown by htop for instance), despite my .wslconfig:

[wsl2]
swap=16GB
swapFile=d:/wsl-swap.vhdx

Deleting the existing swap file, doing a wsl --shutdown and restarting the distro usually properly brings back the swap.

I haven't figured out a pattern yet. Might happen more after WSL or windows didn't shut down gracefully.

Expected Behavior

Swap consistently set up and available upon distro startup.

Actual Behavior

Swap not always set up and available upon distro startup.

Diagnostic Logs

No response

@Biswa96
Copy link

Biswa96 commented Dec 24, 2022

The path in swapFile uses double backslashes, see https://learn.microsoft.com/en-us/windows/wsl/wsl-config. Though I am not sure if that will fix this random issue.

@OneBlue
Copy link
Collaborator

OneBlue commented Dec 27, 2022

Indeed using double backslashes should resolve the issue. If it does, please share /logs

@ghost
Copy link

ghost commented Dec 27, 2022

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

Thank you!

@CComparon
Copy link
Author

The problem keeps occurring despite changing to double backslashes in my .wslconfig file:
swapFile=d:\\virtual machines\\wsl-swap.vhdx

image

Please also find some WSL logs as requested by msftbot.
WslLogs-2022-12-28_18-16-05.zip

@ghost ghost removed the needs-author-feedback label Dec 29, 2022
@OneBlue
Copy link
Collaborator

OneBlue commented Dec 29, 2022

Interesting.
Can you share the output of: lsblk, dmesg and swapon -s when the swap disapears like this ?

@CComparon
Copy link
Author

Sure thing.

When showing 0 kB swap

lsblk

NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda    8:0    0 363.1M  1 disk
sdb    8:16   0   256G  0 disk /mnt/wslg/distro
                               /

dmesg

output available here

swapon -s

no output

Repairing swap

After doing a wsl --shutdown, then manually deleting the (likely corrupted) vhdx swap file, and restarting wsl:

lsblk

NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda    8:0    0 363.1M  1 disk
sdb    8:16   0    36G  0 disk [SWAP]
sdc    8:32   0   256G  0 disk /mnt/wslg/distro
                               /

dmesg

output available here

swapon -s

Filename                                Type            Size            Used            Priority
/dev/sdb                                partition       37748736        0               -2

@ghost ghost removed the needs-author-feedback label Dec 29, 2022
@OneBlue
Copy link
Collaborator

OneBlue commented Dec 29, 2022

Thank you @CComparon. This is interesting, there's nothing is dmesg about the swap being corrupted so I'm going to guess that the issue is on the Windows side.

Can you try to capture logs once the swap is just missing ? Once you're in that state, run: wsl.exe --shutdown, start the log collection, and open WSL to show that there is no swap.

Hopefully this should capture the right error explaining what's happening to the swap disk.

Also does this happen only if docker is running or does this also happen without docker ?

@CComparon
Copy link
Author

What I did this time:

  1. wsl --shutdown
  2. manual corruptted the swap file by erasing it with echo foo > wsl-swap.vhdx
  3. started log collection
  4. started wsl htop
  5. waited for wsl to start and htop to display 0kB of total swap space
  6. stopped log collection

HTH!
Best wishes for 2023 🎆

WslLogs-2023-01-02_19-56-47.zip

@OneBlue
Copy link
Collaborator

OneBlue commented Jan 5, 2023

Based on the logs I can see that the swap disk is in: d:\\virtual machines\\wsl-swap.vhdx. Can you share the output of:

Get-Acl "d:\virtual machines"

In an elevated powershell ?

@CComparon
Copy link
Author

CComparon commented Jan 6, 2023

@OneBlue Sure thing:

    Directory: D:\


Path             Owner     Access
----             -----     ------
virtual machines T14\Cyril BUILTIN\Administrators Allow  FullControl...

Again, the fact that the swap file exists and is corrupted before starting wsl seems to be the cause of the distro booting without a swap.

@ghost ghost removed the needs-author-feedback label Jan 6, 2023
@OneBlue
Copy link
Collaborator

OneBlue commented Jan 6, 2023

I'm wondering, does starting WSL as administrator helps ? The permissions seems to only allow administrators to write that folder. What if you also give FullControl access to your current user ?

@CComparon
Copy link
Author

CComparon commented Jan 6, 2023

My current user is T14\Cyril.
If I manually delete the corrupted swap file and restart wsl, wsl has no problem recreating the swap file, which I believe rules out a filesystem permission issue.

Btw, I was able to reproduce on another machine (Windows 11), which seems to indicate that this problem is ubiquitous.

@ghost ghost removed the needs-author-feedback label Jan 6, 2023
@OneBlue
Copy link
Collaborator

OneBlue commented Jan 6, 2023

I think the issue might be about a non-elevated user trying to open the existing swap file. Can you try granting FullControl T14\Cyril and seeing if that solves the issue ?

@CComparon
Copy link
Author

I granted FullControl to T14\Cyril on the D:\virtual machines folder and its subfolders and files. Unfortunatley wsl keeps starting without a swap if the swap file exists and is corrupted.

@OneBlue
Copy link
Collaborator

OneBlue commented Jan 6, 2023

Interesting. I've added more logs to our log collection script, can you collect logs again when attaching the swap fails ?

/logs

@ghost ghost removed the needs-author-feedback label Jan 6, 2023
@ghost
Copy link

ghost commented Jan 6, 2023

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

Thank you!

@CComparon
Copy link
Author

CComparon commented Jan 14, 2023

Sorry for the delay. Attached are logs your asked for using
WslLogs-2023-01-13_21-02-19.zip
the new collector.

I am 99.9% certain anyone can reproduce this issue very easily, using the following recipe:

  1. run wsl --shutdown
  2. manually corrupt swap file e.g. echo lorem_ipsum > \path\to\swap\file\swap.vhdx
  3. run wsl htop => wsl will start and show there is no swap!

@benhillis
Copy link
Member

Fixed with https://github.com/microsoft/WSL/releases/tag/1.1.2.

@ericblade
Copy link

@benhillis
fwiw, there is still some bit of this affective. I haven't had a swap file in my WSL for quite some time now, just ran into a situation where I needed it (compile process that requires far more ram than is reasonable), and started searching. Found this, went and looked at my swap file location, and found a 32MB file there (not the 32GB specified), deleted it, restarted WSL and all was good.

I was not able to repeat it by simply restarting WSL as would be indicated by the fix for the bug, so that's good. I did not try directly trashing the existing file like OP had suggested. It seems to work across reboots now, but did not until I deleted the existing file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants