Linux Tiny Notes

Here are some miscellaneous notes on using Linux tiny. I wrote this up really quickly while I was integrating Linux-tiny into a 2.6.11 kernel and doing some size testing.

I'm providing these raw notes so that others might benefit from my experience.

Patch Notes
Here are some notes on individual linux-tiny sub-patches:

devlist.patch

 * replaces device allocation code, don't know size impact, is NOT conditional
 * maybe should add, but don't know - looks dangerous

core-small.patch - CONFIG_CORE_SMALL
Add CONFIG_CORE_SMALL Kconfig option

CONFIG_CORE_SMALL patches
These are hash table and data structure static size adjustments
 * pid-max.patch
 * user-hash.patch
 * futex-queues.patch
 * tvec_bases.patch
 * con_buf.patch

config-net-small.patch
Add CONFIG_NET_SMALL Kconfig option

CONFIG_NET_SMALL patches
These tune some net-related data sizes
 * cache_defer_hash.patch
 * unix_socket_table.patch
 * inet_protos.patch
 * flow-cache-small.patch

Miscellanoues patches

 * small-8023.patch - what does this do?
 * tg3-oops.patch - what does this do?

*inline patches

 * just make big routines not inline (unconditionally)
 * Seems pretty safe to me.

06-crypto-sleep.patch

 * looks scary - not immediately obvious from patch how it saves size.

# measurement bits
Looks like very harmless stuff to instrument kernel for mem debugging, and give tools for parsing stuff.


 * kmalloc-accounting.patch - keep track of kmallocs
 * audit-bootmem - print out all bootmem allocations
 * bloat-o-meter.patch - provides bloat-o-meter program to compare two kernel binary images
 * This script shows the size difference on a symbol-by-symbol basis between two binaries (sorted by the amount of difference)


 * deprecate-inline.patch - mark inlines as deprecated so compiler emits warnings
 * Note that it provides count-inlines program to parse compiler output and report size of inlines.
 * func-size.patch - use information about inlines to calculate function sizes (script is very similar to count-inlines program)

kill-printk.patch

 * is single biggest reducer of kernel size, doesn't seem to work with serial console!!
 * CONFIG_PRINTK

nobug.patch
Allow elimination of BUG code, which expands with file and line strings. There are 1776 BUG references in the 2.6.11 kernel. There are 1930 BUG_ON(xxx) references in the kernel.
 * uses CONFIG_BUG

nopanic.patch
too dangerous to turn off panic, not used.

no-elf-core.patch
Allow disabling of ELF core dumps
 * CONFIG_ELF_CORE

no-kcore.patch
Allow disabling of /proc/kcore, is x86-specific
 * uses CONFIG_PROC_KCORE

no-aio.patch
Allow disabling of Posix async IO
 * uses CONFIG_AIO

no-xattr.patch
Allow disabling of xattr syscalls
 * uses CONFIG_XATTR

fslock.patch
Allow disabling of file locking syscalls
 * uses CONFIG_FILE_LOCKING

direct-io-core.patch
Allow disabling of direct IO support
 * uses CONFIG_DIRECTIO

max-swapfiles.patch
Make number of swapfiles configurable (default=32) (shift=5 => 32 files, shift=0 => 1 file)
 * uses CONFIG_MAX_SWAPFILES_SHIFT

ldiscs.patch
Make number of tty line disciplines configurable (default=16)
 * uses CONFIG_NR_LDISCS

max_user_rt_prio.patch
Make number of schedule slots configurable (default=100)
 * uses CONFIG_MAX_USER_RT_PRIO

change-hz.patch
It's not obvious how this changes the size of the kernel, and it appears to be x86 only

= Notes on building and size reductions from various configs = Notes on OSK builds: text   data     bss     dec  filename 2107356 333344  113680 2554380  vmlinux.baseline bloat-o-meter vmlinux.baseline vmlinux.patched = +2920/-8884 text   data     bss     dec  filename 2101372 333888  113648 2548908  vmlinux.patched
 * first, did 'quilt pop pm/deferred-resume-test.patch', then built to get vmlinux.baseline
 * did 'quilt push -a', then built to get vmlinux.patched


 * configured all parameters at minimums, then built
 * couldn't finish linking, and got the following errors:
 * undefined reference to add_preferred_console
 * undefined reference to generic_setxattr and generic_getxattr
 * undefined reference to printk
 * configured printk and xattrs back on, then built to get vmlinux.try1

bloat-o-meter vmlinux.patches vmlinux.try1 = +4520/-350490 text   data     bss     dec  filename 1734504  90616   89036 1914156  vmlinux.try1

Panic trying to mount rootfs via nfs
 * tried to isolate nfs problem:
 * configured with AIO, file locks and direct IO on - same problem
 * configured with 5 swap files, 8 tty line disciplines, and 100 mat rt levels - same problem
 * went back to working config - diffed and noticed NFS_FS was off
 * NFS_FS requires FILE_LOCKING

Table of Config options
Here is a table showing default value and value recommended for size savings.

Note that I couldn't use CONFIG_PRINTK, CONFIG_XATTR or CONFIG_FILE_LOCKING in my setup.

Some results
This was for a quick check of Linux-tiny on an OSK board.

Program for producing report

 * 1) !/usr/bin/python
 * 2) size-delta - a tool for showing size difference between two files
 * 3) also supports output in MoinMoin wiki table format!!
 * 1) also supports output in MoinMoin wiki table format!!

import os, sys

if len(sys.argv)<3: sys.stderr.write("Usage: %s size-delta [-w] file1 file2\n\n" % os.path.basename(sys.argv[0])) sys.stderr.write(" -w   Show data in wiki-table format\n") sys.exit(1)

wiki_format = 0 print sys.argv if "-w" in sys.argv: wiki_format = 1 sys.argv.remove("-w") print sys.argv

size1 = os.popen("size "+sys.argv[1]).readlines[1] size2 = os.popen("size "+sys.argv[2]).readlines[1]

(text1, data1, bss1, total1, hex1, filename1) = size1.split (text2, data2, bss2, total2, hex2, filename2) = size2.split

def print_line(title, d1, d2): delta = int(d2)-int(d1) if wiki_format: print "||%5s||%8s||%8s||%8s||%2d%%||" % (title, d1, d2, delta, int((float(delta)/float(d1))*100)) else: print "%5s: %8s %8s %8s %2d%%" % (title, d1, d2, delta, int((float(delta)/float(d1))*100))

if wiki_format: print "||section||",os.path.basename(sys.argv[1]),"||",os.path.basename(sys.argv[2]),"||delta||percent||" else: print os.path.basename(sys.argv[1])," => ",os.path.basename(sys.argv[2])

print_line("text", text1, text2) print_line("data", data1, data2) print_line("bss", bss1, bss2) print_line("total", total1, total2)

Miscellaneous test notes

 * kernel would not link with CONFIG_PRINTK=n
 * undefined reference to add_preferred_console
 * undefined reference to printk
 * kernel would not link with CONFIG_XATTR=n
 * undefined reference to generic_setxattr and generic_getxattr
 * kernel would not mount root fs (NFS) with CONFIG_FILE_LOCKING=n

Config changes
[tbird@crest osk]$ diff config.baseline config.try3 --- config.baseline    2005-05-23 17:31:57.000000000 -0700 +++ config.try3 2005-05-23 17:31:40.000000000 -0700 @@ -1,7 +1,7 @@ # -# Mon May 23 16:49:43 2005 +# Mon May 23 17:27:14 2005 # CONFIG_ARM=y CONFIG_MMU=y @@ -34,34 +34,33 @@ CONFIG_FASTBOOT=y CONFIG_PRESET_LPJ=0 -# CONFIG_EMBEDDED is not set -CONFIG_KALLSYMS=y -CONFIG_KALLSYMS_ALL=y -CONFIG_KALLSYMS_EXTRA_PASS=y +CONFIG_EMBEDDED=y +# CONFIG_KALLSYMS is not set CONFIG_PRINTK=y -CONFIG_ELF_CORE=y -# CONFIG_CORE_SMALL is not set -# CONFIG_NET_SMALL is not set -CONFIG_FUTEX=y -CONFIG_EPOLL=y -CONFIG_AIO=y +# CONFIG_ELF_CORE is not set +CONFIG_CORE_SMALL=y +CONFIG_NET_SMALL=y +# CONFIG_FUTEX is not set +# CONFIG_EPOLL is not set +# CONFIG_AIO is not set CONFIG_XATTR=y CONFIG_FILE_LOCKING=y -CONFIG_DIRECTIO=y +# CONFIG_DIRECTIO is not set +# CONFIG_UID16 is not set CONFIG_CC_OPTIMIZE_FOR_SIZE=y -CONFIG_SHMEM=y +# CONFIG_SHMEM is not set CONFIG_CC_ALIGN_FUNCTIONS=0 CONFIG_CC_ALIGN_LABELS=0 CONFIG_CC_ALIGN_LOOPS=0 CONFIG_CC_ALIGN_JUMPS=0 -CONFIG_MAX_SWAPFILES_SHIFT=5 -CONFIG_NR_LDISCS=16 -CONFIG_MAX_USER_RT_PRIO=100 -# CONFIG_TINY_SHMEM is not set +CONFIG_MAX_SWAPFILES_SHIFT=0 +CONFIG_NR_LDISCS=2 +CONFIG_MAX_USER_RT_PRIO=5 +CONFIG_TINY_SHMEM=y
 * 1) Automatically generated make config: don't edit
 * 2) Linux kernel version: 2.6.11.10-alp
 * 1) CONFIG_RTC_NO_SYNC is not set
 * 1) CONFIG_KMALLOC_ACCOUNTING is not set
 * 2) CONFIG_AUDIT_BOOTMEM is not set
 * 1) CONFIG_MEASURE_INLINES is not set
 * 1) CONFIG_TINY_CFLAGS is not set

# @@ -435,6 +434,7 @@ CONFIG_SERIO=y CONFIG_SERIO_SERPORT=y +# CONFIG_SERIO_LIBPS2 is not set
 * 1) Loadable module support
 * 1) CONFIG_SERIO_CT82C710 is not set
 * 1) CONFIG_SERIO_RAW is not set

# @@ -912,7 +912,7 @@ CONFIG_BUG=y -CONFIG_DEBUG_BUGVERBOSE=y +# CONFIG_DEBUG_BUGVERBOSE is not set CONFIG_DEBUG_INFO=y CONFIG_FRAME_POINTER=y
 * 1) CONFIG_DEBUG_SPINLOCK is not set
 * 2) CONFIG_DEBUG_KOBJECT is not set
 * 1) CONFIG_DEBUG_FS is not set

Series file
Please note that I didn't try all the patches. I only integrated and used 37 of the broken-out patches. You can see this from the series file I used, which follows:


 * 1) start of linux tiny patches
 * 2) key:
 * 3) ## = patches Tim commented out
 * 4) # = patches commented out in original 2.6.11-tiny broken out series file
 * 1) # = patches commented out in original 2.6.11-tiny broken out series file

