First of all, take your time to measure the bottlenecks. You can check if your boot time is reasonable with the systemd-analyze
tool:
$ systemd-analyze
Startup finished in 3.104s (firmware) + 50ms (loader) + 914ms (kernel) + 1.409s (userspace) = 5.479s
And you can go deeper and check what takes most time to load from userspace passing the parameter blame
:
$ systemd-analyze blame
879ms psd-resync.service
601ms docker.service
319ms psd.service
285ms dev-sdb3.device
277ms wicd.service
276ms user@1000.service
135ms dev-sda2.swap
86ms systemd-journald.service
(...)
If you followed the guide religiously up to here, you are ready to dig into more command line stuff. Don't be scared, I won't brick your computer.
Decrease output during boot. Your system might spit out a ton of information during boot, but really it's too much and too fast to care. Go to your bootloader configuration (Google it) and append the following to the kernel command line:
quiet loglevel=3 splash
It removes most of the messages and sets the log level to display only error messages. You can read the boot output later using dmesg and journalctl.
Use faster disk schedulers. If you have a SSD, you can change the scheduler since the default one, CFQ, accounts for seek time of HDDs, which do not exist on SSD. I recommend the deadline scheduler, but the noop scheduler can be faster, especially on boot. To configure it, first create the file /etc/udev.d/60-scheduler.rules and insert:
# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sdb", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="<scheduler>"
Replacing sdb
with your disk (you can get its name with lsblk) and <scheduler>
with your favorite scheduler (e.g. my configuration. You can also replace the disk scheduler on boot, in which case there will be less overhead on boot times, adding the following to your kernel command line (like in the previous tip):
elevator=<scheduler>
This post has some benchmarks with cfq, deadline and noop and concludes native SATA queueing (called NCQ) probably does a slightly better job than kernel schedulers, so noop might have the best throughput. Replacing accordingly.
Finer tuning of /etc/fstab. First of all, you can use the noatime option on ext filesystems to prevent updating access time of files, thus not writing to the disk every time you touch a file (although touch still works). You can also specify discard on SSD partitions to activate TRIM (Google it), and commit=60 on SSD to sync to disk less frequently. For example, the full line for my / partition:
/dev/sdb3 / ext4 discard,noatime,commit=60 0 0
Addendum: this blog post claims that discard might have a negative impact. As always, your mileage may vary.
Use profile-sync-daemon. It is a great tool by @graysky2 to manage your browser profile on tmpfs, and it both increases performance and reduces disk wear. If supported, use it in "overlayfs" mode to minimize sync delay. To check if your system supports it, run the supplied script testoverlay.py, or run the following manually:
$ zgrep OVERLAY /proc/config.gz
On Fedora (kernels that do not export /proc/config.gz), you need to run the following:
$ grep OVERLAY /boot/config-$(uname -r)
And it should output either CONFIG_OVERLAY_FS=m
or CONFIG_OVERLAY_FS=y
, else you need to recompile your kernel. Then, edit /etc/psd.conf and uncomment USE_OVERLAYFS="yes"
. Reboot and check.
Replace bash by dash on boot. This is a tricky one. dash is a very slim alternative to bash and it can be used on boot to shave off some milliseconds. You need to redirect /usr/bin/sh to /usr/bin/dash if it was linked to bash. Check it first:
$ ls -og /usr/bin/sh
lrwxrwxrwx 1 4 Aug 14 03:03 /usr/bin/sh -> bash
So yes, it was linking bash. Go to /usr/bin and change it:
$ cd /usr/bin
$ ln -s dash sh
And you are good to go. Just remeber to update your scripts if they rely heavily on bash and are configured to use /usr/bin/sh.
Avoid swapping (or disable at all). Swap is a major bottleneck. You will not want to have it on SSD since it will wear out your SSD, and use a too big space if you have a small SSD like me, but HDD is very slow and when your system starts thrashing, it'll feel like hell.
Create a file under /etc/sysctl.d named 99-swappiness.conf and add the following:
# Do less swapping
vm.dirty_ratio = 6
vm.dirty_background_ratio = 3
vm.dirty_writeback_centisecs = 1500
Those configurations are responsible for controlling how often the kernel swaps (documentation), I use them on a 6 GB system with a 8 GB swap partition and this is a good value. Here's a good article on how swappiness works, I recommend the reading.
There's more to come.