4 ms·
Two examples of why I have swap: * On a laptop to hibernate, which results in zero power consumption vs suspend which will drain the battery in a day or so *
by rogerbinns 10y ago
Two examples of why I have swap:
* On a laptop to hibernate, which results in zero power consumption vs suspend which will drain the battery in a day or so
* I use tmpfs for /tmp and using swap as the backing is far more performant than regular filesystems
- lmm 10y ago> * I use tmpfs for /tmp and using swap as the backing is far more performant than regular filesystems This seems absurd. You're running an in-memory filesystem backed by memory-on-disk? You weren't comparing to a journalled filesystem or something like that?
- rogerbinns 10y agoSince I do use journalled filesystems for my real data, your comment implies I should create yet another partition for /tmp using a filesystem that optimises performance over durability/integrity, eg without journalling. I consider files in /tmp to be temporary, and do not expect them to survive a reboot. (Actually I prefer they don't - less administration and housekeeping.) They also have random lifetimes ranging from fractions of a second to several days. And random sizes from zero length to gigabytes (eg making an ISO image). With tmpfs RAM is used which provides the best performance since the filesystem is trivial. Memory pressure will cause swap to be used as needed. Files not accessed will end up in the swap and taking no RAM. By far the fastest I/O is the I/O you don't have to perform.
- lmm 10y ago> Since I do use journalled filesystems for my real data, your comment implies I should create yet another partition for /tmp using a filesystem that optimises performance over durability/integrity, eg without journalling. If you're using a swap partition just for the sake of /tmp then it's the same difference, no?
- rogerbinns 10y ago> If you're using a swap partition just for the sake of /tmp then it's the same difference, no? No. The big difference is that regular filesystems try to do I/O to their backing device - heck that is their point, and what they do the vast majority of the time. tmpfs does not do any I/O. However I/O will happen when there is memory pressure by the swapper, but that is going to be rarer. ie with tmpfs, swap is a spillover mechanism. With a regular filesystem, the underlying device is the primary mechanism. Swap can also be used for actual swap on the occasions it is helpful.
- lmm 10y ago> No. The big difference is that regular filesystems try to do I/O to their backing device - heck that is their point, and what they do the vast majority of the time. tmpfs does not do any I/O. However I/O will happen when there is memory pressure by the swapper, but that is going to be rarer. Yes and no - aren't they just two ways of looking at the same decision? Regular filesystems will buffer, and when the system is low on memory it will flush buffers, using similar criteria to deciding whether to swap. > Swap can also be used for actual swap on the occasions it is helpful. Swap enables actual swap, sure. My experience is that it usually hurts more than it helps though.
- rogerbinns 10y ago> ... Regular filesystems will buffer, and when the system is low on memory it will flush buffers ... That is the bit you are missing. Unwritten filesystem data is regularly flushed. The flush interval is often around 5 seconds. Lookup "pdflush" to get the gist, although things have changed since then. Same with laptop mode. Quite simply if a file is created and lives for at least N seconds then there will be disk activity irrespective of memory pressure. N is 5, perhaps up to 30 seconds in normal use. Even if the file contents aren't fully flushed, metadata is.
- pvdebbe 10y agoReminds me of a youngster who thought he could beat the system by putting the swap file to a ramdisk drive.
- 77pt77 10y ago> On a laptop to hibernate, which results in zero power consumption vs suspend which will drain the battery in a day or so Swap is not strictly needed for this: (it boils down to vm.swappiness=1) https://wiki.debian.org/Hibernation/Hibernate_Without_Swap_Partition https://wiki.debian.org/Hibernation/Hibernate_Without_Swap_P...
- Spivak 10y agoYou still need swap, just not a swap partition. I suppose we can debate if there's a meaningful difference between the two.
- 77pt77 10y agoI could swear there was a way around that but I don't remember the details and can't find them. Still, it's possible to hibernate without having the drawbacks people have been complaining about in this thread.
- rogerbinns 10y agoI have an encrypted swap partition. Hibernation works well with that. I don't believe it is possible with a swap file since the containing filesystem would also be mounted by the hibernation image.
- 77pt77 10y ago> I don't believe it is possible with a swap file since the containing filesystem would also be mounted by the hibernation image. for sure it is. Even for swap files inside an encrypted volume. https://vadim-kirilchuk-linux.blogspot.com/2013/05/swap-file-for-hibernation.html https://vadim-kirilchuk-linux.blogspot.com/2013/05/swap-file... The crux is knowing the swap-file offset and passing that argument as resume_offset on boot. Have a look. It's totally doable and you won't need to have an actual partition.
- rogerbinns 10y agoI never realised the swap header on files also provides enough information to locate the other blocks without going through the filesystem. Logical I guess. This is however more work that "works out of the box" swap partitions.