Back to the home page

This page is exclusively meant for Ubuntu 24.04.x. The corresponding page for Linux Mint, that contains a lot more speed tweaks besides the ones below, can be found here.
Speeding up your Ubuntu is fun! That way, you'll get more performance out of your computer for free.
There are several tweaks to make Ubuntu 24.04.x run faster. Some are quite safe, some are risky. Here you'll find only safe ones.
I don't like risky tweaks, because I think that stability and reliability are much more important than a (often minor) performance boost. That's why I've collected a couple of speed tips, that you can apply safely and that'll probably make your Ubuntu run noticeably faster. Without diminishing the stability and reliability of your system.
Note: Even though in general you can apply those tips safely, nothing in life is really for free.... You always pay some "price". You disable a particular system service or some feature.
Each tweak therefore has its own "price tag". So you should consider before you apply a tip, whether you're willing to pay the "price" for it.
OK, now that that's out of the way, let's get started:
Contents of this page:
- 1. Improve usage of the system memory (RAM)
- 2. Speed up your wireless internet by disabling the WiFi power management
- 3. Improve writing to external media
- 4. Want more tips?
Improve usage of the system memory (RAM)
1. You can improve the usage of the system memory (RAM) with the following tweaks:The absolute number one: turn on zswap
1.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:
Swapping is one of the biggest threats to performance. This hasn't changed over the years and will stay that way, as long as RAM will continue to be faster than permanent storage devices. That's why zswap exists: to mitigate this undesirable effect of swapping, by a reduction of I/O activity. Or in normal human language: zswap will make the system write less to the hard disk.
The kernel feature called zswap, provides a compressed RAM cache for swap pages. Pages which would otherwise be swapped out to the disk, are instead compressed and stored into a memory pool in the RAM.
Once the pool is full or the RAM is exhausted, the least recently used page is decompressed and written to the swap on the hard disk, as if it had not been intercepted at all. After that page has been dumped into the disk swap, the compressed version in the RAM pool will be deleted, thus freeing up the space it took in the RAM.
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) will be taxed more, 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, if your computer has a relatively weak CPU, to turn on zswap only in combination with a swappiness that has been reduced to 45 (see item 1.2 on this page).
B. Now the how-to:
You can switch on zswap as follows (with superior fast compression, by means of lz4 and zsmalloc):
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Now you're going to install lz4. Use copy/paste to transfer this command line into the terminal:
sudo apt-get install lz4
(note that the "l" in "lz4" is a lowercase letter L)
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. Press Enter again.
c. Copy/paste the following blue command line into the terminal. That's one long line, don't chop it up. And don't try to type it, because it's far too easy to make a mistake:
Machines with only 8 GB RAM or less (40 % zswap):
sudo sed -i 's/splash/splash zswap.enabled=1 zswap.max_pool_percent=40 zswap.zpool=zsmalloc zswap.compressor=lz4/' /etc/default/grub
Press Enter.
Machines with more than 8 GB RAM (default 20 % zswap):
sudo sed -i 's/splash/splash zswap.enabled=1 zswap.zpool=zsmalloc zswap.compressor=lz4/' /etc/default/grub
Press Enter.
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.
(if you type the command: note the dash between update and grub)
The zsmalloc and lz4 modules aren't included in the initramfs at boot time, so they won't be loaded automatically. Change that like this:
e. For zsmalloc, copy/paste the following command line into the terminal:
echo "zsmalloc" | sudo tee -a /etc/initramfs-tools/modules
Press Enter.
f. For lz4, copy/paste the following command line into the terminal:
echo "lz4" | sudo tee -a /etc/initramfs-tools/modules
Press Enter.
g. Then in the terminal, in order to update the initramfs with the new modules (use copy/paste to transfer the command to the terminal!):
sudo update-initramfs -uk all
Press Enter.
h. Reboot.
i. Now you can check whether the change has been implemented with this command (use copy/paste):
sudo dmesg | grep zswap
The output should report in its final line:
zswap: loaded using pool lz4/zsmalloc
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 either 20, which is the default, or 40. As said already: don't increase that above 40, because higher percentages might have negative consequences.
Note: If your hard disk is an SSD, there's an extra reason to use zswap. That's because too many write actions, like frequent disk swapping, reduce the lifespan of an SSD.
Why zswap is better than zRam (and never use both of them simultaneously!)
1.1.1. There's also an alternative RAM swap feature called zRam, which is not as good as zswap. The reasons that zswap is generally better than its alternative zRam, are twofold:I. zswap taxes the CPU less than zRam. Especially with desktop use the difference can be significant.
II. zswap is less invasive than zRam: it utilizes the existing swap infrastructure in Ubuntu.
You can find more background information concerning zswap versus zRam here and here. Web pages gone? Download an offline copy of both articles here.
Note: Don't install zRam when you use zswap, because it's downright 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 and would even be detrimental.
When zswap is enabled: decrease swap use when your CPU is weak
1.2. On the hard disk there's a separate file or partition for virtual memory, called the swap. When Ubuntu uses the swap too much, the computer slows down. This still plays a role when zswap has been turned on (see item 1.1 on this page).Ubuntu's inclination to use the swap, is determined by a value called "swappiness". The lower the value, the longer it takes before Ubuntu starts using the swap.
On a scale of 0-200, the default value is 60. When your CPU is relatively weak, that's a bit too high for normal desktop use; the optimal compromise for a weak CPU (these things are always a trade-off) is probably something like 45. Decreasing the default value somewhat on a desktop computer with a weak CPU, has no negative side effects.
On a computer with a powerful CPU, the default swappiness of 60 is best. So don't change it for such a computer.
Note (1): In general, it's nowadays not a good idea anymore to decrease swappiness as a stand-alone measure. Don't change the default swappiness when you haven't enabled zswap.
Note (2): 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.
Now the how-to for setting the swappiness to a more reasonable level for a weak CPU:
a. First check your current swappiness value. Type in the terminal (use copy/paste in order to prevent typos):
cat /proc/sys/vm/swappiness
Press Enter.
The result will probably be 60.
b. To change the swappiness into a more sensible setting for a weak CPU, use copy/paste to transfer the following line into the terminal (this is one long line, definitely use copy/paste in order to avoid typos):
echo "vm.swappiness=45" | sudo tee /etc/sysctl.d/7-swappiness.conf
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. Press Enter again.
c. 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 45.
Regrets? Undoing swappiness reduction is easy
1.2.1. Having regrets about the swappiness reduction? Undoing it is simple with this terminal command:sudo rm -v /etc/sysctl.d/7-swappiness.conf
Reboot and the swappiness should be default again.
Speed up your wireless internet by disabling the WiFi power management
2. For some wireless chipsets, a simple tweak is sufficient for noticeably increasing the connection quality of your wireless internet, thus speeding up your internet usage. Namely disabling the power management for the wireless chipset (and for that chipset alone; don't worry!).This WiFi power management can cause frequently recurring disconnects, so you're better off without it. The price you pay is obviously an increase in power consumption, although this increase isn't big.
The easiest way to improve your wireless internet connection by disabling power management for the WiFi chipset (for that chipset alone, not systemwide), is this:
a. First you need to find out whether Ubuntu applies power management to your WiFi chipset. For this, launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Type in the terminal:
iwconfig
Press Enter.
You can then not only see the name for your wireless chipset (for example: wlp2s0), but also whether Power Management is on for it. When it's off, or when no mention is made of Power Management at all, you don't need to do anything.
When Power Management is on, proceed as follows:
c. Use copy/paste for transferring the following line into the terminal (don't try to type it!):
sudo sed -i 's/3/2/' /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
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. Press Enter again.
d. Reboot your computer.
e. Then check in the terminal, by the command iwconfig, whether Power Management for the wireless chipset is off now.
If so, you're done!
Improve writing to external media
3. On some machines, writing to external media like USB memory sticks or external hard disks, is erratic. It proceeds in fits and starts: a blazingly fast start, followed by a sharp drop to a slow and faltering speed. Furthermore, the process is unintuitive (it's unclear when the operation is complete).This undesirable behaviour can be improved by shrinking the write buffers in the RAM (memory), which is especially useful on machines with a lot of RAM (but machines with little RAM might benefit also from this). Thus you force the system to start writing earlier from the RAM to the external medium, and with shorter intervals.
This smoothes the process considerably, although writing speed will still drop after the fast start. That's inevitable.
You shouldn't reduce those write buffers too much though, because otherwise writing to internal media might be negatively affected. Such things are always a compromise.... But there's a compromise available that usually gives better results than the defaults.
Proceed like this:
a. First you're going to check the current sizes of the write buffers. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Use copy/paste to transfer this command line into the terminal:
cat /proc/sys/vm/dirty_ratio
Press Enter. The output will probably be 20, which means that this buffer has a maximum of 20 % of your RAM.
c. Then execute this command (again, use copy/paste to transfer it into the terminal!):
cat /proc/sys/vm/dirty_background_ratio
Press Enter. The output will probably be 10, which means that this buffer has a maximum of 10 % of your RAM.
Now let's proceed to replace those two ratios by more sensible fixed sizes.
d. First the dirty_bites:
In order to prevent typos, copy/paste this long blue line into the terminal:
For modern computers with more than 4 GB RAM (size of 500 MB):
echo "vm.dirty_bytes=524288000" | sudo tee /etc/sysctl.d/8-writing.conf
For older computers with only 4 GB RAM or less (size of 300 MB):
echo "vm.dirty_bytes=314572800" | sudo tee /etc/sysctl.d/8-writing.conf
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.
e. Then the dirty_background_bytes:
Copy/paste the following blue command line into the terminal:
For modern computers with more than 4 GB RAM (size of 250 MB):
echo "vm.dirty_background_bytes=262144000" | sudo tee -a /etc/sysctl.d/8-writing.conf
For older computers with only 4 GB RAM or less (size of 150 MB):
echo "vm.dirty_background_bytes=157286400" | sudo tee -a /etc/sysctl.d/8-writing.conf
Press Enter.
f. Reboot your computer. Then test whether this hack has worked. First with the commands you've used at steps b and c: both commands should return a 0 now.
These two commands should return the amount of bytes that are currently set:
cat /proc/sys/vm/dirty_bytes
cat /proc/sys/vm/dirty_background_bytes
Problems? Then undo it like this
3.1. Are you dissatisfied with the new write buffer behaviour? Undoing it is simple with this terminal command:sudo rm -v /etc/sysctl.d/8-writing.conf
Reboot and the write buffers should be default again.
Want more tips?
4. Do you want more tips and tweaks? There's a lot more of them on this website!For example:
Avoid 10 fatal mistakes
To the content of this website applies a Creative Commons license.
Back to the home page
Disclaimer