How is the use of Zram (swap) prioritized?

Hello friends, can anyone guide me?
I have a BT Home Hub 5 Type A router.
I want the use of swap to be prioritized because I have set 2GB for swap volume. But the swap space is not used at all during 24 hours and unfortunately the main RAM of the device is only less than 30% empty.
Does anyone have a solution, I would like to use swap and have more than 50% free space in the main RAM of the device.
If swap is applied, does it affect the speed of the router? (Does the speed decrease?)

To answer the asked question: The aggressiveness of Linux's swap mechanism is controlled by the variable "swappiness". You can look at it by cat /proc/sys/vm/swappiness

That said, I would not recommend changing it. Why do you want more free RAM? In Linux, RAM is considered "free" when it's not being used for literally anything else. Linux actively tries NOT to let you RAM go to waste, so if it's not being used for processes, then Linux will use it for file buffers and cache. If a process needs more memory, then Linux takes it from:

  1. Memory not being used for anything (FREE)
  2. Memory being used as buffers or cache
  3. IF and only IF there is still not enough memory, then Linux will engage swapping to write pages for processes that are in the background to the swap, and then steal that memory to give it somewhere else.

Swapping is always the least preferred way to extend RAM. Yes, swapping does decrease the speed of the router. Your title mentions ZRAM, which basically takes some RAM away from normal usage and tries to use compression algorithms to use the RAM as virtual swap. This takes CPU time to do. Your device only has a 500MHz CPU in it.

If you NEED swap space for a particular function, then ZRAM is one option. Another option is using USB swap. Your device only has USB 2.0, so really there is no good option here.

Otherwise, if you are just trying to make your free RAM number higher, I'd recommend just leaving it alone.


Unfortunately, it is not possible to change the swappiness in the /etc/sysctl.conf address !
Please give it uci command to change swappiness to 50.

Why is that?

I don't know of a UCI command to change swappiness. You can change it manually: echo 50 > /proc/sys/vm/swappiness or sysctl vm.swappiness=50
You can automate that in any number of ways. The easiest is probably to use /etc/rc.local either by directly editing it, or using LuCI and navigating to System->Startup->Local Startup

1 Like