← Retour au blog
tech 12 September 2026

Stop Making Swap Partitions: Use Swap Files Instead

Why stick to swap partitions when swap files offer more flexibility and the same performance? Discover why and how to switch to swap files.

Article inspired by the original source
Stop making swap partitions—use swap files instead ↗ gist.github.com

Introduction: Why Change?

For over 20 years, swap files have proven to offer the same performance as swap partitions. Yet, many Linux distributions continue to promote using swap partitions during installation. Why? Perhaps out of habit or lack of information. It's time to revisit this practice and understand why swap files are a better option.

Swap Files: Flexibility and Simplicity

The main advantage of swap files lies in their flexibility. Unlike swap partitions, which require complex disk resizing, swap files can be easily created, deleted, or resized after system installation. This is particularly useful in environments where memory needs can change rapidly.

To create a swap file, simply use the command:

``bash mkswap --size 4G --file /swapfile ``

This command requires util-linux 2.40 or newer. It creates the file, sets permissions, preallocates blocks, and since version 2.41, it also sets the nocow attribute to work on Btrfs.

Better Resource Management

Swap files allow for better system resource management. For instance, if your server starts running low on memory, you can easily increase the swap file size without disrupting system operation. This isn't possible with a swap partition without risking system instability.

Limitations and Exceptions

It's important to note that some file systems, like ZFS, do not yet support swap files well, which can lead to stability issues under heavy load. However, for most other file systems, swap files work perfectly.

How to Persist Changes?

To ensure the swap file is activated at every boot, simply add the following entry to /etc/fstab:

``bash echo "/swapfile none swap defaults 0 0" >> /etc/fstab ``

Conclusion: Take Action

Swap files are not only easier to manage but also more adaptable to changing server needs. Adopting this method can improve your system's flexibility and responsiveness. So, why continue using swap partitions?

Let's discuss your project in 15 minutes.

swap files swap partitions Linux system administration performance
Deepthix newsletter · 100% AI · every Monday 8am

An AI agent reads tech for you.

Our AI agent scans ~200 sources per week and ships the best articles to your inbox Monday 8am. Free. One click to unsubscribe.

Visit the newsletter page →

Want to automate your operations?

Let's talk about your project in 15 minutes.

Book a call