/sreadahead

Automatically exported from code.google.com/p/sreadahead

Primary LanguageCGNU General Public License v2.0GPL-2.0

sreadahead - a readahead implementation optimized for solid state devices

---

How it works
============

Overview
--------

Seek times are nearly zero on SSD devices. However, it still takes
significant time to actually to the IO and get all the data needed
to boot the system into memory.  Since at boot we can't do anything
else but wait on this IO, we lose a lot of time.

Sreadahead attempts to eliminate all this IO wait time at boot by
reading all the needed pages from disk and into memory before they
are actually needed by the boot process.

During an initial boot process, we monitor which parts of the disk
contents are actually used. At a later boot, we can then read all
that information at the first start of the boot process.

Initial boot
------------

The initial boot is when we don't know which content is needed during
the boot phase. During this boot process, we cannot accelerate the
boot process, but we can monitor the boot process and determine which
content is read from disk, and create a list of this content to use
for subsequent boots.

Sreadahead implements this phase by starting a kernel tracer which
monitors open() syscalls in the kernel and storing them in the debugfs
trace buffer.  After the system is done booting, sreadahead processes
the trace content and writes out a pack file that will be read during
subsequent boots.

Subsequent boots
----------------

If sreadahead finds a pack file on the system at boot time, it will
open this pack file and start fetching all the needed files listed
in this pack into memory. Sreadahead minimizes the reads to data that
is actually needed, and will not read entire files if strictly needed.

Resetting the pack file
-----------------------

At one point in time, the pack file will reflect an out-of-date system
state that is no longer accurate. This will degrade the effectiveness
of sreadahead, and at such a point in time, the pack file should be
deleted, so that a new pack can be automatically generated.


---

How distributions should implement sreadahead.

Distributions packaging sreadahead should implement three components:

1) starting sreadahead as early as possible;
2) (optional) at the end of the boot sequence, signal sreadahead to
   generate it's pack file;
3) once in a while, remove the pack file so it can be refreshed.

Typically, the following line would be added to the top of
the "rc.sysvinit" script, or equivalent, such as "rcS" or "single" init.d
script.

	/sbin/sreadahead

This will make sreadahead fork into the background and load an existing
readahead.packed file, and then doing it's work.

Sreadahead will generate the pack file after 15 seconds automatically.
If this is too late, one can send sreadahead a SIGUSR1 signal at
any time before this 15 seconds, to make sreadahead immediately stop
tracing and create a pack file.

To update the pack file, one can simply remove /etc/readahead.packed and
reboot the system.