Pages

Monday, October 4, 2010

Boot time tuning chapter 5th: Timing

Hi everybody,

as promised I'm here again with another chapter about boot tuning. Last time I made a little step back to improve my system reliability, today I'm moving forth again, with no renounce of course!

The solution I was trying it is very customizable, but I'm going to explain as well as I can how can you achieve the same degree of optimization on your box. Our requisites are a text editor, bootchart and if you are running gentoo we will use eselect tool. If you don't have bootchart you can find a guide how to install it here or googling around.

As always I suggest you to give up if you don't know what you're doing, unless you try it on a "testbox". I don't take liability of any consequence.

First of all we need to put your inittab to native form. So
sudo nano /etc/inittab
and throw away any previous changes, it should have no "&" and no "once" either: "once" has to be replaced with "wait", so we will have a default system init. To prove it is alright we will use an eselect tool, you should have it installed by default. If you have a very fast boot already (I mean under 20s) you might want to improve sampling frequency to better see processes. Just edit the conf file:
sudo nano /etc/bootchartd.conf
and edit the proper line:
SAMPLE_PERIOD=0.1 or even 0.05

Now we are ready to trace all processes and services, so reboot your system in bootchart mode, and once finished, open the graph. Default inittab launches 3 blocks in sequence, waiting for the previous to finish before starting the following. You should be able to identify those blocks, they are the famous "sysinit", "boot" and "default" runlevels, each with its own rc and processes. I took a picture of my default bootchart and made three boxes over it (black, red and blue) for sysinit, boot and default.

Now what you want to do is to squeeze those blocks and make them run overlapped as far as it does not create troubles to your boot. So we are going to introduce a script, whose aim is to control the boot timing.

Sound so silly but it makes the job flawlessly:

#!/bin/sh
sleep $1
/sbin/rc boot &
sleep $2

let's save it as /sbin/trigger and give it the rights to be executed.
Consider your boot graph and take note of the time duration of sysinit block and boot block. They will be our starting values of $1 and $2 (in this order). Now move to your inittab and let's tweak it: we need to put again the & in the sysinit line
si::sysinit:/sbin/rc sysinit &
and we should edit the boot line, changing it to
rc::wait:/sbin/trigger [sysinittime] [boottime]
Done.

The procedure now sounds repetitive but can lead to great results. First of all reboot and check if boot time is approx the same as before, but more important, run
sudo eselect rc show all
to see if all rc are started and running as they should.
Now try to reduce both times by a 15% and reboot. Check graph, check time, check services with eselect. If alright move on, and reduce 20% etc. Here is my new boot chart, with blocks highlighted. As you can see time has passed to 13s to 10s with no reliability problem.

Looking at future, you can notice that after default runlevel block there is a "low-grass plain". Actually my desktop comes out after 6-7 seconds, then system waits for his messiah, takes a coffee cup, makes some stretching... I dunno... I'm trying to find out why it takes so much to do anything and then suddenly launch the session-startup scripts and whatever.

Gonna ask Sherlock Holmes and tell you.

Stay tuned!

No comments:

Post a Comment