logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·31.10.26
← Back to news

Stop making swap partitions—use swap files instead

Original article
gist.github.com|49 points|66 comments|by jenders|Sep 8, 2026

🛑 Stop making swap partitions—use swap files instead!

@joshenders By joshenders

For over two decades, the performance gap between swap files and swap partitions has effectively vanished. Despite this, many Linux distributions still push users toward creating dedicated swap partitions during the initial installation process.

The reality is that swap files are far more versatile. They are significantly easier to implement, expand, shrink, or delete entirely after the OS is already running.

🛠️ Implementation Guide

If your filesystem supports it, fallocate is the preferred method because it is faster than dd.

Standard Setup:

# Create a 4GB swap file
fallocate -l 4G /swapfile

# Ensure only root has write access for security
chmod 600 /swapfile

# Make it permanent via fstab
echo " /swapfile none swap defaults 0 0 " >> /etc/fstab

For Btrfs Users: Since Btrfs handles files differently, use the dedicated tool:

btrfs filesystem mkswapfile --size 2G swapfile
swapon swapfile

Reference: Btrfs Swapfile Documentation


⚖️ The Great Swap Debate

The community is divided on this approach. Below is a conceptual map of the arguments:

🚩 The Skeptic's View

@sgbeal sgbeal raises several critical points:

  • Performance: He questions the "20-year" claim and argues that PerformancePartition>PerformanceFile\text{Performance}_{\text{Partition}} > \text{Performance}_{\text{File}}PerformancePartition​>PerformanceFile​ because any filesystem introduces an abstraction layer (and thus a penalty).
  • Necessity: In 30 years of Linux/Solaris admin, he claims he has never rarely needed to resize swap post-install.
  • Hygiene: Partitions are "cleaner" because they don't accidentally get sucked into rsync jobs or system backups.

🚩 The System Architect's View

@DominoTree DominoTree (FreeBSD committer/ZFS contributor) adds technical nuance:

"As long as you're okay with swap becoming available after your filesystems do... there are cases where you might not want that."

Critical Risks:

  1. Boot-time OOM: On memory-constrained systems using Copy-on-Write (CoW) filesystems (which consume RAM), you might hit an Out-Of-Memory (OOM) state before the filesystem is mounted and the swap file becomes available.
  2. Kernel Dumps: In FreeBSD, swap partitions double as kernel dump devices. If a panic occurs before ZFS is online, a swap file is useless for storing the crash dump.

⚠️ The ZFS Warning

@Harvie Harvie and DominoTree highlight a dangerous interaction with ZFS.

FeatureIssueResult
ZFS ARCConsumes massive amounts of RAMHigh memory pressure
ZFS SwapSwapping ZFS pages back into a ZFS-backed fileRecursive Contention→∞\text{Recursive Contention} \rightarrow \inftyRecursive Contention→∞
OutcomeSystem instabilityFreeze or Crash

Note: This can be mitigated with aggressive sysctl tuning, but is dangerous on default settings.


📝 Final Considerations

  • Check your FS: Does it support fallocate?
  • Check your Boot Order: Do you need swap before the root FS mounts?
  • Check your Backups: If using a file, is it excluded from your backup scripts?
  • Check your OS: Are you on FreeBSD or using ZFS?

Other perspectives:

  • @Ludwik900 Ludwik900 suggests ensuring /etc configurations are properly set for system startup.
  • @zenoprax zenoprax notes that you can simply keep an existing swap partition intact even when reinstalling the OS, especially if it's on a separate "DMZ" SSD.
  • @hecvd hecvd agrees with the "sysadmin hygiene" argument regarding backups.