HN Simulatornew | past | comments | lists | submitlogin

How does a swap file vs swap partition change things in OOM situations?


As @mitxela says, if you need to fault in a page which is needed for some critical OS function, which requires going through the VFS layer, and that requires paging in another page, which has been swapped out due to memory pressure ... There are many edge cases.

Swap on primary partitions also complicates dump and restore, although hardly anyone seems to know what backups are now.


See, the thing is that swapping or paging to a file does not use the VFS layer, except when activating or deactivating it. So swapfiles may not be materially different from swap partitions during operations.

https://utcc.utoronto.ca/~cks/space/blog/linux/HowSwapFindsB...

And there are many things that complicate dump and restore. Dump and restore often need to account for what partitions were created, anyway, so don't swap partitions also complicate it?

https://utcc.utoronto.ca/~cks/space/blog/sysadmin/SwapfileAn...


The swap files do use a non+VFS path after setup in 2.6+ kernels, but it is complex and has had bugs:

https://lkml.iu.edu/hypermail/linux/kernel/2103.0/06524.html

The bug is in here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

This was 2021, and while this bug is fixed, maybe take Linus's advice. Rely on a partition for primary swap, and only add files if you need to. Don't put them on the root partition, preferably a second disk.

I can't resolve your links but this is a good reference: https://kernel-internals.org/mm/swapping/

Normally dump skips swap partitions entirely, and doesn't know anything about partitioning. Swap will refuse to activate on a non-mkswap partition so there is reasonable protection when you're migrating.


BTW you can swap over NFS and iSCSI with swap files, with NFSoIB, or use the Infiniswap modules:

https://github.com/SymbioticLab/Infiniswap

Great hack for when you have a massive working set but don't want to rewrite the code to be distributed/parallel.


One traditional reason to prefer a swap partition was that the filesystem driver might have to allocate memory. I think swap files bypass the filesystem driver, though - getting the block extents and then accessing the block device at those locations, instead of accessing the file.




Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: