In this blog article, we will discuss various methods to speed up I/O performance and ultimately settle on using LVM to mount a fast I/O device with a RAMDisk as cache. This approach is beneficial when you don’t care about retaining data in the location between reboots.

Options Considered

  1. Only use RAM (i.e., tmpfs of 20 or 30GB): This option has the problem that if RAM is not enough, the build will fail.
  2. Use larger tmps (double the amounts above) and use the fast I/O location as a swap: The issue with this option is that if the system needs to use the swap, the complete OS could become laggy and unresponsive, affecting the build times.
  3. Concatenate RAM with Fast I/O using LVM: This approach does not guarantee that the filesystem will write first on RAM.
  4. Use LVM to mount the Fast I/O with RAMDisk as cache: This is the best approach among the options considered, but further research on the options of LVM is needed.

We will focus on option 4 for the rest of this article.

Implementation

Here’s a script that implements option 4:

#!/bin/bash
# Create LVM group
fallocate -l 2G fake-ssd.img
sudo losetup /dev/loop50 fake-ssd.img
sudo vgcreate vgextend /dev/loop50
sudo lvcreate -n my_vol -l 100%FREE vg-test

# Prepare and mount LVM volume
sudo mkdir /mnt/vg-test
sudo mkfs.ext4 /dev/mapper/vg--test-my_vol
sudo mount /dev/mapper/vg--test-my_vol /mnt/vg-test/

# Extend LVM with RAM-Disk of 8 or 10GB
sudo modprobe brd rd_nr=1 rd_size=8388608
sudo vgextend vg-test /dev/ram0
sudo lvcreate --type cache --cachemode writeback -l 100%FREE -n my_vol_cache vg-test/my_vol /dev/ram0

# Format and mount cached LVM volume
sudo mkfs.ext4 /dev/mapper/vg--test-my_vol
sudo mount /dev/mapper/vg--test-my_vol /mnt/vg-test/

# Start GitLab Runner using mounted location
sudo gitlab-runner start --working-directory /mnt/gitlab_runner

To make sure the script runs at startup, you can add it to /etc/rc.local. However, it is better to write your own service for this purpose.

Conclusion

Using LVM to mount a fast I/O device with a RAMDisk as cache is an effective method to speed up I/O performance. It is essential to ensure that the system is set up correctly to achieve the best results. Consider writing your own service instead of using rc.local for a more robust implementation.