Keeping System Clean: Crash Dumps and Orphaned SWAPs¶
I have already written about configuring crash dumps and swap files in my reviews of the .wslconfig configuration file and I would like to highlight them from a different perspective. Using WSL, like any other system, involves not only installation and configuration, but also maintenance. For example, archiving and rotating logs in Linux helps conserve disk space to prevent it from becoming overloaded with data. WSL also requires some attention for maintenance.
Crash dumps¶
The WSL GitHub repository contains several closed issues where crash dumps were taking up significant space on the Windows system drive. Despite the 10-dump limit, depending on the situation, each one can be quite large, leading to disk fullness.
By default, crash dumps are kept in the folder:
Where <UserName> is the Windows user name.
To avoid the situation where the disk fills up with dumps, saving can be disabled by setting:
[wsl2]
# Maximum number of crash dumps to retain
# Dependencies: None
# Default: 10
# Values:
# - -1: Disable crash dump collection
# - 0: Behavior undocumented
# - Positive integer: Maximum number of dumps to keep
MaxCrashDumpCount = 0
Or completely disable their collection:
[wsl2]
# Maximum number of crash dumps to retain
# Dependencies: None
# Default: 10
# Values:
# - -1: Disable crash dump collection
# - 0: Behavior undocumented
# - Positive integer: Maximum number of dumps to keep
MaxCrashDumpCount = -1
To check for crash dumps, use the following commands:
The storage location can also be changed by defining a new and controlled one:
[wsl2 ]
# Absolute path to crash dumps folder
# Dependencies:
# - Requires wsl2.MaxCrashDumpCount > 0
# Default: C:\Users\<UserName>\AppData\Local\Temp\wsl-crashes
# Example: crashDumpFolder = C:\\Path\\To\\wsl-crashes
crashDumpFolder = C:\\Path\\To\\wsl-crashes
If the dumps are of no value, the folder containing them can simply be deleted.
Orphaned SWAPs¶
WSL creates a shared swap file for all running instances with the path:
However, the <GUID> folder is unique for each new WSL launch. If WSL terminates unexpectedly, an orphaned page file may remain in the folder.
If a system has enough RAM, the paging file can be completely disabled:
[wsl2]
# Size of the swap file used by WSL all instances
# Dependencies:
# - The default SWAP size is 25% of the total system RAM, or 50% of the RAM specified by the wsl2.memory setting
# Default: 25% of the memory allocated to WSL
# Values:
# - 0: Disable swap entirely
# - Positive integer with unit suffix (e.g., 8GB, 1024MB)
swap = 0
Alternatively, a fixed path can be specified to avoid creating files in <GUID> folders:
[wsl2]
# Absolute Windows path to the swap file
# Dependencies:
# - Ignored if wsl2.swap=0
# Notes:
# - Use `wslinfo --vm-id` to get the <WSL VM ID>
# Default: C:\Users\<UserName>\AppData\Local\Temp\<WSL VM ID>\swap.vhdx
swapFile = C:\\Path\\To\\swap.vhdx
Orphaned SWAPs can be found using the following commands:
But first, shut down WSL so it doesn’t interfere with active swap file:
Orphaned swap files, like crash dumps, can be easily deleted.
Therefore, with just a few settings, it is easy to keep the system clean.