top of page
Search

Run lots of applications (RAM Expansion using ZRAM)

Updated: Nov 2, 2020

Now your enjoying your new elementary OS on your JOI Book, you may have noticed that if you open 4 or more apps at the sametime, it can become very slow. This is because the JOI Book only has 4GB of RAM. In linux once the RAM is full, the system will start using the hard drive as an extended RAM (this is called swap space) unfortunately the hard drive is much slower than RAM, hence the slowdown.


There is a fix though, ZRAM allows you to compress programs in RAM, up to 3 times (i.e. if you give ZRAM 2GB out of your 4GB to compress, you can fit 6GB worth of RAM into your 2GB of ZRAM. There is a CPU overhead for this as linux needs to compress and uncompressed the applications coming in and out of ZRAM.


To configure ZRAM we first need an easy way to track and monitor memory utilization. The "GNOME System Monitor" is great for this task.


Install it from the AppCenter by searching for "GNOME System Monitor", note you'll have to scroll down a lot as there are many applications in the AppCenter.


Once installed you'll need to start it from the Applications menu at the top right hand corner, look for "System Monitor". Once running click on the "Resources" tab at the top. Here you'll see your CPU, Memory and Network utilization. Focus on the middle graph that shows memory and swap space.


Now we can monitor memory usage and our swap space, lets try turning on our zram to help us compress our available memory and thus run more apps.


Firstly load the zram module using the following command (note the num_devices parameter represents the number of CPUs or cores we have, in the case of the JOI BOOK 150 we have a 4 core CPU)

sudo modprobe zram num_devices=4

Now we need to tell linux how much memory we want to compress. Our JOI book comes with 4GB of ram, so we're going to compress half of it. To do this open up a new terminal then copy and paste the command below:

echo 2048M | sudo tee /sys/block/zram0/disksize

Check this worked by running the following command, which should output 2048 in bytes

cat /sys/block/zram0/disksize

Now we need to tell linux to use this as swap space. To do this copy and paste the command below into your terminal

  sudo mkswap /dev/zram0

Note make sure the number at the end of "zram0" matches the number you had on the earlier command. If it works you should see something similar to the output below (but with different ids)

Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx

Now we have to mount this as a swap space drive to do this, copy and paste the command below into your terminal.

sudo swapon /dev/zram0 -p 32767

Again make sure the number at the end of "zram0" matches the number you had on the earlier command


ZRAM should now be up and running, try it out by running the command below, or going back to your "System Monitor" to view your memory usage.

cat /proc/swaps

This should output something like below.



What this means is that linux has 2 options for swap space (after it runs out of RAM) 1st it can use the hard drive, this is normal swapspace (/swapfile) or it can use the ZRAM area you just created.


Go ahead and open up lots of applications until the swapspace starts getting used, hopefully you'll notice very little slowdown.


Wait - We need to make these changes permanent.


So now you have your zram setup, we need to write a few scripts to get this done automatically on startup, otherwise you'll loose these changes as soon as you restart or shutdown your laptop.


DISCLAIMER! - There is probably a better way to do this, if you know one please leave it in the comments, but for now this works.:


Create a file called rc.local in /etc by running the following command.

sudo touch /etc/rc.local

Edit the rc.local file and enter the following into it.

#!/bin/bash
sudo modprobe zram num_devices=4
echo 2048M | sudo tee /sys/block/zram0/disksize
sudo mkswap /dev/zram0
sudo swapon /dev/zram0 -p 32767

make the file executable by running the following command:

sudo chmod +x /etc/rc.local

Now make a service script that will start the rc.local script each time the laptop boots up.

sudo touch /etc/systemd/system/rc-local.service

Copy the following into the rc-local.service script.

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

Enable the new script to start at boot time.

sudo systemctl enable rc-local

Reboot your system, your zram swapspace should now be automatically setup.


160 views0 comments

Recent Posts

See All
bottom of page