Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

61–70 of 257 posts

Re: Stop making swap partitions—use swap files instead

#61

Remember when distros used complicated partition setups, one for /root, one for /var one for /home, a swap partition etc. Was always a bad choice because one of them would be at 99% while others would linger below 10% For swap, the best advice is to disable swap on your desktop, unless <8GB RAM. Really, I've never needed it and you probably won't either.

I'm not sure if that's a bad choice... BTW, I think STIG still requires it. So, if you want to be compliant with some (US) government requirements, you'd still have to put different bits of your system on different partitions / devices.

Why I'm not sure this is a bad idea: a pathological process that quickly captures the entire allocated disk space will be contained by this layout and will likely not affect the system as a whole. Consider, for example, a process that excessively logs into /var/log: once the filesystem mounted at /var fills up, it might fail / hang, but you will still be able to use stuff from /bin or /sbin. But, if your entire root filesystem fills up, you probably won't be able to run any applications at all.

Re: Stop making swap partitions—use swap files instead

#62

Earlier quoted context omitted.

Is that still the case today? Notably (IIUC) overcommit is required for certain security measures. I believe it was chromium that I noticed mmaping somewhere north of 1 TB of memory on startup so that it can do (again IIUC) something akin to ASLR internally.

On Windows you can achieve something like manual overcommit by calling VirtualAlloc with just MEM_RESERVE. That gives you a continuous space in your process's virtual address space, without actually backing it with any physical pages. Kind of like what a malloc does on linux But where linux would automagically back those pages once you use them, Windows requires you to actually ask for those pages to be backed by som…

At a glance that seems like a much more sensible design. I guess it's dead in the water for posix on account of fork being CoW? This is quite the rabbit hole. I wonder if programming languages ought to be designed in such a way to accommodate a preemptive signal indicating allocation failure in place of a page fault? Rather than malloc returning null or etc.

Re: Stop making swap partitions—use swap files instead

#63

Stop using partitions. Use LVM!

Stop using LVM. Use ZFS! (ZFS might be described as the love child of lvm and btrfs, 'cept ZFS got there first) ( Very briefly: you hand ZFS a stack of disks (in mirrors or raidz groups, for redundancy) and it makes a zpool. Then you carve the pool into datasets as needed. Each dataset looks like an ordinary directory and takes only the space its files actually use, so you never guess partition sizes again. And each…

I'll consider it when zfs in in tree.

Re: Stop making swap partitions—use swap files instead

#65
post #30
post #15

swap files make setting up hibernation a bit more complicated - in most cases the file has to be contiguous, e.g. you have to defragment it once after allocating. Then, you need to tell the bootloader the byte offset of the file on the partition.

If you want to share step-by-step, I’ll update the gist.

That’s my point, it’s different for each distro & partitioning setup, so I wouldn’t know what to share here. Having a swap partition makes it as easy as adding `resume=/dev/sdXYZ` or `resume=UUID=…` to your kernel parameters.

Re: Stop making swap partitions—use swap files instead

#66

Tangential, but does anyone know why in 2026 and on Debian 13, my machine still hangs when some process exhausts RAM? Is there really no higher-priority kernel process to prevent total freeze of the system and send a SIGKILL to the culprit process when such a scenario happens?

This has finally been fixed in the latest Ubuntu version (26), it now force closes the culprit.

How did they fix it?

Re: Stop making swap partitions—use swap files instead

#67
post #15

swap files make setting up hibernation a bit more complicated - in most cases the file has to be contiguous, e.g. you have to defragment it once after allocating. Then, you need to tell the bootloader the byte offset of the file on the partition.

Does contiguousness matter these days? Especially since all disk locations are lies anyway as SSD firmware has its own layer of indirection too?

Re: Stop making swap partitions—use swap files instead

#68
Why use swap files when we could have swap directories? ;-)

Sprite had (IMO) a really interesting solution to swap. Each host had a directory, referenced by its host ID under the `/swap` directory, and inside that directory, individual segments of virtual memory would be saved: https://github.com/OSPreservProject/sprite/blob/master/src/k...

Sprite overcommited memory like a modern OS, and stored segments individually so that process migration worked (if a segment was swapped-out, the path to the swap file would remain the same anywhere on the cluster, so if the process was migrated, you didn't need to swap-in the segment before migration):

  eery@cherimoya [1] > cd /swap
  eery@cherimoya [2] > ls
  1   10 11  12 13  14 15  16 17  2 3   4 5   6 7   8 9
  eery@cherimoya [3] > ls 3
  1    113  129  148  161  172  185  20 218  238  252  33   48  63   77   95
  100  114  130  15   162  173  186  203 219  24   253  34   49  64   8    96
  101  115  132  150  163  174  187  204 22   240  254  36   50  66   80   97
  102  116  133  152  164  175  188  205 221  242  255  38   51  67   81   98
  103  117  134  153  165  176  19   207 222  243  26   39   52  7    82   99
  104  12   135  154  166  177  190  209 225  244  27   4    55  70   85
  105  121  139  155  167  179  191  21 226  246  28   40   56  71   86
  106  122  14   156  168  180  193  210 227  247  29   42   57  72   87
  107  125  140  157  169  181  194  213 23   248  3    44   6  73   9
  11   126  143  158  17  182  197  214 230  249  30   45   60  74   90
  111  127  145  159  170  183  198  215 233  25   31   46   61  75   91
  112  128  146  16   171  184  199  216 237  250  32   47   62  76   92
  eery@cherimoya [4] > ls 5
  82  83
  eery@cherimoya [5] > ls 15
  111  126  14   155  17  181  217  253 4    57   72   86   98
  116  131  141  160  170  19   24   29 47   62   77   9
  121  136  150  165  177  210  25   34 52   67   8    95
  eery@cherimoya [6] > grep cherimoya /etc/spritehosts
  12   pc386   cherimoya.shockfox.net           cherimoya
  eery@cherimoya [7] > ls 12
  eery@cherimoya [8] >

Re: Stop making swap partitions—use swap files instead

#69

Remember when distros used complicated partition setups, one for /root, one for /var one for /home, a swap partition etc. Was always a bad choice because one of them would be at 99% while others would linger below 10% For swap, the best advice is to disable swap on your desktop, unless <8GB RAM. Really, I've never needed it and you probably won't either.

I'm not sure if that's a bad choice... BTW, I think STIG still requires it. So, if you want to be compliant with some (US) government requirements, you'd still have to put different bits of your system on different partitions / devices. Why I'm not sure this is a bad idea: a pathological process that quickly captures the entire allocated disk space will be contained by this layout and will likely not affect the syste…

There are also controls that specify noexec, nodev etc for filesystems.
Post reply on HN