Difference between revisions of "Improve boot performance"

From ArchWiki
Jump to: navigation, search
(disabling SSS)
m (Corrected spelling)
(18 intermediate revisions by 5 users not shown)
Line 8: Line 8:
 
{{Article summary end}}
 
{{Article summary end}}
  
==Preface==
 
 
Improving the boot performance of a system can provide reduced boot wait times and a means to learn more about how certain system files and scripts interact with one another. This article attempts to aggregate methods on how to improve the boot performance of an Arch Linux system.
 
Improving the boot performance of a system can provide reduced boot wait times and a means to learn more about how certain system files and scripts interact with one another. This article attempts to aggregate methods on how to improve the boot performance of an Arch Linux system.
 +
 +
== Identifying bottlenecks ==
 +
 +
The {{ic|systemd-analyze}} command can be used to show timing details about the boot process, including an svg plot showing units waiting for their dependencies. See {{ic|man systemd-analyze}} for details.
  
 
== Compiling a Custom Kernel ==
 
== Compiling a Custom Kernel ==
Line 15: Line 18:
 
To decrease boot time, a stripped kernel is a must.
 
To decrease boot time, a stripped kernel is a must.
 
[[Kernel Compilation|Read more about compiling a kernel.]]
 
[[Kernel Compilation|Read more about compiling a kernel.]]
 +
 +
== Early start for services ==
 +
 +
One central feature of systemd is [[D-Bus]] and socket activation. This causes services to be started when they are first accessed and is generally a good thing. However, if you know that a service (like [[UPower]]) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:
 +
 +
# systemctl enable upower
 +
 +
This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.
  
 
==Staggered spin-up==
 
==Staggered spin-up==
  
