Readahead
From ArchWiki
Contents |
Credit Where Credit is Due
This entire wiki page is based on and uses content from Peterw’s blog wherein he has made an excellent guide for readahead on archlinux. Find his original blog posting here: Install readahead-list on ArchLinux
In case his blog goes down, a copy of it has been included [at the end of this wiki page].
Introduction
Readahead is a tool that can cache files before needed and help you accelerating program loading. Readahead-list is a tool that helps you building a list of applications while your system loads. This can then be used by readahead.
This wiki page describes using Readahead in two parts: 1) Bootup - all the files/daemons, etc. that load during your system's boot process. 2) Desktop - all the files that get called when you log into your desktop (gdm, kdm, etc.).
Note that you don't need to run Readahead in both modes if you don't want to do so.
Using Readahead on Arch Linux
Installing Readahead
There is a nice package in the AUR based on Peterw's instructions. [Link to page]. At the time of writing this wiki page (03-May-09) the author of the original PKGBUILD (mtorromeo) has yet to add some additional steps to his PKGBUILD. I recommend that you use the PKGBUILD by 'whaevr' that you can find in the comments section. I have pasted it below:
# Contributor: Daenyth <Daenyth+Arch AT gmail DOT com> pkgname=readahead-list pkgver=0.20050517.0220 pkgrel=1 pkgdesc="readahead-list allows users to load files into the page cache before they are needed, to accelerate program loading" arch=("i686" "x86_64") url="http://freshmeat.net/projects/readahead-list/" license=('GPL') depends=("gcc-libs") source=(https://launchpad.net/ubuntu/intrepid/+source/${pkgname}/1:${pkgver}-1ubuntu4/+files/${pkgname}_${pkgver}.orig.tar.gz https://launchpad.net/ubuntu/intrepid/+source/${pkgname}/1:${pkgver}-1ubuntu4/+files/${pkgname}_${pkgver}-1ubuntu4.diff.gz) md5sums=('a67ec6f8805ff67d3ff97570fa5be5ae' '4f7ee59aaf6a6b501f7e5da1aa7418b9') build() { mkdir ${pkgdir}/etc mkdir ${pkgdir}/etc/readahead touch ${pkgdir}/etc/readahead/boot touch ${pkgdir}/etc/readahead/desktop mkdir -p ${pkgdir}/etc/rc.d/ touch ${pkgdir}/etc/rc.d/readahead-list-desktop touch ${pkgdir}/etc/rc.d/readahead-watch-desktop patch -p1 < ${pkgname}_${pkgver}-1ubuntu4.diff cd "$srcdir/$pkgname-$pkgver" for pat in ../debian/patches/*.patch; do patch -p1 < $pat done ./configure --prefix=/usr --mandir=/usr/share/man make || return 1 make DESTDIR="$pkgdir/" install }
This page assumes that you are familiar with the PKGBUILD process. You can simply use the PKGBUILD provided above to generate your package.
$ makepkg -s
Now install it with pacman (the example below was generated with the x86_64 version of Arch):
# pacman -U readahead-list-0.20050517.0220-1-x86_64.pkg.tar.gz
Edit the empty file /etc/rc.d/readahead-watch-desktop to contain the following:
#!/bin/bash /usr/sbin/readahead-watch -o /etc/readahead/desktop
Edit the other empty file /etc/rc.d/readahead-list-desktop:
#!/bin/bash /usr/sbin/readahead-list /etc/readahead/desktop
Now make them both executable:
# chmod a+x /etc/rc.d/readahead-watch-desktop /etc/rc.d/readahead-list-desktop
Profiling Your System
The Boot Process
Following the instructions in Peterw's blog, first bang-out the daemon in your daemons array for gdm or kde (or whatever WM you're using). In my example, it's gdm:
DAEMONS=(preload syslog-ng network netfs @crond @alsa @hal @fam @powernowd cups !gdm)
Now edit your /etc/rc.sysinit adding the following lines to profile your system's boot process between the top and the part that starts with ". /etc/rc.conf" like this:
#!/bin/bash # # /etc/rc.sysinit # # uncomment the next three lines to profile the boot process # be sure you disable gdm from starting before you reboot # add a bang character to gdm in the daemons array in rc.conf echo "starting readahead-watch..." /usr/sbin/readahead-watch -o /etc/readahead/boot echo "readahead is watching..." . /etc/rc.conf . /etc/rc.d/functions
Now reboot your machine and allow the boot profiling to take place. It should take extra time (1-2 min is normal). When the system does finally displays your text login screen (remember you disabled your WM), login and manually kill the PID that readahead is using. To see the PID, simply execute the following:
# ps ax | grep readahead
This will return the PID which you are to kill as root like so:
# kill PID_GOES_HERE
This just generated your boot profile located in /etc/readahead/boot
Now comment out the lines in your /etc/rc.sysinit to prevent the profiling again:
# echo "starting readahead-watch..." # /usr/sbin/readahead-watch -o /etc/readahead/boot # echo "readahead is watching..."
Remove the bang from your WM in your daemons array in /etc/rc.conf
DAEMONS=(preload syslog-ng network netfs @crond @alsa @hal @fam @powernowd cups gdm)
The Desktop Process
Just as you did profiling the boot process, you will now profile the desktop process. First add the the daemon readahead-watch-desktop to your daemons array in /etc/rc.conf. Place it before your WM (gdm in my case) like this:
DAEMONS=(preload syslog-ng network netfs @crond @alsa @hal @fam @powernowd cups readahead-watch-desktop gdm)
Now reboot your system again and login via graphical login. It is recommended that you launch whatever programs you want included in the profile such as your web browser, email program, whatever you use on a regular basis. When you're ready to stop the profiling process, either open a shell (remember this action will also be included in the desktop profile) or if you don't want the shell getting profiled for some reason, drop into another tty (Ctrl+Alt+F3 for example), login there and again kill the PID that readahead is using as you have done with the boot profiling:
# ps ax | grep readahead
This will return the PID which you are to kill as root like so:
# kill PID_GOES_HERE
This generated your desktop profile located in /etc/readahead/desktop
Enabling Readahead on Your Profiled System
Now that you have generated both the /etc/readahead/boot and /etc/readahead/desktop it's time to activate them. The easiest place to start readahead for your boot process is again in the /etc/rc.sysinit file. Add a line to it below the ones you commented out for the profiling process like this (new lines are shown in bold text):
#!/bin/bash # # /etc/rc.sysinit # # uncomment the next threee lines to profile the boot process # be sure you disable gdm from starting before you reboot # add a bang character to gdm in the daemons array in rc.conf # echo "starting readahead-watch..." # /usr/sbin/readahead-watch -o /etc/readahead/boot # echo "readahead is watching..." # this starts readahead with your boot profile /usr/sbin/readahead-list /etc/readahead/boot . /etc/rc.conf . /etc/rc.d/functions
Now add the readahead-list-desktop daemon to your daemons array BEFORE THE GRAPHICAL STARTUP (gdm in my case) in /etc/rc.conf it is recommended that you background it (prefix it with an @ symbol):
DAEMONS=(preload syslog-ng network netfs @crond @alsa @hal @fam @powernowd cups @readahead-list-desktop gdm)
Now you can reboot and enjoy readahead!
Periodically Update Your Boot and Desktop Profiles
If you make major changes to your boot or desktop processes, repeat the above profiling steps to keep them current in readahead's lists. You get the idea.
User Experiences with Readahead
Please post your experiences with readahead in this section. Include some hardware specs to give others an idea what kind of system is being used.
Comment 1
I installed readhead via the package mentioned above in the AUR and followed the instructions for profiling my system from Peter's blog. Here is a summary of the results; times were measured using bootchart:
Before doing anything: 26 sec Using only the boot profile: 25 sec Using only the desktop profile: 20 sec Using both the boot and desktop profile: 27 sec
Hardware specs: X3360 @ 3.40 GHz, 8 gigs of DDR2 @ 1,000 MHz, HDDs are both Seagate SATA-II 640 gig 7200.11 series.
Copy of Peterw's Blog Entry on Readahead
Again, you can read Peterw's Blog from its [native URL] but for posterity's sake, I have taken the liberty of pasting it below in case his server goes down or whatever.
Install readahead-list on ArchLinux
According to freshmeat:
"Readahead-list allows users to load files into the page cache before they are needed, to accelerate program loading. It improves on the existing readahead by taking the name of a file with the items to load, instead of requiring the arguments being passed as parameters. Additionally, it contains a tool (filelist-order) to optimize the order of the file list in several possible ways."
I am picking the source file from ubuntu/debian because it also includes a tool to “record filesystem events” and generate the list of files to load. Grab the source and the diff here from launchpad
extract it:
gzip -d readahead-list*.diff.gz tar -xzf readahead-list*.tar.gz
patch it:
patch -p1 < readahead-list*.diff cd readahead-list*/
Be sure to apply all the patches in the patches directory:
patch -p1 < ../debian/patches/05* patch -p1 < ../debian/patches/10* patch -p1 < ../debian/patches/50* patch -p1 < ../debian/patches/51*
compile:
#please choose the appropriate prefix: ./configure --prefix=/usr make #(as root) make install
Hopefully everything is compiled. There might be some error messages, but as long as the process did not error out, everything should be ok.
Now for the system setup. The way I think it ought to go is record the startup in two parts, the boot, and the desktop. The boot part will record and load all files related to general startup. The desktop part will load everything from after the system startup (including graphical login manager) to when the default session type is loaded (i.e. kde desktop). The following files and directories need to be created:
#technically, this contents might make this directory better place in /var but /etc will do mkdir /etc/readahead touch /etc/readahead/boot touch /etc/readahead/desktop #the following can be duplicated for each section, if you want it handled by rc touch /etc/rc.d/readahead-list-desktop touch /etc/rc.d/readahead-watch-desktop
To record the first part, we need to stop the graphical login manager from loading, so we login via the command line interface. This is done by editing the DAEMONS section of /etc/rc.conf by adding an ! before kdm, or gdm, etc. Then we need to start the record as early as we can in the boot process. This is technically done by creating a script, and then using the init= parameter on the kernel line of grub. For this tutorial, we will put the lines of code in /etc/rc.sysint. Insert some lines to make the top of the file look like this:
#!/bin/bash # # /etc/rc.sysinit # echo "starting readahead-watch..." /usr/sbin/readahead-watch -o /etc/readahead/boot echo "readahead is watching..." #echo "reading files..." #/usr/sbin/readahead-list /etc/readahead/boot & . /etc/rc.conf . /etc/rc.d/functions
Line 7 is the import one above. This will record all files loaded after the command is run, on any device and save the list to the specified file. After you login, to kill the process run:
ps ax | grep readahead #as root kill $PID
The boot section has now been recorded. Now the files /etc/rc.d/ will look like:
#!/bin/bash #readahead-watch-desktop /usr/sbin/readahead-watch -o /etc/readahead/desktop
#!/bin/bash #readahead-list-desktop /usr/sbin/readahead-list /etc/readahead/desktop
With these files in place, edit the daemon section in the rc.conf to include readahead-watch-desktop before the login manager, and do NOT background it. Reboot the computer, and kill the process in the same was as before after you have logged in (Note: this will record a terminal instance in the file. You can avoid this by hitting something like ALT-F6 to login textually). After you have stopped the recording, edit the daemons section to instead start readahead-list-desktop.
Here are my results.
The results are kind of dismal in the pure timing end, as observable by bootchart only two seconds shorter. But I have never seen my desktop load faster! If I didn’t have the resource heavy services such as klipper, guidance-power-manager or network-manager it would load in a blink.
Play around with the placement of the readahead-list command, just make sure you start a recording from the same place. This placement of the rc.d file is kind of cheating, because it relies on the lag in response time of the user login to load files in the background, but it still makes a heck of a difference. Also, if you always start up firefox or something when you login, record that too and it will start a little faster.