What do you guys think of zram? Anyone use it?
What do you guys think of zram? I currently have no swap partition or swap partition and use btrfs for the root filesystem. I only have 8 GB of RAM and the only time I fill it up is downloading one or two youtube videos to the RAM's tmpfs for faster seeking and prevent disk usage. I am also considering compiling code and/or AUR packages on it.
As far as I know, zram simply means things that would otherwise be swapped out to disk are compressed and stored in RAM, so it is faster than a traditional swap partition because RAM is naturally faster than disks and compression means more efficient use of space. This is done at the cost of some CPU resources.
I'm thinking of using zram in my scenario. In what situations would zram not be preferable? Only when it's never filled, thus trading CPU resources and compressing for nothing?
About this post
- Posted
- Archived
- Score
- 46 · 100% up
- Kind
- Text
- ID
- 754cxt
38 comments
Zram looks like a cool technical solution, but it's inferior to simply buying more ram. I got 16GB and including buffer cache I'm not even using 2GB.
Forget tmpfs for anything but /tmp. The last time I checked it made zero difference over magnetic disks assuming you have enough ram to buffer cache your working files. Literally zero speed difference, test it yourself.
Just buy more ram, it's cheap and it really is the best way to speed up a UNIX system.
Agreed zram isnt a replacement for ram if your machine is heavily loaded but for an office machine it's fine.
Using spare ram for /tmpfs is good for reducing SSD writes and does speed some actions up such as loading browser profiles in ram all the time.
If only my craptop took more than 8 GB ...
Consumer electronics is basically disposable. You could always replace it. But 8GB should leave you 4 to 6GB for buffer cache anyway.
Use it on an RPI to help with the RAM limitation. Completely makes a difference when under heavy load.
I may try this, I'm running arch on three rpis and an having some performance issues on one. Any advice or stuff to watch out for when doing this?
Focus more on CPU time than RAM usage when configuring. So avoid very dense compression as it will eat a LOT of CPU time and make it almost pointless to use.
EDIT: On average, I save about 200~300MB when compiling a Linux kernel.
I have 8GB of RAM and the only time I even come close to running out is when I'm running multiple Windows VMs or something. Under a typical workload (which consists of a browser, Sublime Text, Hexchat, and a couple terminals under i3wm) I never use more than 1.5GB. And most of that is taken up by Firefuck.
I have a 2GB swapfile on my SSD and an
ohfuckalias to turn it on, but I never use it.I use a minimum of 6GB with Chrome alone. How in the world are you staying under 2GB?
Chrome might be the problem. On multi-process Firefox with about 60 tabs open I'm using <800 MB ram on my 8 GB ram laptop.
How many extensions and tabs are you running?
Deleted before we saved it.
How much ram do you have? Chrome usually has a tendency to blow up usage if it detects you have lots of ram.
By not using Chrome. Shit takes up more memory than a default Windows install at times... its probably ~3-5 of your 6 GB. Hell, I remember hitting OOM before running nothing but I3 & Chromium. Meanwhile firefox has never gone above 2 GB for me. & that was with hundreds of tabs in multi process.
mine is
shitshitshitThat's funny because i have a script called ohshit that kills the most consuming process for when pc starts swapping into oblivion.
In a similar situation, I added actual swap and then enabled the "zswap" module. This "zswap" uses a somewhat similar idea as swap in zram. It compresses memory pages and stores them in a cache inside RAM, trying to avoid the use of the actual swap on disk. The size of its compressed memory cache inside RAM is dynamic. It changes the size of that cache completely by itself so there's no need to tweak anything. You just enable it on the kernel command line:
Its problem is that it needs actual swap.
The only tweak for it is to switch to lz4 compression for faster compression/decompression:
Using lz4 needs a change to /etc/mkinitcpio.conf to add the lz4 modules to the initramfs:
and then running
sudo mkinitcpio -Pto recreate the initramfs files.About using /tmp for makepkg, I remember I ran out of space sometimes with the default settings on an 8GB machine. The default size is half of your RAM. I don't remember what packages I had problems with. It might have been the kernel package and Firefox.
I increased the size of /tmp by creating a file to override the "Options=" line you see in the output of
systemctl cat tmp.mount:This can also be done by adding an entry for /tmp to /etc/fstab. This /tmp size increase is why I decided to add a swap partition.
Another thing, if you use
makepkg -cC, it will remove the files for a package in /tmp before and after it's done compiling. That helps to not forget garbage in there eating your RAM.Why you override file system rights these way? Is the defaults have an issue here? I just added the following line to my /etc/fstab and it have same but without 1777 and strictatime
I use zswap too but don't touch compression leaving it to defaults. Actually with 8Gigs of RAM whatever system you use it never been touched by anyway. So it pretty much rare use cases and can be disabled after all cause it not giving any performance.
The default is a 4GB limit when you have 8GB RAM. I ran out of space in /tmp sometimes. I needed a /tmp that can hold more than 4GB.
There's no real reason I used that override.conf file instead of a line in /etc/fstab. Both methods work. Those "mode=1777", etc. settings are there just because I saw those settings in the output of
systemctl cat tmp.mount. It's not possible to add text to a line from the original config with an override config, so I copied the whole original line and added my "size=8G" to it.Swap did get used for me occasionally with 8GB RAM. It happened with VMs running and the web browser using a lot of memory, or when experimenting with something in /tmp.
I use zram extensively for high IO transient databases. Works great, many times faster than spinning disk or SSD, and doesn't cause any wear to the permanent storage.
I wrote an application that's actually a set of programs that does data analysis on a highly transient data set. It collects hundreds of data points on thousands of items every second, then separate programs run various models against the data, and then the data is deleted. Any particular dataset will only exist for 15 to 30 seconds. It's all random IO and done by multiple uncoordinated programs.
It's thousands of IOPS a second all day long, with only the results being saved.
Frankly, doing this with a hard drive or SSD would be impossible, and unadvisable.
I've removed my swap partition and now I use 2x zram on Acer Chromebook C720. Makes a world of difference with that little bit of ram. I recommend if you have less than 4G
How cpu intensive is it? I have a notebook with 1.25GB RAM(maxed capacity), and a Pentium M 1GHz. I'm guessing the CPU would be the bigger bottleneck, but I'd try anything to stretch this device a bit further.
Deleted before we saved it.
works fine for me T61/2GB ram 2ghz c2d - so overhead on any modern cpu should be minimal.
id say there is use cases out there that make it useful but anytime i have ever tried it, i have never noticed a performance difference. i dont buy/build machines with less than 16gb of ram these days though so theres that.