PART 1: Profile Login Sequence
First, we need to ask readahead to monitor a login sequence and make note of all the files read during this period. Advanced users may point out that during bootup, there is a GRUB argument "profile" that causes Ubuntu to optimize bootup. We will need to essentially manually replicate what this boot option does, but save the output to a different file.
First, let's store our readahead list into a ~/.readahead directory.
Code:
mkdir ~/.readahead
Code:
sudo readahead-watch -o ~/.readahead/gnome.root /
after you are fully logged in, press CTRL+ALT+F1 to go back to your terminal, then run:
Code:
sudo killall readahead-watch
sudo chown jdong:jdong ~/.readahead -R
Code:
cat ~/.readahead/gnome.root | xargs -i ls -lk {} | sort -rn -k +5 | less
If you have home on a different partition as root, you should repeat Part 1 for each partition, replacing gnome.root with a different name, and replacing the mountpoint / with each interested mountpoint.
PART 2: Hooking this into the login sequence.
Next, we need to tell Ubuntu to do this readahead on every login. I am going to use /etc/X11/Xsession.d for this, but if you have another preferred way to execute things before everything loads, be my guest!
Create a file called /etc/X11/Xsession.d/00readahead and put this in it:
Code:
for list in ~/.readahead/*; do
readahead-list $list &
done
wait
"hang" at the orange screen while the disk works without much grinding, then once that is done the bootup should soar as if it were a fully cached login. This brings my login session to around 30 seconds, a notable improvement.
PART 3: Hook into bootup sequence
Often times, we don't log in immediately when the prompt comes up. We might be getting a cup of coffee, or an entire lab might be turned on before students arrive. It makes sense to cache a login as a part of bootup. Open up /etc/rc.local in your favorite text editor, and before the exit 0 statement, add:
Code:
for list in /home/jdong/.readahead/*; do
readahead-list $list
done
Now, reboot, and wait for all disk activity to stop before logging in. This
time, I get a login speed of 19 seconds.
You might have two common questions at this point:
1. How much time does it take to call readahead again on files that have been cached once already? About 0.05 seconds to call readahead on the same list a second time
2. How much overhead does it add to bootup if the background readahead was still going, and you tried to log in? About 2 seconds on my setup
CONCLUSION:
In my case, applying this readahead hack lead to a 10-second improvement in login speed in the worst-case scenario, and a remarkable doubling in login speed when the system idles at the login prompt for a few seconds.
This is a pretty appreciable improvement and it would be nice if a nicer version of this hack can be added to Ubuntu. The basic idea should be fairly simple to adapt to an /etc/readahead/readahead.gnome file representative of the default system and hooked by an Xsession.d script.
Potential follow-ups?
Many more applications come to mind as taking a long time to load while the disk grinds (Firefox? Openoffice? Eclipse?). You can use a procedure very similar to this to write a "wrapper script" that first performs a readahead-list call on a list, then call the application with the original arguments. I'd be interested to hear of any improvements gained by that method.
Undoing This Tip
Remove, remove, remove! Delete the ~/.readahead directory, delete /etc/X11/Xsession.d/00readahead, and delete the line you added to /etc/rc.local