HN
Today

Stop making swap partitions–use swap files instead

This Gist contends that swap files are superior to swap partitions, offering comparable performance for decades while providing greater flexibility post-installation. The discussion on Hacker News delves into the nuanced caveats of this advice, exploring issues like hibernation, specific filesystem interactions, and the perennial problem of Linux's Out-Of-Memory killer. It’s a classic HN debate on optimizing fundamental system architecture.

34
Score
28
Comments
#6
Highest Rank
3h
on Front Page
First Seen
Sep 11, 7:00 AM
Last Seen
Sep 11, 9:00 AM
Rank Over Time
16186

The Lowdown

The author argues passionately that Linux users should abandon traditional swap partitions in favor of swap files, claiming they offer equivalent performance and vastly superior flexibility.

  • Historical Parity: States that swap files have matched swap partition performance for over two decades, citing a 2005 LKML discussion.
  • Flexibility: Highlights the ease with which swap files can be created, added, removed, modified, or extended after initial system installation, contrasting with the fixed nature of partitions.
  • Installer Critique: Calls out Linux distributions for continuing to recommend swap partitions during installation, despite the advantages of swap files.
  • Implementation Guide: Provides a concise, step-by-step guide using fallocate (preferred over dd for speed on supported filesystems), chmod, mkswap, swapon, and fstab to set up a persistent swap file. The piece serves as a modern, practical guide for managing virtual memory on Linux, advocating for a more adaptable approach.

The Gossip

Hibernation Headaches

Many users point out that swap files significantly complicate hibernation setup, often requiring contiguous files and specific bootloader configurations. While some observe macOS handles swap files and hibernation seamlessly, others note this is due to deep hardware/software integration (e.g., TPM), which Linux typically lacks without custom configuration.

Filesystem Frictions & Performance Factors

The discussion quickly clarifies that swap file performance isn't universally identical to partitions. Fragmentation can introduce overhead, especially on older filesystems or HDDs where placement (outer vs. inner tracks) matters. Specific warnings are raised for BTRFS and ZFS, where swap files are explicitly discouraged or have complex requirements. The static nature of Linux swap files, unlike some dynamically resizing OSes, is also highlighted.

Out-Of-Memory Outbursts

A significant sub-thread tackles the notorious problem of Linux systems freezing when RAM is exhausted. This is attributed to kernel overcommit policies and the OOM killer's late-stage intervention, which often prefers thrashing over killing processes. Commenters share various solutions, including adjusting kernel parameters (`lru_gen/min_ttl_ms`), using user-space OOM daemons like `earlyoom` or `systemd-oomd`, and `ulimit` for specific processes, though these tools come with their own complexities and potential pitfalls.