Linux Format - UK (2019-12)

(Antfer) #1
36 LXF257 December 2019 http://www.linuxformat.com

Lightweight Linux


our distro should be in quite a good condition
if you’ve followed the steps on the previous
pages. The good news is that there’s still
scope for improvement. On the downside, however, the
tricks from here on are more involved and come with a
disclaimer: if applied recklessly, they can have serious
repercussions on your installation.

Track stragglers
In addition to startup apps (which we’ve already pruned
earlier in the feature), a typical Linux distro also runs a
large number of services. You don’t need all of them and
starting them every time you boot your computer
wastes resources. Even if you have the resources to
spare, remember that services can be exploited and
running ones you don’t need is, in effect, an additional
security risk.
But before you axe them, it’s best to get a picture of
what’s happening while your distro boots up. Bootchart
is a handy utility that enables you to profile your Linux
boot process and measure the loading times of different
services. In fact it’s so useful that it’s now rolled inside
Systemd. To use it, fire up a terminal and enter systemd-
analyze time to reveal the time taken to boot your
machine. Similarly, systemd-analyze blame lists all
running units, ordered by the time they took to start.
To generate an image of the boot process, type
systemd-analyze plot > boot.svg. From this image you
can find all active processes and remove the ones you
don’t need. For example, if you print occasionally, you
can disable CUPS from starting at boot time. The image
also helps you to identify processes that take control of
all resources and force the others to wait, effectively
blocking the boot process. Now that you understand
how your computer boots up and the services that are
started, it’s time to tailor the boot process to your
requirements and shave off some time. Use systemctl
disable to turn off any service that you don’t require.

Wondering why your RAM-laden machine is still slow
off the blocks? Chances are it’s because your distro is
still using swap space on the hard disk, which has a far
slower read/write speed than RAM.
If your system has enough memory to handle
whatever you throw at it, you should minimise the use
of swap space. The swappiness parameter governs the
kernel’s ability to move processes out of physical
memory and onto the swap disk, which in certain
situations can increase application response times.
The command cat /proc/sys/vm/swappiness will
display the current level of swappiness set by your distro.
Ubuntu’s default swappiness value is 60. The parameter
will accept any value between 0 and 100. Set a lower
value if you want to avoid swapping-out processes. If
you set a value of 0 the kernel will stop swapping
processes out of physical memory to the swap partition
for as long as possible. Ubuntu’s default value means
that the kernel will begin swapping when your computer
uses up 40 per cent of the physical RAM.
Use the sudo sysctl vm.swappiness=10 command to
temporarily change the swappiness value to 10, which
tells the kernel to only use swap space when 90 per cent
or more of the RAM is used up. This change will be lost
when you restart the computer. If you notice a spring in
the step of your distro, you can preserve the value by
editing the /etc/sysctl.conf file in a text editor. Look
for the vm.swappiness parameter in the file and change
its value. If it doesn’t exist, you can add it at the end of
the file.

Fabricate memory
On the other hand, if your problem is a lack of RAM,
you can make better use of it with the help of your fast
processor. In our experience this works best with top-of-
the-line netbooks and virtual machines. On such
computers you can use the zRAM kernel module to
create a device in RAM and compress it. Thanks to this
compression factor you effectively increase your RAM.
When you use zRAM, you are taxing your processor
since it will have to constantly compress and
decompress memory. Even with this handicap, the use
of zRAM turns out to be more efficient and quicker than
swapping memory to a hard drive.
On Ubuntu, you can install the module with sudo apt
install zram-config and then reboot your computer. The
package installs a script to run it as a service and
doesn’t require any configuration. Use the cat /proc/
swaps command to check if it’s online. If zRAM is
working perfectly, the command should list one or more
/dev/zram partitions. If you find that your processor is
unable to cope with the added load and your computer’s
usability has taken a hit as a result, you can disable and
remove the zRAM module with sudo apt autoremove
zram-config.

Y


You can use the
systemd bootmap
to see the order in
which services start
and the time they
spent initialising.

ACCELERATE CORE


COMPONENTS


