3

A Windows 11 system is configured with two physical storage devices. The first has a typical layout, of boot, reserved, and data partitions, whereas the second is partitioned exclusively for a page file, and due to the physical topology of the system is appropriate for nonpermanent data. Virtual memory for the system is configured to use the entire partition of the second device, and none of any partition of the first. (See below for capture of configuration.)

Despite the configuration, Windows repeatedly creates, at the root of the main file system, a file called swapfile.sys, sized of roughly 268 MB, which may not be deleted in Windows, but rather only by mounting from a non-Windows recovery environment. Even so, when Windows starts, it recreates the file.

How may I permanently remove this file, or designate its location on the secondary storage device allocated for transient storage?


enter image description here


C:\>dir /a
 Volume in drive C is Windows
 Volume Serial Number is B426-88EF

 Directory of C:\

04/07/2022  02:44 PM    <DIR>          $Recycle.Bin
10/27/2022  12:14 AM    <DIR>          $WinREAgent
10/16/2022  11:36 PM             1,024 AMTAG.BIN
10/06/2021  10:09 PM               112 bootTel.dat
10/27/2022  03:12 PM    <DIR>          Config.Msi
04/07/2022  03:27 PM    <DIR>          cygwin64
09/15/2019  06:12 AM    <JUNCTION>     Documents and Settings [C:\Users]
10/01/2022  03:33 AM            12,288 DumpStack.log
10/27/2022  05:46 PM            12,288 DumpStack.log.tmp
09/15/2019  05:41 AM    <DIR>          hp
06/07/2021  03:48 PM    <DIR>          Intel
06/05/2021  07:10 AM    <DIR>          PerfLogs
10/27/2022  03:11 PM    <DIR>          Program Files
10/16/2022  06:13 PM    <DIR>          Program Files (x86)
11/08/2022  01:42 AM    <DIR>          ProgramData
04/07/2022  04:36 PM    <DIR>          Recovery
11/08/2022  01:42 AM       268,435,456 swapfile.sys
10/27/2022  03:21 PM    <DIR>          SWSetup
10/01/2022  04:25 PM    <DIR>          System Volume Information
04/07/2022  01:41 PM    <DIR>          system.sav
10/06/2021  07:01 PM    <DIR>          Users
10/27/2022  12:28 AM    <DIR>          Windows
               5 File(s)    268,461,168 bytes
              17 Dir(s)  45,940,146,176 bytes free
3
  • Do you have FastBoot on in Windows? As far as I know you can't really delete the swapfile on the system-drive as long as FastBoot is active. The swapfile will return after each reboot (which isn't a REAL reboot, but a sort of hibernate/restart combination if FastBoot is enabled).
    – Tonny
    Commented Nov 4, 2022 at 12:16
  • @Tonny, I reboot and power down using the start menu. I am not specifically aware of the feature you mention being invoked.
    – brainchild
    Commented Nov 4, 2022 at 12:35
  • It is actually called "Fast Startup" (Fast Boot was a mistake on my part) and can be found in the advanced settings under Power Management options. It is enabled by default on most Windows 10 and Windows 11 installations and can (potentially) mess with things like the swapfile.
    – Tonny
    Commented Nov 4, 2022 at 12:56

1 Answer 1

3
+50

Bad news : What you're asking is impossible, at least for the moment.

In short : The Virtual Memory setting does not pertain to Swapfile.sys, except that to totally disable it, you need to do so by turning off totally the page-file (not recommended).

Relocating the page-file does not affect the placement of Swapfile.sys, except that turning off paging will also turn off Swapfile.sys.

TechNet explains Swapfile.sys as follows:

With the introduction of the UWP App, we needed a way to manage their memory outside of the traditional Virtual Memory/Pagefile method. With that, the “%SystemDrive%\swapfile.sys” was born.

Windows can efficiently write the whole (private) working set of a suspended UWP app to disk in order to gain additional memory when the system detects pressure. This process is analogous to hibernating a specific app, and then resuming it when the user switches back to the app. In this case, Windows takes advantage of the suspend/resume mechanism of Modern apps to empty or re-populate an app’s working set.

Windows 8/10/11 now has three similar files that pertain to totally different mechanisms:

  • Hiberfil.sys : Used for hibernation data
  • Pagefile.sys : Virtual memory used for swapping programs
  • Swapfile.sys : Used for swapping UWP memory and hardwired at %SystemDrive%\swapfile.sys

Another explanation by Microsoft’s Black Morrison says :

You may ask, ‘Why do we need another virtual page file?’ Well, with the introduction of the Modern App, we needed a way to manage their memory outside of the traditional Virtual Memory/Pagefile method.

Windows 8 can efficiently write the whole (private) working set of a suspended Modern app to disk in order to gain additional memory when the system detects pressure. This process is analogous to hibernating a specific app, and then resuming it when the user switches back to the app. In this case, Windows 8 takes advantage of the suspend/resume mechanism of Modern apps to empty or re-populate an app’s working set.

Microsoft’s Pavel Lebedinsky explains a bit more:

Suspend/resume of Metro-style apps is one scenario, there could be others in the future.

The swapfile and the regular pagefile have different usage patterns and different requirements with regard to space reservation, dynamic growth, read/write policies etc. Keeping them separate makes things simpler.

(Simpler for Microsoft doesn't mean simpler for the users.)

2
  • Thanks for the explanation. I suppose only someone intelligent enough to work at Microsoft would truly comprehend the rationale behind the design choices.
    – brainchild
    Commented Nov 6, 2022 at 9:31
  • I suppose that we have here three teams of Microsoft developers, each working in its own area. The UWP team made quite a few unfortunate design decisions, which made it unpopular for developers. This is just one more such decision. Suggesting on the Feedback Hub the feature of relocating Swapfile.sys is the most that you can do.
    – harrymc
    Commented Nov 6, 2022 at 9:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .