Linux for little systems
an area Linux mainstream has been moving away from since Linus got a real job." To this end, he has released a tree called 2.6.0-test11-tiny which incorporates a large set of patches aimed at slimming down the kernel. It's worth a look as an expression of just what needs to be done if you want to run Linux on small systems.
So what's required? The -tiny patch includes, among others, the following:
- Building the kernel with the -Os compiler option, which
instructs gcc to optimize for size. This option results in a smaller
kernel; interestingly, there have also been reports that -Os
yields better performance on large systems as well, since the
resulting executable has better cache behavior.
- The 4k kernel stack patch cuts the runtime per-process memory use
significantly.
- Various patches shrink the size of internal data structures to their
minimum values. Target structures include the block and char device names hash
tables, the maximum number of swapfiles, the maximum number of
processes, the futex hash table, CRC lookup tables, and many others.
- For truly daring users, the -tiny kernel has an option to remove
printk() from the kernel entirely, along with its associated
buffers and most of the strings passed to printk(). The
space savings will be considerable; you just have to hope that the
kernel has nothing important to tell you. Strings for BUG()
and panic() calls can also be removed.
- Various subsystems which are not normally optional become so. With
the -tiny kernel, it is possible to configure out sysfs (which can
take a lot of run-time memory), asynchronous I/O,
/proc/kcore, ethtool support, core dump support, etc.
- Inline functions are heavily used in the kernel; they can improve performance, and, in some situations, the use of inline code is mandatory. Excessive use of inline functions can bloat the size of the kernel considerably, however. The -tiny kernel includes a patch which makes the compiler complain about the use of inline functions, allowing a size-conscious developer to find which ones are invoked most often.
There are almost 80 separate patches in all. Matt claims that his kernel,
when configured with a full networking stack, fits "comfortably" on a 4MB
box, which is, indeed, considered small these days. Matt has some
ambitious future plans, including cutting functionality out of the console
subsystem and (an idea that is sure to raise some eyebrows) making parts of
the kernel be pageable. It remains to be seen whether things will get that
far, but there is no doubt that making Linux work on small systems is a
worthy goal.
