What Is Swap File?

The swap file is a special file used by operating systems internally in order to store some less frequently used memory content or RAM content. the swap file also called page file or paging file and stored on the hard drive in a temporary location. The swap file is useful to solve memory problems by moving less frequently used memory content to the disk. But this may also create problems as when we try to access the content moved to the swap file it will be slower than the ram file as we need to read the disk. Here the disk speed is very important.

Swap File Advantages

Swap file provides some advantages when used properly.

  • Using more memory than currently exist.
  • Making operating systems faster.
  • Running more applications at the same time with less memory.

Swap File Disadvantages

Even though there are some advantages there are also some disadvantages to using the swap file. These disadvantages generally occur when the swap file usage is not planned properly.

  • The applications using the swap file became slower.
  • If there are a lot of applications using the swap file the general system performance drops.
  • If the disk read and write speed is not good enough the swap file operations became slower and also make other disks’ read and write operations slower.
  • If there are lots of swap file operation the system slow down.

Swap File (Page File) In Windows

Windows operating systems use the swap file but are generally named as page file or paging file. The swap file is named below for different Windows operating system versions. The page files are stored as hidden files and not displayed in the file explorer by default.

See also How To Create Local User In Windows 10?

Windows VersionSwap/Page File NamePath
Windows NT, 2000, XP, Vista, 7, 8, 10 and 11PAGEFILE.SYSC:\
Windows 95,98, and MEWIN386.SWPC:\
Windows 3.x386PART.PARC:\WINDOWS

We can display the swap file for the Windows operating systems by enabling the Hidden Items box in the file explorer. Then just navigate to the related path like C:\ for the modern operating systems like Windows 10 or Windows 11 to display the swap files.

Swap File Linux

The swap files are also used in Linux operating systems. There are different implementations for the swap file as they can be created anywhere with different names by setting type as swap filesystem. But there are popular ways like using the /swap as the swap file for the system.

We can create a swap file with the size of 2 GB like below.

$ sudo fallocate -l 2GB /swap

Then we can fill the swap file with some content.

$ sudo dd if=/dev/zero of=/swap bs=1024 count=2048576

The last step is using the mkswap command to set the type of the /swap file as swap.

$ sudo mkswap /swap

Leave a Comment