[LG Optimus 2x] orion1208:
Some thoughts/experiments on zram and swapping

My apologies if this has been discussed in this forum before or if this is a bit off-topic, but since my little "experiments" were all done on this CM11 rom, I hope to obtain more relevant feedback by posting the results here.

As we know, this great rom comes with zram with swappiness set at 60 by default. I am happy with these settings but honestly our 2X's ram has become really limited (512MB) compared to the size of the modern apps. So, I have been experimenting with ways to a) improve multitasking performance, i.e., less lags and reloads when changing foreground applications; and b) improve the performance of more memory-intensive applications, e.g., the browsers.

Before I report my little "findings", I assume that i) we use only lightweight applications that should sit happily within the physical ram of our device most of the time. For example, we should use a lightweight browser instead of Chrome, m.facebook.com instead of the official Facebook app, etc; ii) we have frozen (or at least disabled) all unnecessary (executions of) apps and widgets; and iii) we seldom play heavy games on 2X - which might not be applicable to everyone but that is my case where my "experiments" were done with.

Given the above assumptions, I found that the following settings might lead to a bit better user-perceived performance in the above two aspects (a-b).

Disable zram with Trickster MOD Kernel Settings (available in Play Store).

Enable the unused swap partition (~380 MB) by using SwapEnabler.zip provided by pengus77.

Lower swappiness to 20.

My rationale is like this:

Based on assumption (i) that most apps we use are lightweight and should run happily within the RAM most of the time, using zram could actually introduce the (unnecessary) competition between the zram and the physical RAM our apps use, which might lead to some short - but noticeable - lags during the usage of an app and the process of switching foreground apps.

Having said (1), we still need to cater the not-uncommon situations that we really need more RAM than what we have, so we introduce the swap partition.

Since accessing the swap partition on the internal memory is slower than the in-memory zram, we probably want to defer swapping as much as possible, but not until the OOM killer kicks in, hence an arbitrarily-low value of 20 (which is also being used in the V6 Supercharger if I understand correctly).

In essence, the above changes may lead to:

Faster response in "normal" usage since the system is now free from the (de-)compression operations of zram, while all the available physical ram can be used by the apps directly. The effect of more swapping caused by the removal of the zram is hopefully offsetted by the reduction of the swappiness.

Higher penalty in swapping ("disk" vs. zram) but larger swap space (380MB vs. zram), which subsequently leads to slower swapping but possibly a "healthier" system (less chance of processes being killed) when the demand of memory suddenly surges (e.g., too many tabs in browsers, too much multitasking, etc.).

I have applied the above settings for a few days and so far my "impression" is pretty good - not sure if that is placebo effect though.

Disclaimers and call for advices/comments:

I am in no way an experienced Android developer, so please feel free to correct me if there is any misunderstanding in this report.

Using the swap partition can possibly reduce the lifespan of our internal memory.

Depending on your selection of apps and usage pattern, your mileage may vary.

Any corrections, advices, comments, or report of experiences are welcome! :fingers-crossed: