Back to the home page
Contents of this page:
- 1. The absolute number one: turn on zswap
- 2. When zswap is enabled: decrease swap use
- 3. At least 16 GB memory (RAM): tame the inode cache
- 4. Other safe speed tweaks
You can improve the usage of the system memory of Linux Mint 22 with the following tweaks:
The absolute number one: turn on zswap
1.You'll often achieve a considerable speed gain by turning on zswap. This is especially so on older machines, but on modern machines there will also be a speed gain, even though it'll be smaller. It's therefore advisable to turn it on in all cases. Below, I'll explain how to do that.A. First some background information:
The kernel feature called zswap provides a compressed RAM cache for swap pages. Pages which would otherwise be swapped out to disk, are instead compressed and stored into a memory pool in RAM.
Once the pool is full or the RAM is exhausted, the least recently used page is decompressed and written to the swap file or partition on the hard disk, as if it had not been intercepted at all. After that page has been dumped into the swap file or partition, the compressed version in the pool will be freed.
By default, zswap is switched off. When switched on, it uses up to 20 percent of the RAM memory by default (don't increase that above 40, because higher percentages might not leave enough RAM for general use).
The price you pay for turning on zswap, is twofold:
- Your processor (CPU) is being taxed more heavily, because it'll have to compress and decompress more. With a single-core CPU of low speed there might be a noticeable performance hit, as compressing/decompressing data requires a faster CPU, preferably a multi-core one.
- When the system has filled the RAM swap, it'll start swapping on the hard drive as well. With a burden on the available RAM: the chunk of memory that has been sacrificed for the RAM swap.
That's why I advise to turn on zswap only in combination with a swappiness that has been reduced to 30 (see item 2 on this page).
B. Now the how-to:
You can switch on zswap as follows (with superior fast threefold compression, by means of lz4 and z3fold):
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste the following command line into the terminal:
xed admin:///etc/default/grub
Press Enter. Type your password when prompted.
(the three consecutive slashes are intended and no typo!)
c. Find the following line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Now you're going to add some parameters to that line. This is the easiest way: simply replace the entire line by the following blue line (this is one long line, don't chop it up and use copy/paste to transfer it):
Machines with only 4 GB RAM or less (40 % zswap):
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.max_pool_percent=40 zswap.zpool=z3fold zswap.compressor=lz4"
(if you want to type this line yourself: note that the "l" in "lz4" is a lowercase letter L)
Save the modified file and close it.
Machines with more than 4 GB RAM (default 20 % zswap):
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4"
(if you want to type this line yourself: note that the "l" in "lz4" is a lowercase letter L)
Save the modified file and close it.
d. Copy/paste the following command line into the terminal, in order to execute the modification:
sudo update-grub
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
(if you type the command: note the dash between update and grub)
e. The module for the z3fold feature isn't included in the initramfs at boot time, so it won't be loaded automatically. As z3fold (threefold compression) is simply better than the default zbud (twofold compression), change that like this:
Copy/paste the following command line into the terminal:
xed admin:///etc/initramfs-tools/modules
Press Enter.
f. In the bottom of the text of that file, create a new line with z3fold 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
z3fold
Save the changes and close the text editor.
g. Then in the terminal (use copy/paste to transfer the command to the terminal!):
sudo update-initramfs -u
Press Enter.
h. Reboot.
i. Now you can check whether the change has been implemented with this command (use copy/paste):
dmesg | grep zswap
It should report in its final line: zswap: loaded using pool lz4/z3fold.
j. The percentage of your RAM that zswap uses, can be checked with the following command:
cat /sys/module/zswap/parameters/max_pool_percent
It should report 20, which is the default, or 40. As said already: don't increase that above 40, because higher percentages might have negative consequences.
Warning: there's also RAM swap feature called zRam. Don't install that, because it's counterproductive in combination with zswap!
Both zswap and zRam provide a compressed cache and would, when used simultaneously, wind up using more system memory than each individually. Simultaneous use makes therefore no sense.
When zswap is enabled: decrease swap use
2. On the hard disk there's a separate file or partition for virtual memory, called the swap. When Mint uses the swap too much, the computer slows down. At least when zswap has been enabled (see item 1 on this page).Note: Don't fully disable the disk swap, no matter how much RAM your computer has! Not only because zswap needs it, but also because disabling the disk swap is a bad idea in general: it's counterproductive to do so and might degrade the performance of your system.
Mint's inclination to use the swap, is determined by a value called "swappiness". The lower the value, the longer it takes before Mint starts using the swap.
On a scale of 0-200, the default value is 60. Which is too high for normal desktop use; the optimal compromise is probably something like 30. Decreasing the default value somewhat on a desktop computer, has no negative side effects.
Now the how-to for setting the swappiness to a more reasonable level, namely 30:
a. First check your current swappiness value. Type in the terminal (use copy/paste):
cat /proc/sys/vm/swappiness
Press Enter.
The result will probably be 60.
b. To change the swappiness into a more sensible setting, type in the terminal (use copy/paste to avoid typos):
xed admin:///etc/sysctl.conf
Press Enter. Type your password when prompted.
Now a text file opens. Scroll to the bottom of that text file and add your swappiness parameter to override the default. For that, copy/paste the following two blue lines into the text file:
# Decrease swap usage to a more reasonable level
vm.swappiness=30
c. Save and close the text file. Then reboot your computer.
d. After the reboot, check the new swappiness setting:
- Launch a terminal window.
(You can launch a terminal window like this: *Click*)
- Type (use copy/paste):
cat /proc/sys/vm/swappiness
Press Enter.
Now it should be 30.
Note: If your hard disk is an SSD, there's an extra reason to decrease swappiness. That's because too many write actions, like frequent swapping, reduce the lifespan of an SSD. Also check these tips for optimizing an SSD for your Linux.
At least 16 GB memory (RAM): tame the inode cache
3. Computers with at least 16 GB of memory (RAM), will probably benefit by shrinking the inode cache less aggressively.The price that you pay for this, is that certain system items will remain longer in the RAM memory, which decreases the amount of available RAM for general tasks. That's why this tweak is only useful for computers with at least 16 GB of memory (RAM).
This is how you do it:
a. Type in the terminal (use copy/paste):
xed admin:///etc/sysctl.conf
Press Enter. Now a text file opens.
b. Scroll to the bottom of that text file and add your cache parameter to override the default, so copy/paste the following two blue lines into that text file:
# Improve cache management
vm.vfs_cache_pressure=50
Save and close the text file.
c. Reboot your computer.
Other safe speed tweaks
4. Other safe speed tweaks can be found on this page.Want more?
Do you want more tips and tweaks? There's a lot more of them on this website!
For example:
Clean your Linux Mint safely
Avoid 10 fatal mistakes
To the content of this website applies a Creative Commons license.
Back to the home page
Disclaimer