Replacing zram with zswap

asked 2015-01-05 16:03:30 +0200

bulkin gravatar image

Update10 introduced some questionable memory-management adjustments. First of all, zram is not meant to be used in conjunction with a permament memory based swap, as that leads to LRU inversion: older pages get into the higher-priority zram and quickly fill it, while newer pages are swapped in and out of the slower emmc-based swap, so all the advantages of zram are lost and almost 100 MB of RAM are simply wasted. Another issue is the decreased swapiness value: the lowmemory killer kicks in earlier leading to user applictions being killed quite often and sometimes unexpectedly.

Even just disabling zram, decreasing lowmemorykiller minfree values and increasing swapiness leads to an overall usability improvement.

edit retag flag offensive close delete

Comments

Which minfree and swappiness values have you found best after disabling zram?

synthent ( 2015-01-10 18:40:58 +0200 )edit

I've used 1024,2048,4096,6144,8192 for minfree and 60 for swapiness, but you probably can set minfree to all zeroes without any adverse effects.

bulkin ( 2015-02-01 17:05:51 +0200 )edit

On the contrary I see swap in zram quite useful. I have increased zram swap size from default 13% to 33% and really rarely see that swapped data does not fit in zram swap. Here is typical output of my stats script which calculates some aggregate statistics of zram swap devices.

$ ./zram_swap_stats.lua
compr_data_size:            42455.51 KiB
mem_used_total:             48428 KiB
orig_data_size:             130700 KiB
zero_pages:                 10104 KiB
disksize:                   274136 KiB

notify_free:                22460
num_reads:                  52248
num_writes:                 57661

SwapCached:                 41648 KiB
Memory saved:               50728 KiB
Compression:                0.32
Compression with overhead:  0.37
Used:                       51.36%

The most interesting line is "Memory saved" which displays estimate if freed memory by swap in zram. It is calculated as:

orig_data_size(non-zero swapped pages) + zero_pages(zero pages swapped) - mem_used_total(by zram) - SwapCached(cached in RAM swap contents)

~50MB RAM gained. Not bad. In tight memory conditions when SwapCached becomes low and swap in zram becomes more filled space gained might be more than 100MB.

Self-Perfection ( 2015-02-04 18:30:05 +0200 )edit

Judging by your num_reads, the device uptime is less than a day and you haven't used it very much. Here is the output of you script after 2 weeks of light to regular smartphone usage: http://pastebin.com/DXdBFxyF . Zram is filled completely:

[root@Jolla ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/mmcblk0p24                        partition       520180  115480  -1
/dev/zram0                              partition       124604  121388  100
/dev/zram1                              partition       124604  122192  100

while free reports 36 MB free and 114 MB cached. And this is with only settings, messaging and omweather open. If I browse a bit, something will surely be killed by the OOM-killer.

Anyway, my feature request is not about reverting to how things were, it is about improving the current situation.

bulkin ( 2015-02-04 18:56:03 +0200 )edit
1

When I posted my previous comment uptime of my phone was almost two days.

I have a feeling that lipstick leaks memory over time and lipstick is probably the reason of high swap usage on your device. I have never got patience to let lipstick run for more than several days because after a couple of days lipstick starts to constantly use CPU.

Please, post output of following command:

pmap -d `pgrep ^lipstick$` | tail -1; ps -FC lipstick

and try to restart lipstick:

$ systemctl --user restart lipstick

I believe that after restarting lipstick your swap usage would drop below 100MB.

Just in case: pmap requires root. Restarting lipstick stop all GUI apps.

Self-Perfection ( 2015-02-05 13:12:13 +0200 )edit