If your computer starts slowing down while juggling multiple programs, there’s a good chance a swap file is quietly keeping things moving. This hidden file on your disk extends your system’s memory, acting as a safety net when RAM runs short. As Microsoft Learn (official Windows documentation) explains, the page file helps manage memory and supports crash dumps — a sign that swapping is both a fallback and a feature. Here’s what you need to know about swap files across Linux, Windows, and Android.

Default swap file name on Linux: swapfile ·
Default page file name on Windows: pagefile.sys ·
Typical swap size recommendation for 32GB RAM: 2GB to 8GB ·
Swap file location (Linux root): /swapfile

Quick snapshot

1Confirmed facts
2What’s unclear
  • Exact performance impact compared to swap partition varies by workload
  • Optimal swap size for 32GB RAM depends on hibernation usage and memory load
  • Effectiveness of swap on Android devices without dedicated hardware
3Timeline signal
4What’s next
  • Administrators may need to resize swap files as memory demands grow; Linux swap files are easier to resize than swap partitions
  • Systems with 32GB RAM often need only 2–8GB of swap

The table below distills default names and locations across operating systems.

Key swap file facts at a glance
Default swap file name on Linux swapfile
Default page file name on Windows pagefile.sys
Typical location (Linux) /swapfile (root of filesystem)
Default location (Windows) C:\pagefile.sys
Maximum page file size (Windows 10) Up to 3× RAM or 16TB (whichever is smaller)
Swap creation command (Linux) fallocate or dd, then mkswap and swapon
Required permissions Usually 600 (root only)
Persistence on Linux Requires entry in /etc/fstab

What is the purpose of a swap file?

What exactly is a swap?

  • A swap file is a system file that creates temporary storage on disk when the system runs low on memory (Lenovo (PC manufacturer glossary))
  • It allows the operating system to move inactive memory pages out of RAM so active processes can continue running (Rackspace (cloud hosting documentation))
  • Also called a page file on Windows or paging file in older systems

In plain English, a swap file is like an overflow room for your computer’s short-term memory. When RAM gets full, the system pushes less-used data to the swap file, freeing up space for the tasks you’re actively working on.

The trade-off

A swap file buys you room to run more apps than your RAM alone can hold, but it’s slower than physical memory because disk access is many times slower than RAM. That’s why you’ll feel the system lag when swapping kicks in heavily.

What is a swap file example?

The default swap file on Linux is named swapfile, while Windows uses pagefile.sys as its page file. Both serve the same purpose: extending RAM with disk storage.

Where is the swap file located?

What is a swap file in Linux?

What is a swap file on Android?

  • Android does not use a swap file by default – it relies on a technique called zRAM (compressed RAM) instead
  • Rooted devices with custom kernels can enable swap files, but this is uncommon and may reduce flash storage lifespan
Bottom line: What this means: Android’s approach avoids the wear of frequent write operations to flash storage, which is more important on mobile devices than on desktops.

How to make a swap file?

Creating a swap file on Linux

  1. Create a file of the desired size using fallocate or dd. Example: fallocate --length 2GiB /swapfile (INTROSERV (Linux tutorial site))
  2. Set the file’s permissions so only root can read/write: chmod 600 /swapfile
  3. Format the file as swap space: mkswap /swapfile
  4. Enable the swap file: swapon /swapfile
  5. To make the swap permanent, add this line to /etc/fstab: /swapfile swap swap defaults 0 0

Setting page file size on Windows 10

  • Navigate to System Properties → Advanced → Performance Settings → Advanced → Virtual Memory
  • Uncheck “Automatically manage paging file size”
  • Select a drive, choose “Custom size”, then enter the initial and maximum size (e.g., 2048 MB to 8192 MB)
  • Click Set, then OK (you may need to reboot) (Microsoft Learn (official Windows documentation))

Swap file on Android (rooting required)

  • Root access and a custom kernel that supports swap are required
  • Tools like Swapper for Root or RAM Expander can create a swap file on the SD card
  • Performance gains are often minimal and come with increased flash wear

How to get rid of a swap file?

Disabling swap on Linux

  • Turn off all swap with: swapoff -a
  • To disable a specific file: swapoff /swapfile (Rackspace (cloud hosting documentation))

Removing swap file

  • After disabling, delete the file: rm /swapfile
  • Remove or comment out the swap entry in /etc/fstab to prevent re-activation on reboot (INTROSERV (Linux tutorial site))

Deleting page file on Windows

  • Open Virtual Memory settings and select “No paging file”
  • Click Set, then restart for the change to take effect
  • pagefile.sys will be deleted automatically after reboot

The implication: removing swap is straightforward once you disable it.

How much swap for 32GB RAM?

General swap sizing rules

  • Older rule of thumb: 2× RAM for hibernation, 1× RAM without hibernation
  • For 32GB RAM, that would mean 32GB to 64GB – but that’s overkill for most systems today
  • Linux kernel developers suggest swap size equal to RAM if you want hibernation, otherwise minimal (Rackspace (cloud hosting documentation))

Swap size for hibernation vs. without hibernation

  • Hibernation writes the entire contents of RAM to swap, so swap must be at least as large as RAM
  • Without hibernation, swap can be much smaller – just enough to handle memory pressure episodes

Modern recommendations for 32GB RAM

  • A practical range is 2GB to 8GB, depending on workload (Rackspace (cloud hosting documentation))
  • Systems that run many virtual machines or memory-heavy databases may benefit from 16GB or more
  • If you never see swap usage approaching zero, you can reduce the swap file size safely
The upshot

For most desktop users with 32GB RAM, 4GB of swap is a sensible default. It covers memory spikes without wasting disk space. If you use hibernation, set swap to 32GB or more.

For most users, a conservative swap size balances safety and storage efficiency.

Swap file vs page file: What is the difference?

Swap file vs swap partition

  • Swap file: stored on a regular filesystem; can be resized, moved, or removed without repartitioning (Lenovo (PC manufacturer glossary))
  • Swap partition: a dedicated partition on the disk with a fixed size; resizing requires repartitioning tools
  • Performance is similar, though swap partitions have slightly less overhead because they don’t go through the filesystem layer

Swap file vs page file on Windows

  • They are the same concept: a file used as virtual memory. Windows calls it the page file (pagefile.sys) (Microsoft Learn (official Windows documentation))
  • Windows also has a secondary file, swapfile.sys, used only for Universal Windows Platform (UWP) app suspend/resume

Performance considerations

  • SSDs are much faster than HDDs for swap, reducing the performance penalty
  • Placing swap on an SSD may accelerate wear, but modern SSDs can handle typical swap writes for years
  • For heavy swapping scenarios (e.g., running out of RAM frequently), a swap partition may offer marginally better performance than a swap file due to filesystem overhead

Five features, one pattern: swap files give you flexibility; swap partitions give you raw speed. For most users, the convenience of a swap file outweighs the tiny performance edge of a partition.

Swap file vs swap partition at a glance
Feature Swap file Swap partition
Setup Create file, format, enable Partition in advance
Resizing Easy – just change file size Hard – needs repartitioning
Removal Delete file Remove/edit partition
Performance Very close Slightly less overhead
Flexibility High Low

The trade-off: If you often tweak your system’s memory configuration, a swap file is your friend. If you set it once and forget it, a swap partition is just fine.

Step-by-step: Creating a swap file on Linux

  1. Check current swap usage: free -h or swapon -s (Rackspace (cloud hosting documentation))
  2. Decide your swap size (e.g., 2GB for 32GB RAM). Use fallocate --length 2GiB /swapfile
  3. Secure the file: chmod 600 /swapfile
  4. Format as swap: mkswap /swapfile
  5. Enable it: swapon /swapfile
  6. Add to /etc/fstab for permanence: /swapfile swap swap defaults 0 0
  7. Optionally adjust swappiness: sysctl vm.swappiness=10 (less aggressive swapping) (Rackspace (cloud hosting documentation))

These steps ensure a persistent, secure swap file.

Clarity: what we know and what’s uncertain

Confirmed facts

  • Swap file acts as virtual memory extension using disk storage
  • Linux uses swap files and swap partitions interchangeably
  • Windows uses pagefile.sys as its swap file
  • Swap files can be created, resized, and removed without repartitioning

What’s unclear

  • Exact performance difference between swap file and swap partition in real-world workloads
  • Optimal swap size for 32GB RAM when you don’t use hibernation
  • How well Android swap implementations work without dedicated hardware support

Expert perspectives on swap files

“A swap file is a system file that creates temporary storage space on a solid-state drive or hard disk when the system runs low on memory.”

Lenovo Glossary (PC manufacturer glossary)

“A swap file is a type of swap memory for Computers. It is a good thing.”

Reddit user in r/linuxquestions

For users deciding between a swap file and a swap partition on Linux, the choice comes down to flexibility versus raw performance. If you value easy resizing and removal, a swap file is the practical pick. If you prefer the predictability of a dedicated partition, that route still serves fine. For Windows users, the page file is managed automatically – but for anyone customizing a system with 32GB RAM, setting a manual size of 4–8GB offers a balanced safety net.

Frequently asked questions

Can I delete the swap file?

Yes, but only after disabling it. On Linux, run swapoff then delete the file. On Windows, set the paging file to “No paging file” and reboot.

Does a swap file affect performance?

Yes – swap is slower than RAM because it uses disk I/O. However, if your system rarely swaps, the impact is negligible. Heavy swapping can slow things down significantly.

Is a swap file necessary on a system with enough RAM?

Not strictly necessary, but still useful. Even with 32GB RAM, a small swap file can help the kernel manage memory more efficiently and provide a safety buffer. It also enables crash dumps and hibernation.

What happens when the swap file is full?

If swap is full and RAM is exhausted, the system will start killing processes (Out-of-Memory Killer on Linux) or crash. This is rare on systems with enough RAM and a properly sized swap file.

Is it better to put swap on an SSD or HDD?

SSD is faster, so it’s better for swap performance. The additional wear from swap writes is generally not a concern for modern SSDs with proper wear-leveling.

Can I move the swap file to a different drive?

Yes. On Linux, create a new swap file on the desired drive, enable it, then remove the old one. On Windows, you can change the page file location in Virtual Memory settings.

Should I use a swap file or swap partition on Linux?

Swap files are easier to manage and resize. Swap partitions have slightly less overhead. For most users, swap files are the modern recommendation. If you need hibernation, ensure the swap file is at least as large as RAM.

FAQs address common user concerns about swap management.