Windows users have often heard about some page and swap file. In this article, we will discuss what it is, what it is used for, and how to set it up correctly.
- What is the swap (page) file in Windows?
- What is the recommended paging file size?
- How to change the swap (page) file size?
- How to disable swap (page) file in Windows 10?
- How to delete the swap file (pagefile.sys and swapfile.sys) in Windows 10?
- How to re-enable the swap (page) file in case of problems?
- How to move the swap file to a different disk drive?
- What to do if important data has been lost due to manipulation of the swap file?
What is the swap (page) file in Windows?
A swap file (aka virtual memory) is a kind of file stored on a hard disk (or SSD) where RAM data is written when it becomes insufficient for the correct functioning of the operating system.
To better understand what it is, let’s look at a real example. Suppose you have a few tabs in your browser. For the operation of any tab, the system allocates the amount of RAM needed to display its contents correctly. Naturally, the more complex the content on the page, the more RAM is needed. But what to do if there are several “heavy” programs running on your computer, several tabs in the browser, and you need to open more, but your computer starts lagging?
In such a situation, the system will copy the data of not used at the moment tabs and write them on the hard disk into the swap file. After that, the data will be unloaded from the RAM, and it will be free for other tasks.
If you need to open any of the above browser tabs again – the system will read the data from the swap file and copy them back to RAM.
And then there is a reasonable question – why use RAM at all, if data can be read directly from the drive? The answer is simple: hard disks (and even SSD disks) are too slow and do not allow to provide the necessary speed of data transfer between the processor and memory. RAM is many times faster and can provide the required speed. But at the same time, its main disadvantage is a complete data loss in case of power failure. And the price is noticeably more expensive.
For example, today for the price of 16 GB of RAM you can easily get a SSD drive of 512 GB or a regular hard drive of 2 terabytes. However, it is impossible to exclude the use of RAM because of the huge (in comparison even with SSD drives) data transfer rate.
Older versions of Windows used the pagefile.sys file as a page file. Since Windows 10, two files are used – pagefile.sys and swapfile.sys They always work together and are stored in the root of the C:\ drive. To view them, you need to enable the display of hidden and system files and folders. To do this, open the C:\ drive, select the “View” tab and check the “Hidden Items” box
The first file (pagefile.sys) stores data from applications that you installed yourself from third-party sources, so it can be up to several gigabytes in size. The second file (swapfile.sys) stores data from system applications, and those you installed from the Microsoft Store. Therefore it is strongly recommended not to disable the swap file to save space on the system disk, as many system applications will stop launching. If you need to free up memory on the system disk, there are other ways to do so. For more details, read the article “How to free up space on the system disk“.
What is the recommended paging file size?
By default, the Windows 10 operating system sets the swap file size, which, according to the developers, is universal for all user’s purposes. In addition, if the computer has a large amount of RAM installed, the swap file is used seldom.
But, sometimes, the user’s tasks require increasing its size. Windows developers anticipated such a situation, so they added the desired feature. Before you start changing the swap file size, you need to know what size you should set for maximum performance. Some users believe that the larger the paging file size, the better for system performance. It is far from the truth.
If you set the swap file too high — the system will just ignore the RAM, and you will get a horrible laggy operating system instead of a better performance (because the hard disk is slower at times).
If the user sets the swap file size too small — it will be equivalent to its disabling, and many system utilities may stop working.
The Internet today offers a range of recommendations on how to calculate the swap file size. We chose the two most sensible concepts.
The first says that the larger the amount of RAM — the smaller the swap file size. It is because if the amount of RAM is very large, all temporary data will be stored there, which means that the swap file will only load the hard disk. In this case, it is recommended that you use the following settings:
- if your computer has 1 GB of RAM installed – swap file – 2048 – 2048 MB;
- if your computer has 2GB of RAM installed – swap file – 1512 – 1512 MB;
- if your computer has 4 GB of RAM installed – swap file 1024 MB – 1024 MB;
- if your computer has 8 GB of RAM installed — it is best to use the automatic swap file mode;
You probably noticed that the size value is specified twice. It is the initial and maximum size of the swap file. In the old days, when hard disks in computers were very small, it made sense to set different sizes for the paging file to save disk space. Nowadays, however, it is best to use the same value for both counts. Thus you will reduce the load – the system will not constantly recalculate the swap file size, plus the fragmentation level will be reduced.
The second method involves calculating the optimal swap file size. To do this, you should:
Step 1: Run all the applications you need to work with. Then press the “Ctrl + Alt + Delete” key shortcut.
Step 2: The “Task Manager” will open in front of you. Click on the “Performance” tab. There you will see the amount of RAM being used.
Step 3: Multiply the amount of RAM used by a factor of two and subtract the amount of installed RAM in your computer from this value.
For example, in our example, we have 6 GB of RAM installed, but Task Manager shows that 3.7 GB is being used for the workload we need. The swap file size calculation will look like this:
3,7 GB х 2 – 6 GB = 1,4 GB
Based on the calculation, we can conclude that we need to set a value of 1400 MB.
If the result of these calculations is negative, you have sufficient RAM, and the swap file can be set to automatic mode.
Important: Never set the swap file to more than three times the amount of RAM you have installed. Otherwise, you will surely get an unworkable operating system. It is best to use any of the methods described above.
How to change the swap (page) file size?
If you have done all the necessary calculations and conclude that you need to increase or decrease the paging file size, follow a series of simple steps:
Step 1: Right-click on “Start” and choose “Settings“
Step 2: The Windows preferences window opens in front of you. Click on “System“
Step 3: Scroll all the options on the left side of the window to the bottom and select “About“. Then on the right side of the window find “Advanced System Settings” and click on it.
Step 4: In the System Properties window, in the “Performance” field click on the “Settings” button.
Step 5: In the window that appears, select the “Advanced” tab and in the “Virtual Memory” field you will see what size of paging file you are currently using. If you are don’t like this value, click on the “Change” button.
You will be taken to the window for changing the paging file size. First of all, we recommend that you look at the field labeled “Total paging file size on all drives“. Here you will see three fields:
Minimum allowed– the smallest possible size you can set. Using this value is not recommended, as it can lead to unexpected consequences
Recommended – the paging file size which the system recommends you to use (compare it with the one you calculated yourself);
Currently allocated – the size of the swap file currently used by the system;
Step 6: Uncheck the box next to “Automatically manage paging file size for all drives“, then check the “Custom size” box, enter the desired value in the “Initial size” and “Maximum size” fields, click “Set” and then “OK” button.
In our case, the system recommends 1615 MB (215 MB more than we expected), so we will follow the recommendation of the operating system and use 1615 MB.
If in your case the system’s suggestion will be very different from your calculations (for example, by 1 GB) – recalculate the required swap file size again (using the instructions from the previous paragraph of this article), and use the value you got, since the operating system does not always give the right recommendations.
After clicking “OK“, restart your computer to apply the changes.
Now, the paging file size will be changed. To check this, follow steps 1 to 5 again and check the “Total paging file size on all drives” field
How to disable swap (page) file in Windows 10?
If you decide to completely disable the swap file, you can do so using the built-in features of your operating system.
Note: It is strongly not recommended to disable the swap file in Windows 10, as this may cause the operating system to malfunction.
If you think that the amount of installed RAM in your computer is enough for all tasks – it is better to enable “System recommended size“. However, if you are sure you want to disable the swap file – follow these steps:
Step 1: Click on the “magnifying glass” icon near the “Start” button and type “Adjust the appearance and performance of Windows” in the search box and click on the appropriate search result.
Step 2: Uncheck the “Automatically manage paging file size for all drives” box, then check the “No paging file” box, and click the “Set” button. Then press “OK“
Step 3: A warning will appear about the possible consequences of disabling the swap file. Click “YES” and restart your computer.
Your swap file will now be disabled.
How to delete the swap file (pagefile.sys and swapfile.sys) in Windows 10?
The pagefile.sys and swapfile.sys files are system files, so you cannot delete them using Windows 10 explorer. Usually, after disabling the swap file using the method described in the previous paragraph of this article and rebooting the operating system, the pagefile.sys and swapfile.sys files are automatically deleted. However, sometimes a swap file will remain on the hard drive even after it has been disabled. Most often this applies to the swapfile.sys
To delete swapfile.sys file manually you should:
Step 1: Right-click on “Start” and choose “Run” (you can also use the “Win + R” key combination). In the window that appears, type the command “regedit” and press “Enter“
Step 2: The Registry Editor will open in front of you. Go to the following address: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management (you can copy this address, paste it into the registry editor and press “Enter“)
Step 3: Right-click on the free space on the right side of the window and select “New” and then “DWORD 32-bit Value“
Give the new parameter the name “SwapfileControl“. After that restart your computer. The file will be completely removed from the hard drive.
If you suddenly want to bring it back – delete the “SwapfileControl” parameter you just created using the Windows 10 registry editor.
How to re-enable the swap (page) file in case of problems?
If you have resized, disabled, or deleted the swap file and have problems with your operating system, the first thing you should do is to enable it back.
In order to re-enable the swap file you should:
Step 1: Open the “Start” menu and press the “space bar“. A search box will open in front of you. Enter the query “Adjust the appearance and performance of Windows” and click on the corresponding result.
Step 2: Select the “Advanced” tab and click “Change” in the “Virtual Memory” field
Step 3: Check the “Automatically manage paging file size for all drives” box and click the “OK” button. Then reboot your computer.
If the problem was with the swap file – it should be fixed after the reboot, as the operating system will automatically adjust the size of the swap file.
How to move the swap file to a different disk drive?
Sometimes users want to move the swap file to a different disk because of the system disk’s small capacity or for other reasons. Windows built-in tools allow you to do this. It looks like removing the swap file on the system drive and enabling it for a different local drive.
To move the swap file to a different local disk, follow these steps:
Step 1: Press the “Win + R” key combination, type the command “systempropertiesadvanced” and press “Enter“
Step 2: You will see the system properties in front of you. In the “Performance” field, click the “Settings” button.
Step 3: While in the performance settings, select the “Advanced” tab and click “Change” in the “Virtual Memory” field
Step 4: Uncheck the “Automatically manage paging file size for all drives” box. In the list of connected drives, select the drive that currently holds the page file (in our case, the system drive) and check the “No paging file” box below. Then click “Set“
Step 5: Without closing the window, select the disk to which you want to move the swap file (by clicking on it) and check the “Custom size” box below. Then specify the paging file size in the corresponding fields, or check the option “System managed size” to let Windows determine the paging file size itself and then click “Set” again. Then click the “OK” button and restart your computer.
During the next boot, the swap file will be deleted from the disk where it was stored, and created on the one you specified.
What to do if important data has been lost due to manipulation of the swap file?
Often manipulations with the swap file can cause Windows failure, and it is not always possible to restore its functionality. In such a situation, you usually reinstall the operating system, which inevitably results in formatting the C:\ drive, and if important information was stored there, it will be lost.
If such a situation has happened to you, use a professional RS Partition Recovery program right away. Otherwise important files may be lost forever.
The program has an intuitive interface, so the recovery process does not cause difficulties even for inexperienced PC users.
RS Partition Recovery supports ALL modern file systems, so it does not matter in what operating system the drive was used. The most important thing is that you connect the drive with the important file to the working computer.
We’d also like to mention the deep disk scanning mode, which allows you to recover even files that were lost several months ago.
So, in order to recover a lost file you should:
Step 1. Install and launch the RS Partition Recovery.
Step 2. Select the drive or partition from which you want to recover data.
Step 3. Choose the type of analysis.
Fast scan you should use in case the file was lost recently. The program will scan the drive quickly and show the files available for recovery.
The Full analysis function allows you to find lost data, after formatting, disc resizing, or file structure corruption (RAW).
Step 4. Preview and select the files to recover it.
Step 5. Add the files you want to save to the "Restore list" or select the entire partition and click Recovery.
It should be noted that it is best to save the recovered file to an external hard drive or USB flash drive.