Compcache

(How to enable compcache)
m ("Coronary", "diminished user sexual functions" and "watchdog barks" where hilarious, but out of place =))
 
(5 intermediate revisions not shown)
Line 1: Line 1:
-
Compcache or Ramzswap, hitherto referred as ramz is a method for taking a chunk of 'normal' ram and using it as a compressed virtual memory(VM) swap space.  That is, we use ram as virtual virtual ram by compressing the contents on the fly and storing it in ram. This is in order to squeeze as much space from the limited ram as possible.
+
Compcache or Ramzswap, hitherto referred as ramz is a method for taking a chunk of 'normal' RAM and using it as a compressed virtual memory (VM) swap space.  That is, we use RAM as a sort of a virtual, virtual RAM by compressing the contents on the fly and storing it in RAM that's marked up as a swap device. This is in order to squeeze as much space from the limited RAM as possible. A swap device created from compressed RAM is many times faster than a regular swap device using hard drives or traditional flash memory.
Line 9: Line 9:
Apparently compcache is the single greatest thing to ever happen to the N8x0.
Apparently compcache is the single greatest thing to ever happen to the N8x0.
<br>
<br>
 +
 +
=== N900 ===
=== N900 ===
Line 14: Line 16:
====The problem====
====The problem====
----
----
-
Lack of ram is seen as one on the main performance bottlenecks an N900 user has to contend with. In it's stock set up the N900 is prone to having massive swap space coronary. This can leads to poor performance, diminished user sexual function and in the worst cases, a reboot due to watchdog timers becoming ignored. This is generally alleviated in 1 of 4 ways.
+
Lack of RAM is considered one on the main performance bottlenecks a N900 user has to contend with. In its stock set-up, the N900 is prone to having massive swapping after even short periods of heavy use. This leads to poor performance, and in the worst cases, a reboot. This is generally alleviated in one or several of four ways.
-
 
+
==== The solutions====
==== The solutions====
----
----
-
=====Install 'swappolube'=====
+
=====Install 'Swappolube'=====
-
[[Swappolube]] is a set of VM tweaks initially dreamed up by the user Hawaii. For MOST users the installation of swappolube from the repositories and applying the default settings will suffice to alleviate the problem.
+
[[Swappolube]] (sic) is a set of VM parameter tweaks initially dreamt up by the user Hawaii. For MOST users, the installation of Swappolube from the repositories and applying the default settings will suffice to alleviate the problem.
Line 36: Line 37:
-
It has been found that as the swap space fills up the OS is unable to allocate continuous space on the swap space. This leads to poor performance. The package [[ereswap]] was created to alleviate this.
+
It has been found that as the swap space fills up, the OS is eventually more and more unable to allocate continuous space on the swap device. This leads to poor performance, that can be periodically reset by turning the swapping device off and on again, clearing the slate. The package [[ereswap]] was created to make this easy.
Line 43: Line 44:
-
The articles namesake.  The use of compcache has been a contentious issue.  Most users have found it to cause extremely poor system performance. As soon as the ramz space gets filled, which is pretty quick, the system grinds to a slow crawl.
+
The article's namesake.  The use of compcache has been a contentious issue.  Most users have found it to cause extremely poor system performance. For many users, as soon as the ramz space gets full - which is pretty quick, considering it's only tens of megabytes large - the system grinds to a slow crawl.
 +
 
 +
Some empirical and anecdotal evidence suggests that the 'extreme' swap-retention settings of swappolube (that most users run) are highly unsuitable ramz.  Swappolube sets the VM to swap as rarely as possible. This does not work for ramz - likely, an opposite approach must be taken: The device must swap a lot. As in this scenario the swapping is optimally mostly done to the RAM swap device, there will be little penalty in speed.
-
It has been suggested that by some users that the 'extreme' settings of swappolube that most users run are utterly wrong for ramz.  Swappolube sets the VM to swap little bits rarely.  This does not work for ramz.  The opposite approach for ramz must be taken, the device must swap a lot, all the time.  As the swapping is to ram, there will be little penalty in speed.  Although it has been suggested that there will perhaps be a slight penalty in processor use (de/compression of ramz) and thus battery life.
 
