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 performance by tweaking the system memory (RAM)
- 2. Speed up your wireless internet by disabling the WiFi power management
- 3. Improve writing to external media
- 4. Lots of RAM (at least 32 GB): put /tmp on tmpfs
- 5. A choice with a considerable price: setting your CPU to maximum performance mode
- 6. Want more tips?
Improve performance by tweaking the system memory (RAM)
1. You can improve the performance 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. In my how-to, you'll also learn how to set that maximum at 30 percent, which virtually "increases" your system memory a lot (don't increase that maximum above 40 percent, because higher maximum percentages might not leave enough RAM for uncompressed 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).
Note: If your hard disk is an SSD, there's an extra reason to use zswap. That's because too many disk write actions, like frequent disk swapping, reduce the lifespan of an SSD.
B. Now the how-to:
Switching on zswap involves heavy modification of the Grub bootloader settings. It's therefore sensible to make a copy of the current Grub settings first, aptly called grubcopy.
This makes it easy to roll back the changes you're about to make (in the unlikely case that you should ever wish to undo them). So proceed like this:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste the following blue command line into the terminal:
sudo cp -v /etc/default/grub /etc/default/grubcopy
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.
So far, so good. You can switch on zswap as follows (with superior fast compression, by means of lz4 and zsmalloc):
c. First you're going to add some boot parameters to the settings file of bootloader Grub. For that, 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 all, because it's far too easy to make a mistake:
sudo sed -i 's/splash/splash zswap.enabled=1 zswap.max_pool_percent=30 zswap.zpool=zsmalloc zswap.compressor=lz4/' /etc/default/grub
Press Enter.
d. Copy/paste the following command line into the terminal, in order to update Grub with the new settings:
sudo update-grub
Press Enter.
(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 can'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 of all installed kernels with the new settings (use copy/paste to transfer the command into the terminal!):
sudo update-initramfs -uk all
Press Enter. This might take a long time to complete!
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 maximally uses, can be checked with the following command:
cat /sys/module/zswap/parameters/max_pool_percent
It should report 30. As said already: don't increase that above 40, because higher maximum percentages might have negative consequences.
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:a. zswap taxes the CPU less than zRam. Sometimes much less: especially with desktop use the difference can be significant.
b. 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).A. First some background information:
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.
B. Now the how-to:
Now the how-to for setting the swappiness to a more reasonable level for a computer with a weak CPU and an enabled zswap:
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. In Mint this has changed: you'll see asterisks when you type. 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.
Increasing the size of the available swap on the hard disk
1.3. In Linux Mint and Ubuntu, the virtual memory on the hard disk is a swap file instead of a dedicated swap partition (except when LVM is used). This swap file is, unsurprisingly, called swapfile.By default its size is 2 GiB. Which is fine for most use cases, especially so if you've enabled zswap (see item 1.1 on this page). Still, a few people may need a bigger swap file. If you're one of them, read on.
You can change the size of this swap file in the following way:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. First you're going to check the presence and the size of the current swap file. Copy/paste the following blue command line into the terminal, for which no root permissions are needed:
swapon --show
Press Enter.
It'll probably tell you that there's indeed already a swap file and that its size is currently set at 2 G (2 GiB).
c. Now you need to disable the current swap file. Copy/paste the following blue command line into the terminal:
sudo swapoff /swapfile
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.
d. Next, you can delete the current swapfile. Copy/paste the following blue command line into the terminal:
sudo rm -v /swapfile
Press Enter.
e. Next step: create a new swap file of the desired size. For this, you're going to use the application dd to make sure a file without "holes" is created. Using the correct parameters requires a bit of calculation.
An example makes it easy: let's suppose you want to make an 8 GiB swap file. For that, you'll need to calculate the number of MiBs involved: 8 x 1024 MiB = 8192 MiB.
Copy/paste the following blue command line into the terminal, in order to create an 8 GiB swap file:
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
Press Enter. This might take some time to complete, so wait patiently until it's finished!
f. Assign the swap file read/write permissions for root only (not strictly needed, but it tightens security), with this terminal command (use copy/paste):
sudo chmod -v 600 /swapfile
Press Enter.
g. Format the file as swap, with this terminal command (use copy/paste):
sudo mkswap --verbose /swapfile
Press Enter.
h. The swap file will be activated automatically on the next reboot. So reboot your computer.
i. After the reboot, you can check the size of the new swap file with the following terminal command, for which no root permissions are needed:
swapon --show
Press Enter. If you've applied the 8 GiB in the example, this should now report that its size is 8 G.
(This is a simplified version of the excellent how-to written by vanadium on Askubuntu)
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 (don't worry: you'll disable it for that chipset alone, not systemwide!).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 is this:
a. First you need to find out whether Ubuntu applies power management to your WiFi chipset at all. Proceed like this:
- Launch a terminal window.
(You can launch a terminal window like this: *Click*)
- 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:
b. Now the actual tweak. 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. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
c. Reboot your computer.
d. 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 relative maximum of 20 percent 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 relative maximum of 10 percent of your RAM.
Now let's proceed to replace those two ratios (relative sizes) by more sensible absolute maximum sizes.
d. First the buffer for the dirty_bites:
In order to prevent typos, copy/paste this long blue line into the terminal, which sets an absolute maximum size of 500 MB:
echo "vm.dirty_bytes=524288000" | 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 buffer for the dirty_background_bytes:
Copy/paste the following blue command line into the terminal, which sets an absolute maximum size of 250 MB:
echo "vm.dirty_background_bytes=262144000" | 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 previously at steps b and c: both commands should return a 0 now.
These two commands should return the maximum amounts 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 buffer maximums should be default again.
Lots of RAM (at least 32 GB): put /tmp on tmpfs
4. Does your system have lots of RAM memory? If it has at least 32 GB, then you can probably speed up your system a bit by placing /tmp on a tmpfs partition. Which means, translated into ordinary language: you bring about that temporary files will not be placed on the hard disk anymore, but on a virtual RAM disk instead.In certain cases this will not only increase overall performance, but also reduce boot time.
Note: In general, do not apply this on systems with less RAM than 32 GB! Because then this tweak might not make them faster, but (much) slower.
This is how to create a tmpfs partition:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste this blue command line into the terminal (it's one line!):
sudo cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/
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.
c. Then copy/paste this command into the terminal:
sudo systemctl enable tmp.mount
Press Enter.
d. Reboot your computer.
e. After the reboot: check whether it works, with this terminal command:
systemctl status tmp.mount
By default, a tmpfs partition has its maximum size set to half your total RAM. The actual memory consumption depends on how much you fill it up, as a tmpfs partition doesn't consume any memory until it is actually needed.
It may be useful to set a lower hard cap on its size, for example 4 GB, in order to make sure that you'll always have enough RAM for general use. For doing that, see the next item (4.1).
Changing the default maximum size of tmpfs
4.1. As said: by default, a tmpfs partition has its maximum size set to half your total RAM. The actual memory consumption depends on how much you fill it up, as a tmpfs partition doesn't consume any memory until it is actually needed.If you wish to set another maximum size for tmpfs than the default, you can do that by changing the size option defined in /etc/systemd/system/tmp.mount. For example, if you wish to set the maximum size to 4 Gigabyte, copy/paste this line into the terminal:
sudo sed -i 's/size=50%%/size=4G/' /etc/systemd/system/tmp.mount
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.
Afterwards, reboot your computer.
After the reboot you can check whether the modification has succeeded, by executing this terminal command:
df -h /tmp
How to undo tmpfs
4.2. Do you wish to undo tmpfs? Then copy/paste this line into the terminal:sudo rm -v /etc/systemd/system/tmp.mount
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.
Afterwards, reboot your computer.
A choice with a considerable price: setting your CPU to maximum performance mode
5. There are ways to change the CPU performance mode permanently to the maximum. Note that there's a considerable price attached to that: a steep increase in power consumption! So don't do this as a matter of course, but first consider this carefully....Anyway, these are your options:
Temporary change: how to toggle the performance mode of your CPU with cpupower-gui (session-only)
5.1. There's a nifty tool called cpupower-gui, for temporarily toggling the performance mode of your CPU. Temporarily, because the performance mode will automatically revert to its default after a reboot. This is how to install and use it:a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste the following command line into the terminal:
sudo apt-get install cpupower-gui
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.
c. Then launch cpupower-gui from the menu and tweak to your heart's delight. It lets you set the scaling governor either individually for each CPU core (sigh.... Why? And why is it the bloody default?), or for all of them at once (which is of course what you always want). So make sure you flip the switch for the option called All CPUs.
The default governor will probably be either schedutil or powersave, both of which are a good compromise for most users. You can set it to performance, which will ensure that your CPU will always run at maximal speed (and at maximal power consumption!). At least during your current session; this setting won't survive a reboot.
Beware what you set it to! This can cause a sizeable increase in power consumption, which is of course not a small thing: that's why I only recommend to select performance when you really need it (e.g. for gaming). And only for the duration of that need, so temporarily.
To check what your CPU cores are currently set to, utilize this terminal command (copy/paste it into the terminal and press Enter):
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Permanent change: how to use powerprofilesctl to toggle the performance mode of your CPU (persistent)
5.2. There's also a tool for changing the CPU performance mode permanently, namely the powerprofilesctl tool.Beware what you set it to! This can cause a sizeable increase in power consumption, which is of course not a small thing: that's why I only recommend to select performance when you really need it (e.g. for gaming). And only for the duration of that need, so temporarily.
You can use it like this:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste the following command line into the terminal, in order to find out what's the current mode:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Press Enter.
This should tell you what performance mode your CPU cores are currently set to (probably powersave).
c. Then you're going to install a terminal application. For this, copy/paste the following command line into the terminal:
sudo apt-get install power-profiles-daemon
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.
d. Now you're going to see what the available settings in powerprofilesctl are for your CPU:
powerprofilesctl list
Press Enter.
One of the available settings will probably be performance, which (unsurprisingly) will give you the best performance but also the highest power consumption. But it might also be that your only options are balanced and power-saver (power-saver is the annoyingly deviant name that powerprofilesctl uses for powersave). Your currently active setting will be marked with an asterisk.
e. Now you're going to set another performance mode. An example makes it easy. Let's say that you wish to set your CPU to everlasting maximal performance, aptly called performance (when available), instead of the probable default power-saver. For that, copy/paste the following command line into the terminal:
powerprofilesctl set performance
Press Enter.
f. Finally, check whether the change has been successful, by executing this terminal command again:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Permanent change: how to use powerprofilesctl to switch back to the default CPU governor powersave (persistent)
5.2.1. Do you want to re-establish the default CPU governor powersave again? Reverting back to powersave is easy, but for unclear reasons (sigh....) the name of the setting in powerprofilesctl is a bit different, namely power-saver. So this is the command you need to execute then:powerprofilesctl set power-saver
Press Enter.
Then check whether the change has been successful, by executing this terminal command:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Want more tips?
6. 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