Add documentation for enabling ZRAM for GitLab on RaspberryPi

You can find my recommended documentation addition, along with the relevant script here

I'm currently doing benchmarking to get numbers on how significant the improvement is, but from a GitLab user/admin standpoint it is immediately noticeable.

If interested in adding this to the docs, I'll make any edits/updates it needs and do a MR.

  • Documents Feature A
  • Follow-up from: #XXX, !YYY

New doc or update?

  • New documentation
  • Update existing documentation

Checklists

Product Manager

  • Add the correct labels
  • Add the correct milestone
  • Indicate the correct document/directory for this feature
  • Fill the doc blurb below

Documentation blurb


description: "Enabling ZRAM swap for GitLab on RaspberryPi"

Running on a Raspberry Pi

Additional recommendations

Enabling ZRAM swap

Using ZRAM as swap is another option to increase the performance of your Raspberry Pi device without requiring an proper harddrive.

Offer a very short description of the feature or use case, and what to expect on this page. (You can reuse this content, or part of it, for the front matter's description at the top of this file).

Overview

Using ZRAM as swap is another option to increase the performance of your Raspberry Pi device without requiring an proper harddrive. ZRAM uses compression algorithms and creates a block device which can be used for swap or as a general-purpose RAM disk. Using ZRAM for swap results in a noticeable improvement in the performance of GitLab on Raspberry Pi 2/3.

Use cases

Boosting RaspberryPi 2/3 performance when running GitLab without proper hard drive.

Requirements

Raspberry Pi 2/3 running Raspbian or Ubuntu 16.04 SD card Best SD Cards for RasPi

Instructions

Enabling ZRAM swap

Using ZRAM as swap is another option to increase the performance of your Raspberry Pi device without requiring an proper harddrive.

ZRAM uses compression algorithms and creates a block device which can be used for swap or as a general-purpose RAM disk. Using ZRAM for swap results in a noticeable improvement in the performance of GitLab on Raspberry Pi 2/3.

To optimize the RaspberryPi for ZRAM and automatically enable it on reboot, we can use a shell script.

sudo nano /usr/bin/zram.sh
#!/bin/bash
cores=$(nproc --all)
modprobe zram num_devices=$cores

swapoff -a

totalmem=`free | grep -e "^Mem:" | awk '{print $2}'`
mem=$(( ($totalmem / $cores)* 1024 ))

core=0
while [ $core -lt $cores ]; do
  echo $mem > /sys/block/zram$core/disksize
  mkswap /dev/zram$core
  swapon -p 5 /dev/zram$core
  let core=core+1
done

This script creates an additional compressed RAM swap disk for each CPU core and activates it. No further configuration action is necessary.

You can also download this script with the following command:

sudo wget -O /usr/bin/zram.sh https://gitlab.com/greg/rpi_zram/raw/master/zram.sh

Make the script executable:

sudo chmod +x /usr/bin/zram.sh

Run zram.sh with the command:

sudo zram.sh

By running swap -s we can see that we have four additional swap space partitions created and running: /dev/zram0, /dev/zram1/, /dev/zram2/, and /dev/zram3/

To automatically enable ZRAM at boot time, edit the /etc/rc.local file

sudo nano /etc/rc.local

and insert the line

/usr/bin/zram.sh &

at the end of the file, but before the final

exit 0

line of the file.

The final two lines should look like:

/usr/bin/zram.sh
exit 0

Save the /etc/rc.local file and after rebooting the Raspberry Pi, it will automatically start up with the configured ZRAM memory.

How to Remove the overclocking

Remove the line /usr/bin/zram.sh & from the /etc/rc.local file.

Reboot your Raspberry Pi.

All ZRAM configuration will be disabled after reboot.


Notes:

Developer

  • Copy the doc blurb above and paste it into the doc
  • Write the tutorial - explain how to use the feature
  • Submit the MR using the appropriate MR description template
Edited by Greg Myers