====Using compcache====
====Using compcache====
----
----
<br>
<br>
 +
'''''Caveats!'''''
'''''Caveats!'''''
-
*While ramz does work on kernel power version 49 (KP49) it is highly recommended that you use KP50!
+
*While ramz does work on kernel power version 49 (KP49), it is highly recommended that you use KP50!
*Ramz requires a disksize that is specified in KB in powers of 2.  Acceptable sizes are:
*Ramz requires a disksize that is specified in KB in powers of 2.  Acceptable sizes are:
Line 78: Line 81:
|65536
|65536
|64MB
|64MB
 +
|-
 +
|98304
 +
|96MB
|-
|-
|131072
|131072
Line 85: Line 91:
</div>
</div>
-
*It is recommended that you use 64MB
+
*It is recommended that you do not use more than 64MB for ramz.
-
*You MUST have swap enabled on a physical disk before enabling ramz or your n900 WILL insta-crash potentially taking your file system with it!
+
*Unless enabled very early in the device boot, you MUST have swap enabled on a physical disk before enabling ramz, or your n900 WILL insta-crash and reboot, potentially corrupting your file system!
 +
 
 +
*Due to the CPU load slightly increased by the de/compression done by ramz, using ramz likely incurs a slight penalty in battery life.
 +
 
 +
*''Compcache is still considered experimental! It may not work, asplode your n900 and rip your *@!# clean off.  You have been warned.''
-
*''Compcache is still considered experimental!  It may not work, assplode your n900 and rip your **** clean off.  You have been warned.''
 
====How to enable compcache====
====How to enable compcache====
Line 100: Line 109:
</source>
</source>
-
Once enabled you must tell the system to use the ramz disk:
+
It will take a short while for the kernel to catch up with this, so you should pair this with a 'sleep 1' command. Once enabled, you must tell the system to use the ramz disk:
<source lang="bash">
<source lang="bash">
Line 106: Line 115:
</source>
</source>
-
For any of this to be any benefit the ramz disk needs to have a higher priority than the 'physical' swap space.  Make sure ALL applications are closed and disable then re-enable your physical swap.  On a stock setup (swap on eMMC) you can do this:
+
For any of this to be any benefit, the ramz disk needs to have a higher priority than the 'physical' swap space.  Make sure ALL applications are closed and disable then re-enable your physical swap.  On a stock setup (swap on eMMC) you can do this:
<source lang="bash">
<source lang="bash">
Line 112: Line 121:
</source>
</source>
-
For other setups i.e. when you have swap on uSD you must substitute 'mmcblk0p3' with the location of your swap space.  (If you swap partition is the second partition on the uSD then it will be 'mmcblk1p2').
+
For other setups, i.e. when you have swap on uSD you must substitute 'mmcblk0p3' with the location of your swap space.  (If your swap partition is the second partition on the uSD then it will be 'mmcblk1p2').
You can now check you have the appropriate partitions with:
You can now check you have the appropriate partitions with:
Line 125: Line 134:
You can see ramzswap is 64MB AND with a higher priority than mmcblk0p3.
You can see ramzswap is 64MB AND with a higher priority than mmcblk0p3.
-
Now you must change you VM settings to effectivly use the new ramz setup.  The following settings have been found to work with 32MB, 64MB and 128MB ramz sizes.  They are a work in progress and will be updated as they are tuned to the authors workload (heavy user, treating n900 as a pocket laptop as oppose to merely a phone).
+
Now you must change your VM settings to effectively use the new ramz setup.  The following settings have been found to work with 32MB, 64MB and 128MB (beware!) ramz sizes.  They are a work-in-progress and will be updated as they are tuned to the authors' workload (heavy user, treating n900 as a pocket laptop as oppose d to merely a phone).
 +
 
 +
