esos wrote: Thu Mar 14, 2024 11:14 pm
And zram is better than having no swap at all
How to setup and use zram?
Do you think zram can run efficient while you have only 4Gb of ram.
Thanks.
Under Fatdog (your pup may vary) for creating/using zram file ...
Code: Select all
modprobe zram # load module (creates /sys/block/zramX folder and content)
#show supported compression algorithms
cat /sys/block/zram0/comp_algorithm
lzo [lz4]
#opt to use lz4 compression algorithm
echo lz4 > /sys/block/zram0/comp_algorithm
echo 1G > /sys/block/zram0/disksize # no more than 2x memory size as pointless
mkfs.ext2 /dev/zram0
mkdir /xxx
mount /dev/zram0 /xxx
For creating it as swap you'd use mkswap/swapon ...etc. instead of mkfs.ext2/mount
Be mindful however that using zram, or encrypted swap, adds the additional overhead of having to compress/decompress (encrypt/decrypt). May very well not resolve the issue, rather just prolong things a bit longer before a massive slow-down/lock-up occurs.
If you're OK with leaving a forensic trail, then a straight swap file, not encrypted, on HDD can work OK and resize your save/tmp areas to use that. But that is more for a case of where you have save on demand, and generally don't save changes. Which is little different to that of repointing save/tmp to be on HDD rather than in ram i.e. 'problems' can be resolved by re-configuration rather than adopting zram or encrypted swap. For many that may be as simple as moving your browser cache and download folders to be on HDD rather than in ram. For others such as doing large video edits, move the temp/work folders to be on HDD ...etc.
I run a Fatdog usb boot as one of my choices, but with forensics in mind, not leaving a footprint on 'foreign' host cpu/system. Even though my radeon grabs 600MB for vram, leaving just 3.4GB ram (that Linux typically halves that amount as being the available 'free' ram), that is still more than enough for typical usage where fatdog main sfs and changes are loaded into and run from ram, as are potential changes (that I don't actually save) recorded in ram.
If you are tight on space, then don't copy sfs's into ram, leave them on disk and blocks will be read into/ejected from ram/cache by the system. The times that fails is when there's too much 'current' data required and insufficient ram/cache space to accommodate that i.e. you're asking too much of the available hardware/resources. Or when the configuration isn't appropriate, such as attempting to edit a large video where the actual and temp files are being fully kept in ram.
a.k.a. with 4GB I suspect you can run things better without either swap or zram as neither will totally eliminate the risk of a slow-down/lock-up. If you do need to do 'big things' on foreign systems where you don't want to leave evidence (private data that others could potentially see after you'd used/left that system) then a portable usb/ssd device is the more appropriate over a usb flash-stick. In which case a straight non-compressed swap or re-pointing the 'ram' based save area to be on the ssd instead works fine. Or even if you don't want to preserve changes, make a copy of the current save file/folder before bootup, run with changes being stored into a new version of the save file/folder, and then ditch that to restore the original save file/folder - so as though no changes were saved.
In my case Fatdog main sfs is around 450MB (xz high compressed, over 2GB of actual data), in addition to that another save/changes sfs is around 20MB (my reconfiguration of Fatdog for locale/looks etc.), I also have a chrome sfs that is around 130MB, so in total, 600MB of compressed sfs data copied into ram at bootup. A further 600MB of the 4GB ram is allocated by Radeon as vram, leaving 3.4GB, of which LInux in effect halves that down to 1.7GB. With 600MB in sfs form, that leaves around 1.1GB of free ram initially. Linux works fine with that, will page/cache things in/out fine. The only time it becomes a issue is if that 1.1GB is used up by single files or browser cache ...etc. that with a bit of configuration/application of thought ... can largely if not totally avoided. Whist with all sfs's in ram, the system runs (very) quick. To free up more ram I could leave the sfs's on disk, but in my case the disk is a old mechanical one and its very slow to spin-up/use, so for operational reasons I prefer my sfs's in ram. But that is somewhat wasteful, as for light usage in effect I have the sfs copy of files copied into ram, and then the cached copy of files also being copied into/remaining in cache, but if things work fine that way that's not really a issue, and if the system needs the cached space then it dumps that so that the next read of a file within a sfs has to be decompressed/copied back into cache again if/when needed.