oreilly.comSafari Books Online.Conferences.


Achieving Low-Latency Response Times Under Linux
Pages: 1, 2, 3, 4

Patching your own Linux kernel for low latency

You can easily prepare your own Linux system for low-latency performance. Simply apply one of the patches available from Andrew Morton's scheduling latency page or Ingo Molnar's low-latency patches page to a specific Linux kernel source package, then build and install the patched kernel. Patches are available for kernel versions from 2.2.10 through the 2.4.0-testN series: Be sure to choose the correct patch for your selected kernel version!

The patches address latencies introduced at a variety of points within the Linux kernel, including scheduling for interrupt requests (IRQ), the virtual memory system, and TCP socket connections. Versions up to 2.4.0-test9 are for uniprocessor systems only. Versions from 2.4.0-test10-pre3 onwards support multiprocessor systems, but I was unable to test those patches.

Patching a 2.2.x kernel should present no special problems. Simply apply the patch to the source package as detailed below, then rebuild and install the new kernel. Most mainstream distributions (e.g., Red Hat, Mandrake, Debian, SuSE) will have the required versions of the various support packages for compiling and installing the 2.2.x kernels. The situation is quite different for the 2.4.0-test kernels.

If you decide to patch a 2.4 kernel, I strongly advise reading Paul Winkler's excellent mini-HOWTO on upgrading to 2.4 with the low-latency patch and support for the ALSA driver. Building a 2.4 kernel is not especially difficult, but it requires some updated packages (described in /usr/src/linux/Documentation/Changes) and some special treatment with regard to the new modutils package (see below).

To those of you who have never built a Linux kernel, I say: Have no fear, the procedure is simplicity itself, especially with the graphic configuration utilities (the curses-based menuconfig and the Tk-based xconfig). But before you can build your kernel, you have to get its source package. Go to the Linux Kernel Archive and follow the instructions there on retrieving your desired sources. Once you have the source package on your local disk, become the root user (with su root), move it to /usr/src, and unpack it.

Note: You must be root to successfully execute the rest of the commands indicated in this section !

Here's how to unpack a gzipped source tarball:

cd /usr/src
tar xzvf linux-2.4.0-test9.tar.gz

And here's how to unpack a bzipped tarball:

cd /usr/src
tar xIvf linux-2.4.0-test9.tar.bz2

RPM users need only run this command:

rpm -ivh linux-2.4.0-test9.src.rpm

Whatever package you used, after unpacking you should have a new directory named /usr/src/linux-2.4.0-test9. The next two commands will create a link to that directory simply named /usr/src/linux:

rm /usr/src/linux
ln -s /usr/src/linux-2.4.0-testX /usr/src/linux

Now you can apply Andrew Morton's patch to the 2.4.0-test9 kernel sources. First, download the patch from Andrew's site and move it to /usr/src. Then follow these commands (while still root):

cd /usr/src/linux
patch -p1 < 2.4.0-test9-low-latency.patch

Now change to the source directory, then build and install your patched kernel:

cd /usr/src/linux
make mrproper
make config

You'll need to make a few specific option selections during the configuration process (make config, make menuconfig, or make xconfig). If you have an IDE/EIDE hard-disk, go to "ATA/IDE/MFM/RLL support" and select two options in the "IDE, ATA and ATAPI Block devices" section: Say "Yes" to "Generic PCI Bus-master DMA Support" and "Use PCI DMA by default when available." You must enable these options in order to use the hdparm utility to turn on DMA for your hard disks. Next, go to the "Character devices" section and enable "Enhanced Real-time Clock Support" for access to your computer's hardware clock. Finally, set up sound support. If you want to use the ALSA drivers, enable sound support as a module but don't select anything else; otherwise, select the modules that work for your particular soundcard.

Now you can proceed to build and install the kernel. While still in the /usr/src/linux directory, run these commands:

make depend
make bzImage
make install

At this point you may want to reconfigure LILO. Run vi /etc/lilo.conf, make whatever changes you prefer, and then run /sbin/lilo to update the loader.

The new modutils package must be compiled under the 2.4 kernel itself, so before you can build and install the new kernel modules you must reboot, then compile and install the new modutils. Return to /usr/src/linux and run the following commands:

make modules
make modules_install

Now reboot your system.

That's it, except for tuning your disks and heeding Andrew Morton's advice regarding proscribed activities (don't scroll the framebuffer console, don't switch consoles, don't run a server with hundreds of TCP connections per second, and so forth). As Andrew says, none are particularly "show-stoppers", but see his web site for more details.

Pages: 1, 2, 3, 4

Next Pagearrow

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: