Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.07k forks source link

Disable swapfile.sys #190

Closed Disassembler0 closed 5 years ago

Disassembler0 commented 5 years ago

Request received via mail.

# Enable SWAP File
Function EnableSwapFile {
    Write-Output "Enabling SWAP File..."
    Remove-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name "SwapfileControl" -ErrorAction SilentlyContinue
}

# Disable SWAP File
Function DisableSwapFile {
    Write-Output "Disabling SWAP File..."
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name "SwapfileControl" -Type Dword -Value 0
}

As a side note - this isn't swap per se. This is just swapfile.sys used for suspended Modern UI applications. The real swap in pagefile.sys is unaffected by this tweak.

AzimsTech commented 5 years ago

What are the benefits and disadvantage of disabling this?

Disassembler0 commented 5 years ago

I'd say no benefits and no disadvantages provided you have sufficient hardware. :)

What it does is that it removes the hidden system swapfile.sys file which always has 256 MB in size and which is used to swap out suspended processes of Modern UI apps and Windows components such as Start menu, Cortana, Store etc. if the need arises. If this tweak is applied, you get extra 256 MB disk space free in exchange for not being able to swap out a bunch of processes occupying roughly the same size in RAM, depending on how many Modern UI apps you use (there is bunch of other tweaks which reduce them only to those which are really necessary).

I can imagine this tweak being used on systems with ridiculously small SSDs (<128 GB) and by people who absolutely want to get rid of every extraneous part of system. Other that that, it doesn't really help, but it doesn't harm either.

AzimsTech commented 5 years ago

Nice! Thanks for the clear explanation.