Some hardware implements [[Wikipedia:Spin-up#Staggered spin-up|staggered spin-up]], which causes the OS to probe ATA interfaces serially, which can spin up the drives one-by-one and reduce the peak power usage. This slows down the boot speed, and on most consumer hardware provides no benefits at all since the drives will already spin-in immediately when the power is turned on. To check if SSS is being used:
+
Some hardware implements [[Wikipedia:Spin-up#Staggered spin-up|staggered spin-up]], which causes the OS to probe ATA interfaces serially, which can spin up the drives one-by-one and reduce the peak power usage. This slows down the boot speed, and on most consumer hardware provides no benefits at all since the drives will already spin-up immediately when the power is turned on. To check if SSS is being used:
  
 
  $ dmesg | grep SSS
 
  $ dmesg | grep SSS
Line 24: Line 35:
 
If it wasn't used during boot, there will be no output.
 
If it wasn't used during boot, there will be no output.
  
To disable it, add {{ic|libahci.ignore_sss=1}} to the [[kernel line]].
+
To disable it, add {{ic|1=libahci.ignore_sss=1}} to the [[kernel line]].
 +
 
 +
==Filesystem Mounts==
 +
 
 +
Thanks to [[mkinitcpio]]'s {{ic|fsck}} hook, you can avoid a possibly costly remount of the root partition by changing {{ic|ro}} to {{ic|rw}} on the kernel line and removing it from {{ic|/etc/fstab}}. Options can be set with {{ic|1=rootflags=mount options...}} on the kernel line.
 +
 
 +
You can also remove API filesystems from {{ic|/etc/fstab}}, as systemd will mount them itself (see {{ic|pacman -Ql systemd <nowiki>|</nowiki> grep '\.mount$'}} for a list). It is not uncommon for users to have a /tmp entry carried over from sysvinit, but you may have noticed from the command above that systemd already takes care of this.  Ergo, it may be safely removed. 
 +
 
 +
Other filesystems like {{ic|/home}} can be mounted with custom mount units.  Adding {{ic|noauto,x-systemd.automount}} will buffer all access to that partition, and will fsck and mount it on first access, reducing the number of filesystems it must fsck/mount during the boot process.
 +
 
 +
==Initramfs==
 +
 
 +
As mentioned above, boot time can be decreased by slimming the kernel, thereby reducing the amount of data that must be loaded.  This is also true for your initramfs (result of mkinitcpio), as this is loaded immediately after the kernel, and takes care of recognizing your root filesystem and mounting it.  To boot, very little is actually needed and includes the storage bus, block device, and filesystem.  Falconindy (Dave Reisner) has begrudgingly created a [http://blog.falconindy.com/articles/optmizing-bootup-with-mkinitcpio.html short tutorial] on how to achieve this on his blog.
 +
 
 +
== Less output during boot ==
 +
 
 +
Change {{ic|verbose}} to {{ic|quiet}} on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.
  
 
== Additional Resources ==
 
== Additional Resources ==
* [[Arch Boot Process]]
+
* [[systemd]]
 
* [[e4rat]]
 
* [[e4rat]]
 
* [[udev]]
 
* [[udev]]
 
* [[Daemon]]
 
* [[Daemon]]
* [[rc.conf]]
 
 
* [[mkinitcpio]]
 
* [[mkinitcpio]]
 
* [[Maximizing Performance]]
 
* [[Maximizing Performance]]
* [[Systemd]] - An alternative init process
 
 
* [[Bootchart]] - A tool to assist in profiling the boot process
 
* [[Bootchart]] - A tool to assist in profiling the boot process
 
* [[Kexec]] A tool to reboot very quickly without waiting for the whole BIOS boot process to finish.
 
* [[Kexec]] A tool to reboot very quickly without waiting for the whole BIOS boot process to finish.

Revision as of 13:06, 22 November 2012

Template:Article summary start Template:Article summary text Template:Article summary end

Improving the boot performance of a system can provide reduced boot wait times and a means to learn more about how certain system files and scripts interact with one another. This article attempts to aggregate methods on how to improve the boot performance of an Arch Linux system.

Identifying bottlenecks

The systemd-analyze command can be used to show timing details about the boot process, including an svg plot showing units waiting for their dependencies. See man systemd-analyze for details.

Compiling a Custom Kernel

To decrease boot time, a stripped kernel is a must. Read more about compiling a kernel.

Early start for services

One central feature of systemd is D-Bus and socket activation. This causes services to be started when they are first accessed and is generally a good thing. However, if you know that a service (like UPower) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:

# systemctl enable upower

This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.

Staggered spin-up

Some hardware implements staggered spin-up, which causes the OS to probe ATA interfaces serially, which can spin up the drives one-by-one and reduce the peak power usage. This slows down the boot speed, and on most consumer hardware provides no benefits at all since the drives will already spin-up immediately when the power is turned on. To check if SSS is being used:

$ dmesg | grep SSS

If it wasn't used during boot, there will be no output.

To disable it, add libahci.ignore_sss=1 to the kernel line.

Filesystem Mounts

Thanks to mkinitcpio's fsck hook, you can avoid a possibly costly remount of the root partition by changing ro to rw on the kernel line and removing it from /etc/fstab. Options can be set with rootflags=mount options... on the kernel line.

You can also remove API filesystems from /etc/fstab, as systemd will mount them itself (see pacman -Ql systemd | grep '\.mount$' for a list). It is not uncommon for users to have a /tmp entry carried over from sysvinit, but you may have noticed from the command above that systemd already takes care of this. Ergo, it may be safely removed.

Other filesystems like /home can be mounted with custom mount units. Adding noauto,x-systemd.automount will buffer all access to that partition, and will fsck and mount it on first access, reducing the number of filesystems it must fsck/mount during the boot process.

Initramfs

As mentioned above, boot time can be decreased by slimming the kernel, thereby reducing the amount of data that must be loaded. This is also true for your initramfs (result of mkinitcpio), as this is loaded immediately after the kernel, and takes care of recognizing your root filesystem and mounting it. To boot, very little is actually needed and includes the storage bus, block device, and filesystem. Falconindy (Dave Reisner) has begrudgingly created a short tutorial on how to achieve this on his blog.

Less output during boot

Change verbose to quiet on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.

Additional Resources