<- back to feed
technical 6 Mixed

Why You Should Use Swap Files Instead of Partitions

[thesis]

Linux users should transition from dedicated swap partitions to swap files because they offer identical performance and far greater flexibility. Swap files are much easier to create, resize, and remove after a system is already installed, eliminating the need for complex disk re-partitioning. While some niche edge cases exist, the modern Linux kernel handles swap files efficiently enough that the traditional partition method is obsolete for most users.

key points

01

Swap files provide the same speed as partitions because the kernel bypasses the filesystem abstraction for direct block access during swapping operations.

02

Managing swap files is administratively simpler since they can be added or extended on the fly without altering the physical disk layout.

03

Certain environments, such as ZFS filesystems or systems requiring hibernation, may still require specific configurations or partitions to avoid stability issues.


community discussion

6 Mixed

[consensus]

Commenters generally agree that swap is more than just a safety net for Out-Of-Memory (OOM) situations; it can improve overall system performance by allowing the kernel to page out unused anonymous pages and free up RAM for more useful caches. While some argue that high-RAM systems don't strictly need it, the prevailing view is that some swap space is beneficial for memory management efficiency. There is also a consensus that modern SSDs have significantly reduced the performance penalty of swapping compared to old spinning disks.

[i]

top insight

The discussion regarding zram vs. zswap provides a nuanced look at memory compression; zram creates a compressed block device in RAM, while zswap acts as a compressed cache that eventually writes to a physical disk. A key insight is that zswap is superior for hibernation and generally easier to implement because it doesn't require a custom daemon to handle pages that fail to compress, unlike some zram configurations. This distinguishes between temporary memory expansion and long-term storage offloading.