4 ms·
Fwiw I no longer use disk swap files for anything, but ZRAM swap instead. It's mature, it's in the linux kernel, it's faster, and less wearing on SSDs, and RAM
by SkyMarshal 4y ago
Fwiw I no longer use disk swap files for anything, but ZRAM swap instead. It's mature, it's in the linux kernel, it's faster, and less wearing on SSDs, and RAM is cheap. I don't have a linux laptop though, so don't know how it affects hibernation. Anyone know how/if hibernation works on a laptop using ZRAM swap instead of disk-based swap?
- jeroenhd 4y agoHibernation requires a copy of your RAM to be stored on disk. Compressed RAM alone can be used with traditional sleep mode, but hibernation won't work. That said, you can combine ZRAM and swap files/partitions. You need to make sure the priorities are in the right order, though, and maybe you need to script your system to disable and flush zram to swap on hibernate and enable it again on resume, but that way you can do hibernation together with ZRAM.
- KingMachiavelli 4y agoZRAM is amazing for cloud VMs which typically have strict disk IOPS limits which means any significant swap usage is going to destroy IO performance or even lock the system. ZRAM w/o swap completely prevents this IO condition and is much faster than disk swap anyway.
- fathyb 4y agoShouldn't a cloud VM have swap disabled by default if it's using networked block storage? It is on AWS at least.
- ElectricalUnion 4y agoAzure provides what they call "Azure Temporary disk" at typically /dev/sdb for most instance sizes; it's *not encrypted* and it's ephemeral, but is garanteed to be co-located (at least rack-level) with your CPUs.
- yabones 4y agoLinux generally gets very squirrely when it's in a low-memory state. I think it's a bit safer to turn swappiness down and use a small swapfile and/or zram just to keep it from getting completely bricked up. That way you're sacrificing IO for a few seconds/minutes to intervene.
- Dylan16807 4y agoRAM is pretty cheap but it's not free and not always possible to upgrade, and my personal computers keep ending up with gigabytes of data in memory that won't be touched for hours or ever. I'm happy spending a negligible amount of SSD lifetime to clear up that space.
- pkulak 4y agoSeems silly to set aside ram to use when your ram runs out. What am I missing here?
- chronogram 4y agoYou don't set it aside, unused pages just get compressed to save space.
- pkulak 4y agoOkay, I think I don't know how swap works on Linux. Is it: When there's no more ram, swap is used or When ram hasn't been used in a while, it is sent to swap Or maybe a mix of both?
- chronogram 4y agoBoth, yes. The second one depends on your configuration, and your configuration depends on your hardware and your use-case. For example I have some 4GiB VPSs with a single vCPU and slow IO, so I configure the virtual memory to aggressively compress unused ram with lz4; decompressing them takes no CPU power and is orders higher throughput and lower latency than any disk swap can ever be, even when using just 1 vCPU. Then it means I have gigabytes of RAM that is used as file cache, instead of wasting that space with unused ram, and when everything is needed at the same time it just drops the cache. Having all that cache availability also means that it can take in a lot of files without locking up. The first one also happens when you have too much RAM allocated for your things. When it's temporary until your applications finish it'll swap around and slowly finish eventually, but depending on your over-allocation and your swap's speed it can take significantly longer.
- rhn_mk1 4y agoRepeat after me: ZRAM is not swap. ZRAM uses the same OS interface as swap does, and that interface is called "swap" but really is more about composing system memory out of tiered backing memory. One of those tiers can be swap. With ZRAM and no swap, all your system memory is volatile. As long as Linux requires nonvolatile system memory to hibernate, it will be impossible to hibernate in this setup.
- _piif 4y agoSame here. I was using zswap at one point merely for hibernation but got tired of the dice roll on whether my system would wake up, would wake up but with locked up graphics, would show me a black screen, would show me a blinking cursor or would kernel panic (on my hardware with an Intel iGPU at least). I just gave up on hibernation altogether and been happily using zram ever since.
- deleted 4y ago[deleted]