Prepare environment for experiments #
Before I start, I want to be on the same page with the reader, so any example or any code snippet can be executed, compiled and checked. Therefore we need a modern GNU/Linux installation where we can play with code and kernel.
If you are using Windows or Mac OS, I would suggest installing Vagrant with Virtual Box. For the GNU/Linux distributive I’d like to use Arch Linux. Arch is a good example of a modern actual version of the GNU/Linux system (BTW, I use Arch Linux). It supports the latest kernels, systemd and cgroup v2.
If you’re already on Linux you know what to do 😉.
Can I use docker?
Unfortunately, no. We need a system where we can go nuts and play around with cgroup limits, debug programs with low level tools and run code as a root user without any limitations.
So below, I’m showing all you need to install on Arch.
Arch Linux provisioning #
When you get your Arch running, please update it and install the following packages:
$ pacman -Sy git, base-devel, go
We need to install
yay (https://github.com/Jguer/yay) in order to be able to setup software from community-driven repositories:
$ cd ~ $ git clone https://aur.archlinux.org/yay.git $ cd yay $ makepkg -si
vmtouch tool from
$ yay -Sy vmtouch
We will need
page-type tool from the kernel repo, so the easiest way to install it, is to download the linux kernel release and make it manually:
$ mkdir kernel $ cd kernel $ wget https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-5.14.tar.gz $ tar -xzf linux-5.14.tar.gz $ cd linux-5.14/tools/vm $ make $ sudo make install
Now we are almost ready. We need to generate a test data file, which will be used in our experiments with Page Cache:
$ dd if=/dev/random of=/var/tmp/file1.db count=128 bs=1M
And the final step is dropping all linux caches in order to get a clean box:
$ sync; echo 3 | sudo tee /proc/sys/vm/drop_caches