LEVEL 3


36 LXF257December 2019 3332Decmbr 019425 1

Lightweight Linux


our distro should be in quite a good condition
if you’ve followed the steps on the previous
pages. The good news is that there’s still
scopefor improvement. On the downside, however, the
tricks from here on are more involved and come with a
disclaimer: if applied recklessly, they can have serious
repercussions on your installation.

Track stragglers
In addition to startup apps (which we’ve already pruned
earlier in the feature), a typical Linux distro also runs a
large number of services. You don’t need all of them and
starting them every time you boot your computer
wastes resources. Even if you have the resources to
spare, remember that services can be exploited and
running ones you don’t need is, in effect, an additional
security risk.
But before you axe them, it’s best to get a picture of
what’s happening while your distro boots up. Bootchart
is a handy utility that enables you to profile your Linux
boot process and measure the loading times of different
services. In fact it’s so useful that it’s now rolled inside
Systemd. To use it, fire up a terminal and enter systemd-
analyze time to reveal the time taken to boot your
machine. Similarly, systemd-analyze blame lists all
running units, ordered by the time they took to start.
To generate an image of the boot process, type
systemd-analyze plot > boot.svg. From this image you
can find all active processes and remove the ones you
don’t need. For example, if you print occasionally, you
can disable CUPS from starting at boot time. The image
also helps you to identify processes that take control of
all resources and force the others to wait, effectively
blocking the boot process. Now that you understand
how your computer boots up and the services that are
started, it’s time to tailor the boot process to your
requirements and shave off some time. Use systemctl
disable to turn off any service that you don’t require.

Wondering why your RAM-laden machine is still slow
off the blocks? Chances are it’s because your distro is
still using swap space on the hard disk, which has a far
slower read/write speed than RAM.
If your system has enough memory to handle
whatever you throw at it, you should minimise the use
of swap space. The swappiness parameter governs the
kernel’s ability to move processes out of physical
memory and onto the swap disk, which in certain
situations can increase application response times.
The command cat /proc/sys/vm/swappiness will
display the current level of swappiness set by your distro.
Ubuntu’s default swappiness value is 60. The parameter
will accept any value between 0 and 100. Set a lower
value if you want to avoid swapping-out processes. If
you set a value of 0 the kernel will stop swapping
processes out of physical memory to the swap partition
for as long as possible. Ubuntu’s default value means
that the kernel will begin swapping when your computer
uses up 40 per cent of the physical RAM.
Use the sudo sysctl vm.swappiness=10 command to
temporarily change the swappiness value to 10, which
tells the kernel to only use swap space when 90 per cent
or more of the RAM is used up. This change will be lost
when you restart the computer. If you notice a spring in
the step of your distro, you can preserve the value by
editing the /etc/sysctl.conf file in a text editor. Look
for the vm.swappiness parameter in the file and change
its value. If it doesn’t exist, you can add it at the end of
the file.

Fabricate memory
On the other hand, if your problem is a lack of RAM,
you can make better use of it with the help of your fast
processor. In our experience this works best with top-of-
the-line netbooks and virtual machines. On such
computers you can use the zRAM kernel module to
create a device in RAM and compress it. Thanks to this
compression factor you effectively increase your RAM.
When you use zRAM, you are taxing your processor
since it will have to constantly compress and
decompress memory. Even with this handicap, the use
of zRAM turns out to be more efficient and quicker than
swapping memory to a hard drive.
On Ubuntu, you can install the module with sudo apt
install zram-config and then reboot your computer. The
package installs a script to run it as a service and
doesn’t require any configuration. Use the cat /proc/
swaps command to check if it’s online. If zRAM is
working perfectly, the command should list one or more
/dev/zram partitions. If you find that your processor is
unable to cope with the added load and your computer’s
usability has taken a hit as a result, you can disable and
remove the zRAM module with sudo apt autoremove
zram-config.

Y


You can use the
systemd bootmap
to see the order in
which services start
and the time they
spent initialising.

ACCELERATE CORE


COMPONENTS


LEVEL 3

Free download pdf