Swap Space Management
Page Contents
Swap Space
Swap space is a special area for the OS that can be used as additional system random access memory (RAM). The traditional approach to swap space used a swap partition on your drive system. A modern approach, as used by Bodhi Linux 7.0.0 (based upon Ubuntu 22.04), is the use of a swap file.
Tip: see Enabling Zswap for more information on (potentially) speeding up older machines
Swap File
One advantage of a swap file (over a swap partition), is easier resizing.
Below are details of managing the swap file using Terminology.
Check Swap Status
Check that your Bodhi Linux installation already has swap enabled:
sudo swapon --show
which should output something like:
NAME TYPE SIZE USED PRIO /dev/sda1 partition 1.0G 0B -2
Create
If a swap file does not exist, create a file which will be used for swap. In this example, a 1GB file will be created name swapfile.
Note: GB: Gigabyte; MB: Megabyte
sudo fallocate -l 1G /swapfile
Set the correct permissions for the file:
sudo chmod 600 /swapfile
Now make a swap area within the file and enable:
sudo mkswap /swapfile sudo swapon /swapfile
To make the changes persistent, make an entry into fstab (if it is not already there) using your preferred editor (Leafpad, Nano, Vim).
***CAUTION***: extreme care should be taken when modifying fstab! An incorrectly stated fstab will result in a failure to boot Bodhi Linux.
Add the following change to /etc/fstab
/swapfile none swap sw 0 0
Verify the swap was created and usable (see: Check Swap Status above).
Resize
We are effectively deleting the swap file, and recreating the file.
Follow Remove (below), omitting the change to /etc/fstab
Follow Create (above), omitting the change to /etc/fstab
Verify the swap was created and usable (see: Check Swap Status above).
Remove
Delete the swap
sudo swapoff -v /swapfile
Delete the swap file
rm -v /swapfile
Remove the line /swapfile none swap sw 0 0
(using your preferred editor) from the file: /etc/fstab
Be sure to save changes.
Swappiness
For most users doing general computing, you will not need to adjust Swappiness. Bodhi Linux has a default of <code>swappiness=60</code>. Advanced users are likely aware and now you are too – this is a highly debated topic which is outside of beginner’s guide. For a good discussion check out https://askubuntu.com/questions/103915/how-do-i-configure-swappiness. There are lots of hardware, run-time and user variables that will determine your results – explore what works for your system if you are curious!
Enabling Zswap
Our Forum Crew Member, @kiezel, has a link to his project Easy Linux Tips Project that walks a user through enabling zswap. – “This should create a noticeable speed boost, especially on older machines.”
Note: in the how-to, replace:
xed admin://
with
pkexec leafpad
.
So for
xed admin:///etc/default/grub
use:
pkexec leafpad /etc/default/grub
One potential issue:
lz4 not available
You definitely want lz4 compression, because that’s simply better than the default lzo compression. In Bodhi Linux, the module for the lz4 feature isn’t included in the initramfs
at boot time.
So let’s change that:
pkexec leafpad /etc/initramfs-tools/modules
In that text file, create a new bottom line with lz4 in it, so that it becomes:
# List of modules that you want to include in your initramfs. # They will be loaded at boot time in the order below. # # Syntax: module_name [args ...] # # You must run update-initramfs(8) to effect this change. # # Examples: # # raid1 # sd_mod lz4
Save the changes and close the text editor.
Then in the terminal:
sudo update-initramfs -u
Reboot.
After the reboot, test again by running:
dmesg | grep zswap
Bodhi Linux Home
Bodhi Linux – Wiki Home Page
Bodhi Linux – Wiki Table of Contents