Paste the below lines into xterm to setup the VM and tune the flash device usage:
<source lang="bash">
<source lang="bash">
Line 141: Line 152:
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
-
echo 125 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
+
echo 100 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
-
echo 125 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
+
echo 100 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
-
echo 250 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
+
echo 200 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
-
echo 250 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
+
echo 200 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
</source>
</source>
Line 156: Line 167:
#referance: http://www.westnet.com/~gsmith/content/linux-pdflush.htm
#referance: http://www.westnet.com/~gsmith/content/linux-pdflush.htm
-
#swapoff ramzswap and remove ramzswap module
+
#Smart swap on/off
-
swapoff /dev/ramzswap0 && sleep 1
+
#drivelist=$(sfdisk -lnd /dev/mmcblk1)
-
rmmod /ramzswap && sleep 1
+
if [ "$(cat /proc/swaps | awk '/mmcblk/ {print $1}' | cut -d "k" -f2 | cut -c1)" == "0" ]; then
-
 
+
        echo "swap is on emmc"
-
#insert ramzswap module and specify disksize
+
        if [ "$(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')" ]; then
-
insmod /lib/modules/current/ramzswap.ko disksize_kb=65536 && sleep 1
+
        nice -20 swapoff $(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')
 +
        #insert ramzswap module and specify disksize
 +
        insmod /lib/modules/current/ramzswap.ko disksize_kb=65536 && sleep 1
 +
        nice -20 swapon $(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')
 +
        echo "swap is on swapped on emmc"
 +
        fi
 +
fi
-
#swapon ramzswap & swap-reset eMMC
+
if [ $(cat /proc/swaps | awk '/mmcblk/ {print $1}' | cut -d "k" -f2 | cut -c1) = "1" ]; then
-
swapon /dev/ramzswap0 && sleep 1
+
        nice -20 swapoff $(sfdisk -lnd /dev/mmcblk1 | grep Id=82 | awk '/mmcblk1/ {print $1}')
-
swapoff /dev/mmcblk0p3 && sleep 1 && swapon /dev/mmcblk0p3 && sleep 1
+
        #insert ramzswap module and specify disksize
 +
        insmod /lib/modules/current/ramzswap.ko disksize_kb=65536 && sleep 1
 +
        nice -20 swapon $(sfdisk -lnd /dev/mmcblk1 | grep Id=82 | awk '/mmcblk1/ {print $1}')
 +
        echo "swap is on sd"
 +
fi
#vm changes
#vm changes
Line 195: Line 216:
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
-
echo 125 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
+
echo 100 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
-
echo 125 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
+
echo 100 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
-
echo 250 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
+
echo 200 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
-
echo 250 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
+
echo 200 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
#display results
#display results
Line 204: Line 225:
</source>
</source>
-
====Making all this happen automatically====
+
====Automating all of this====
----
----
-
There is a package called swapset[http://maemo.org/packages/view/swapset/], it claims to setup swaps and the ramz module automatically.  The author of this article has not used it and thus cannot vouch for it's effectiveness.  Using swapset AND putting the above settings into swappolube would probably cause all of the above to work automatically.
+
There is a package called swapset[http://maemo.org/packages/view/swapset/], which attempts to setup swaps and the ramz module automatically.  The author of this article has not used it, and thus cannot vouch for its effectiveness.  Using swapset AND putting the above settings into swappolube would probably cause all of the above to work automatically. Probably.
<br>
<br>

Latest revision as of 22:39, 11 March 2015

Compcache or Ramzswap, hitherto referred as ramz is a method for taking a chunk of 'normal' RAM and using it as a compressed virtual memory (VM) swap space. That is, we use RAM as a sort of a virtual, virtual RAM by compressing the contents on the fly and storing it in RAM that's marked up as a swap device. This is in order to squeeze as much space from the limited RAM as possible. A swap device created from compressed RAM is many times faster than a regular swap device using hard drives or traditional flash memory.


Contents

[edit] N8x0


To be added by a wild N8x0 user...
Apparently compcache is the single greatest thing to ever happen to the N8x0.


[edit] N900

[edit] The problem


Lack of RAM is considered one on the main performance bottlenecks a N900 user has to contend with. In its stock set-up, the N900 is prone to having massive swapping after even short periods of heavy use. This leads to poor performance, and in the worst cases, a reboot. This is generally alleviated in one or several of four ways.

[edit] The solutions


[edit] Install 'Swappolube'

Swappolube (sic) is a set of VM parameter tweaks initially dreamt up by the user Hawaii. For MOST users, the installation of Swappolube from the repositories and applying the default settings will suffice to alleviate the problem.


[edit] Swap on micro SD card(uSD)

It has been found that an easy way to alleviate eMMC contention is to move the swap space to the uSD card[1].


[edit] Swap de-fragmentation

It has been found that as the swap space fills up, the OS is eventually more and more unable to allocate continuous space on the swap device. This leads to poor performance, that can be periodically reset by turning the swapping device off and on again, clearing the slate. The package ereswap was created to make this easy.


[edit] Compcache

The article's namesake. The use of compcache has been a contentious issue. Most users have found it to cause extremely poor system performance. For many users, as soon as the ramz space gets full - which is pretty quick, considering it's only tens of megabytes large - the system grinds to a slow crawl.

Some empirical and anecdotal evidence suggests that the 'extreme' swap-retention settings of swappolube (that most users run) are highly unsuitable ramz. Swappolube sets the VM to swap as rarely as possible. This does not work for ramz - likely, an opposite approach must be taken: The device must swap a lot. As in this scenario the swapping is optimally mostly done to the RAM swap device, there will be little penalty in speed.


[edit] Using compcache



Caveats!


  • While ramz does work on kernel power version 49 (KP49), it is highly recommended that you use KP50!
  • Ramz requires a disksize that is specified in KB in powers of 2. Acceptable sizes are:
Ramz size English
2048 2MB
4096 4MB
8192 8MB
16384 16MB
32768 32MB
65536 64MB
98304 96MB
131072 128MB
  • It is recommended that you do not use more than 64MB for ramz.
  • Unless enabled very early in the device boot, you MUST have swap enabled on a physical disk before enabling ramz, or your n900 WILL insta-crash and reboot, potentially corrupting your file system!
  • Due to the CPU load slightly increased by the de/compression done by ramz, using ramz likely incurs a slight penalty in battery life.
  • Compcache is still considered experimental! It may not work, asplode your n900 and rip your *@!# clean off. You have been warned.


[edit] How to enable compcache

To enable compcache you must enter these commands as root, the following will create a ramz disk of 64MB:

insmod /lib/modules/current/ramzswap.ko disksize_kb=65536

It will take a short while for the kernel to catch up with this, so you should pair this with a 'sleep 1' command. Once enabled, you must tell the system to use the ramz disk:

swapon /dev/ramzswap0

For any of this to be any benefit, the ramz disk needs to have a higher priority than the 'physical' swap space. Make sure ALL applications are closed and disable then re-enable your physical swap. On a stock setup (swap on eMMC) you can do this:

swapoff /dev/mmcblk0p3 && sleep 1 && swapon /dev/mmcblk0p3

For other setups, i.e. when you have swap on uSD you must substitute 'mmcblk0p3' with the location of your swap space. (If your swap partition is the second partition on the uSD then it will be 'mmcblk1p2').

You can now check you have the appropriate partitions with:

cat /proc/swaps
Filename				Type		Size	Used	Priority
/dev/mmcblk0p3                          partition	786424	64476	-2
/dev/ramzswap0                          partition	65528	61572	-1

You can see ramzswap is 64MB AND with a higher priority than mmcblk0p3.

Now you must change your VM settings to effectively use the new ramz setup. The following settings have been found to work with 32MB, 64MB and 128MB (beware!) ramz sizes. They are a work-in-progress and will be updated as they are tuned to the authors' workload (heavy user, treating n900 as a pocket laptop as oppose d to merely a phone).

Paste the below lines into xterm to setup the VM and tune the flash device usage:

echo 10 > /proc/sys/vm/dirty_ratio
echo 10 > /proc/sys/vm/dirty_background_ratio
echo 250 > /proc/sys/vm/dirty_writeback_centisecs 
echo 1000 > /proc/sys/vm/dirty_expire_centisecs 
echo 100 > /proc/sys/vm/swappiness 
echo 200 > /proc/sys/vm/vfs_cache_pressure 
echo 0 > /proc/sys/vm/page-cluster
echo 64 > /sys/block/mmcblk0/queue/nr_requests
echo 64 > /sys/block/mmcblk1/queue/nr_requests
echo 0 > /sys/block/mmcblk0/queue/iosched/slice_idle
echo 0 > /sys/block/mmcblk1/queue/iosched/slice_idle
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
echo 100 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
echo 100 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
echo 200 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
echo 200 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async

[edit] How to do this all at once


Paste the below code into a root xterm.

#!/bin/sh
 
#referance: http://www.westnet.com/~gsmith/content/linux-pdflush.htm
 
#Smart swap on/off
#drivelist=$(sfdisk -lnd /dev/mmcblk1)
if [ "$(cat /proc/swaps | awk '/mmcblk/ {print $1}' | cut -d "k" -f2 | cut -c1)" == "0" ]; then
        echo "swap is on emmc"
        if [ "$(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')" ]; then
        nice -20 swapoff $(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')
        #insert ramzswap module and specify disksize
        insmod /lib/modules/current/ramzswap.ko disksize_kb=65536 && sleep 1
        nice -20 swapon $(sfdisk -lnd /dev/mmcblk0 | grep Id=82 | awk '/mmcblk0/ {print $1}')
        echo "swap is on swapped on emmc"
        fi
fi
 
if [ $(cat /proc/swaps | awk '/mmcblk/ {print $1}' | cut -d "k" -f2 | cut -c1) = "1" ]; then
        nice -20 swapoff $(sfdisk -lnd /dev/mmcblk1 | grep Id=82 | awk '/mmcblk1/ {print $1}')
        #insert ramzswap module and specify disksize
        insmod /lib/modules/current/ramzswap.ko disksize_kb=65536 && sleep 1
        nice -20 swapon $(sfdisk -lnd /dev/mmcblk1 | grep Id=82 | awk '/mmcblk1/ {print $1}')
        echo "swap is on sd"
fi
 
#vm changes
#/proc/sys/vm/dirty_ratio (default 40)
echo 10 > /proc/sys/vm/dirty_ratio
 
#dirty_background_ratio
echo 10 > /proc/sys/vm/dirty_background_ratio
 
#dirty_writeback_centisecs
echo 250 > /proc/sys/vm/dirty_writeback_centisecs
 
#/proc/sys/vm/dirty_expire_centiseconds (default 3000)
echo 1000 > /proc/sys/vm/dirty_expire_centisecs
 
#free space saved for large allocations, values below 256 cause insta-crash
#echo 1024 > /proc/sys/vm/min_free_kbytes
 
#'Normal' VM stuff
echo 100 > /proc/sys/vm/swappiness
echo 200 > /proc/sys/vm/vfs_cache_pressure
echo 0 > /proc/sys/vm/page-cluster
 
#Flash disc tuning
echo 32 > /sys/block/mmcblk0/queue/nr_requests
echo 32 > /sys/block/mmcblk1/queue/nr_requests
echo 0 > /sys/block/mmcblk0/queue/iosched/slice_idle
echo 0 > /sys/block/mmcblk1/queue/iosched/slice_idle
echo 32 > /sys/block/mmcblk0/queue/iosched/quantum
echo 32 > /sys/block/mmcblk1/queue/iosched/quantum
echo 100 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
echo 100 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
echo 200 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
echo 200 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
 
#display results
cat /proc/swaps

[edit] Automating all of this


There is a package called swapset[2], which attempts to setup swaps and the ramz module automatically. The author of this article has not used it, and thus cannot vouch for its effectiveness. Using swapset AND putting the above settings into swappolube would probably cause all of the above to work automatically. Probably.


[edit] N9/50

To be added by an ardent masochist.