tiny/use-funit-at-a-time.patch tiny/core-small.patch tiny/pid-max.patch tiny/user-hash.patch tiny/futex-queues.patch tiny/tvec_bases.patch tiny/con_buf.patch tiny/config-net-small.patch tiny/cache_defer_hash.patch tiny/unix_socket_table.patch tiny/inet_protos.patch tiny/flow-cache-small.patch tiny/namei-inlines.patch tiny/buffer-inlines.patch tiny/fs_open-inlines.patch tiny/inode-inlines.patch tiny/ext2namei-inlines.patch tiny/fslocks-inline.patch tiny/tiny-cflags.patch tiny/kmalloc-accounting.patch tiny/audit-bootmem.patch tiny/bloat-o-meter.patch tiny/deprecate-inline.patch tiny/func-size.patch tiny/kill-printk.patch tiny/nobug.patch tiny/no-elf-core.patch tiny/no-kcore.patch tiny/no-aio.patch tiny/no-xattr.patch tiny/fslock.patch tiny/direct-io-core.patch tiny/uid16.patch tiny/max-swapfiles.patch tiny/ldiscs.patch tiny/max_user_rt_prio.patch
 * 1) tiny/tiny-extraversion.patch
 * 2) stuff already in -mm
 * 3) tiny/kgdb-ga.patch
 * 4) tiny/kgdboe-netpoll.patch
 * 1) tiny/kgdb-ga.patch
 * 2) tiny/kgdboe-netpoll.patch
 * 1) tiny/devlist.patch
 * 2) tiny stuff
 * 3) core
 * 1) core
 * 1) core
 * 1) net
 * 1) Unconditional bits
 * 2) tiny/small-8023.patch
 * 3) tiny/tg3-oops.patch
 * 1) tiny/small-8023.patch
 * 2) tiny/tg3-oops.patch
 * 1) tiny/06-crypto-sleep.patch
 * 2) build options
 * 1) build options
 * 1) measurement bits
 * 1) measurement bits
 * 1) trimmed debugging support
 * 2) tiny/no-doublefault.patch
 * 1) tiny/no-doublefault.patch
 * 1) tiny/no-doublefault.patch
 * 1) tiny/tiny-panic.patch
 * 1) tiny/nopanic.patch
 * 1) trimmed code
 * 2) TRB - 5/19 - haven't looked at these yet
 * 3) tiny/tiny-crc.patch
 * 4) tiny/threadinfo-ool.patch
 * 5) tiny/semaphore-inline.patch
 * 6) tiny/slob.patch
 * 7) tiny/slob-accounting.patch
 * 8) tiny/mempool-shrink.patch
 * 9) tiny/sysfs-backingstore.patch
 * 10) tiny/no-translations.patch
 * 11) tiny/tinyvt.patch
 * 12) trimmed apis
 * 13) TRB - 5/19 - haven't looked at ## ones yet
 * 14) tiny/ptrace.patch
 * 15) tiny/remove-vm86.patch
 * 16) tiny/sysenter.patch
 * 1) TRB - 5/19 - haven't looked at ## ones yet
 * 2) tiny/ptrace.patch
 * 3) tiny/remove-vm86.patch
 * 4) tiny/sysenter.patch
 * 1) tiny/posix-timers.patch
 * 2) tiny/ethtool.patch
 * 3) tiny/inetpeer.patch
 * 4) tiny/net-filter.patch
 * 5) tiny/dev_mcast.patch
 * 6) tiny/rtnetlink.patch
 * 7) tiny/igmp.patch
 * 8) tiny/binfmt-script.patch
 * 9) tiny/elf-no-aout.patch
 * 10) trimmed constants
 * 1) trimmed constants
 * 1) tiny/change-hz.patch
 * 2) trimmed hw support
 * 3) TRB - 5/19 - haven't looked at ## ones yet
 * 4) tiny/small-nomodedb.patch
 * 5) tiny/ide-hwif.patch
 * 6) tiny/sbf.patch
 * 7) tiny/serial-pci.patch
 * 8) tiny/dmi_blacklist.patch
 * 9) tiny/pci-quirks.patch
 * 10) tiny/tsc.patch
 * 11) tiny/cpu-support.patch
 * 12) tiny/mtrr.patch
 * 13) inflate cleanups
 * 14) TRB - 5/19 - haven't looked at ## ones yet
 * 15) tiny/inflate-noinline.patch
 * 16) tiny/inflate-formatting.patch
 * 17) tiny/inflate-legacy.patch
 * 18) tiny/inflate-input.patch
 * 19) tiny/inflate-iostate.patch
 * 20) tiny/inflate-huft.patch
 * 21) tiny/inflate-crc.patch
 * 22) tiny/inflate-killglobals.patch
 * 23) tiny/inflate-initramfs.patch
 * 24) tiny/inflate-initrd.patch
 * 25) tiny/inflate-i386.patch
 * 26) tiny/inflate-arm.patch
 * 27) tiny/inflate-x86_64.patch
 * 28) unsorted
 * 29) TRB - 5/19 - haven't looked at ## ones yet
 * 30) tiny/inflate-roll-crc.patch
 * 31) tiny/netpoll-timeout.patch
 * 32) tiny/movsl-mask.patch
 * 33) tiny/rolled-md4.patch
 * 34) tiny/kill-ext3-md4.patch
 * 1) TRB - 5/19 - haven't looked at ## ones yet
 * 2) tiny/inflate-roll-crc.patch
 * 3) tiny/netpoll-timeout.patch
 * 4) tiny/movsl-mask.patch
 * 5) tiny/rolled-md4.patch
 * 6) tiny/kill-ext3-md4.patch


 * 1) end of linux tiny patches