Using zram & zswap

Although I have 9GB of RAM and 8GB of SWAP, I still feel like I run out of memory too quickly sometimes, while I still like to keep everything optimal in general. So I was wondering about two Kernel features I heard of a while ago, called zram and zswap. It’s said they compress all data on the RAM and SWAP, reducing memory usage at a potential cost of speed. Also that they target inode / dentry caches specifically, which is what annoys me most on Linux… since accessing too many directories on a drive fills the memory with whole GB of data. I use the official Kernel in openSUSE 13.1, which is currently 3.11.10.

My first question was how to best enable them on openSUSE, since google didn’t help me a lot here. Do I use sysctl, do I add a boot flag in grub2, or something else?

Otherwise I was wondering if they are stable, and if there’s any risk in using them. Such as the system freezing, or even worse data on the drive getting corrupted. Are these features fully safe?

zram is just a compressed ram disk - if you are running out of memory, you are running out of memory and that’s that :stuck_out_tongue:

However it would be interesting to know what you use over 9GB for - unless you are running heavy VM or video/audio editing.

I have a systemd service for zram…openSUSE Software

More info here: Package of the day - systemd-zram-service - Open Chat - openSUSE Forums

Sure, that makes sense. Although I’m not fully clear what a compressed RAM disk means. Does it simply mean that all RAM is mounted as a compressed partition? That would make most sense, but just asking to be sure.

Like I said, the Kernel uses up a lot of RAM when I access large folders. At startup my system uses about 1.8 GB, and after a few days of uptime it slowly goes as far as 3.6 GB. I work with video and animation software such as Blender, and also a few high-end Linux games. So sometimes, I do get up to 6 GB used at best.

You still have over 3 gig and have not touched swap. A RAM disk is just that an emulation of a disk in ram. A ram disk is used on the initial of loading of things. Can be used for anything you would use a real disk for but it goes away when you lose power.It is not used as RAM it is used as a disk might be.

I see. I thought zram meant the entire RAM (not SWAP) is mounted as compressed. Same way BTRFS partitions can be mounted with a compression flag, so everything you put on that partition is automatically compressed… of course in regard to RAM in this case.

Either way, it seems that what I’m looking for is currently called compcache. It’s in Kernel 3.14 that this is replaced by zram, which is said to be a better version. The official openSUSE repositories have a compcache package, which is said to enable memory compression.

Do I simply install that package, or do I need to configure anything else? And once Kernel 3.14 is in, will that be replaced by newer zram system? Is it best to wait until then?

There seems to be a bit of misinformation or at least miscommunication in this thread.

First off - ‘ZRam,’ formerly known as compcache, is a compressed ram disk - that is to say, it creates a virtual block device, which can be used for ‘storage’ - but is backed by RAM. One of the uses for this is as “swap” for a system that doesn’t have a physical swap device - such as an embedded system, or a system with a limited-write-life SSD / flash memory. (zram is used in some editions of Android, to shoehorn more functionality into older phones by kinda-sorta providing more total memory without needting to kill the flash storage with swap).

ZRam comes at a performance cost, of course - the act of compressing (and decompressing) data as it goes into and out of ‘swap’ (again, actually a block of RAM) uses CPU - and sometimes it may not actually compress down all that well.

ZSwap is similar, but it’s designed around being used on a system that DOES have a physical swap partition / file / whatever backing it. Per the Arch wiki, “zswap is a compressed RAM cache for swap devices.” So, you get another tier between main memory and swap - which is ‘compressed cache.’ (This is funny to me, given the former name of ZRam being compcache)

Now, what I used - for a while - was ZRam as a swap device, higher priority than my ‘normal’ swap device - but as you can read on the link below, this is actually not optimal, as it seems that the priority system isn’t intelligent enough to keep the ‘most recently / frequently used’ data in the highest-priority swap. Instead, once the ‘fast, zram swap’ gets used up, anything new will get written to the disk / secondary swap, regardless of which data / pages need to be read/written more often.

There’s a surprisingly good breakdown of this over on AskUb____.

I haven’t actually tested out ZSwap, but it seems like it would be a better option for a “normal” system. That being said, this user’s review of performance over on Ubuntu 13.10 seemed to be sub-optimal - actually worsening overall performance - but he or she was using an artificially small memory size (1GB) for testing, which I suspect makes a pretty big difference.

The long and the short of this is that ZSwap and ZRam will both make use of CPU time / processing power to ‘shrink’ your memory pages, in one way or another.

And, really, if you’re not hitting swap all that often, none of these will probably make much of a difference! I’m currently of the ‘decrease swappiness and use an SSD for most of your applications’ school of thought. Less swappiness means less of your memory will be free for disk cache, but while cache is great, if your disk is a nice fast SSD, that’s not going to be as much of a problem / benefit, IMO.

But, your mileage will totally vary depending on what type of load you’ve got on your system!

Also, please remember to check your disk schedulers - I don’t know where openSUSE is in terms of CFQ/NOOP/DEADLINE autoselecting appropriately, but use the latter two on your VMs, and probably also for systems using SSDs!

OK this is an old thread so may not be relevant any more.

SLES 12 can use “zswap” which is a compressed memory backed cache that sits between main ram and swap (e.g. it “goes through” this cache first).

In most cases, it can actually reduce the amount of I/O that eventually gets written to swap and in my limited testing has been beneficial.

It’s enabled by adding the “zswap.enabled=1” kernel parameter (Ysast2 bootloader &) and is listed as an option in the “official” SLES 12 release notes ( ).

I hope someone finds this useful.


This is a openSUSE board and not SLES board. So this advise may or may not apply

Good point, yes it’s also working in openSUSE, I have it running in Tumbleweed (same basic instructions)