Skip to content

Shrink kernel image size by adjusting configurations #6

Description

@jserv

Here are opportunities to shrink the Linux kernel image size by adjusting configurations, verified on cortexm-linux.

  • Disable CONFIG_SYSFS to shed kobject/kset
    No userspace in config enumerates /sys, so the entire sysfs attribute infrastructure is pure overhead on a 16MB nommu target.

    • Add "# CONFIG_SYSFS is not set" to kernel config overrides
    • Remove /sys mountpoint and sysfs mount from init script
    • Mount devtmpfs explicitly in /etc/rc (DEVTMPFS_MOUNT=y has no effect
      on initramfs roots, so dynamic device nodes need this)
    • Add post-olddefconfig assertion to catch silent config drift on future
      kernel version bumps
  • Enable CONFIG_BASE_SMALL to shrink core hash table
    pid_max drops from 32768 to 4096, and core data structure (dentry cache, inode cache, IDR radix trees) use smaller hash tables. The option is an EXPERT-visible bool.

  • Set CONFIG_TINY_RCU=y. Minimal RCU implementation for uniprocessor -- smaller than TREE_RCU. Designed for small systems

  • Set CONFIG_SHMEM=n. Enables the tiny-shmem fallback (ramfs-backed shm), removing the full tmpfs/shmem implementation from the kernel. Saves significant core code on a system that does not need POSIX shared memory.

  • Disable CONFIG_AUDIT. Kernel auditing framework is irrelevant on a single-user nommu target; drags in audit logging, filter
    infrastructure, and syscall audit paths.

  • Disable CONFIG_SYSVIPC and CONFIG_POSIX_MQUEUE. System V IPC (shmget/semget/msgget) and POSIX message queues are unused by BusyBox; each adds several KB of dead syscall infrastructure.

  • Disable CONFIG_WATCH_QUEUE, CONFIG_TASKSTATS, CONFIG_TASK_DELAY_ACCT, CONFIG_TASK_XACCT, CONFIG_TASK_IO_ACCOUNTING. Optional accounting/notification subsystems with no consumer on this target.

  • CONFIG_BINFMT_SCRIPT (shebang #! interpreter support).
    The inittab uses ::sysinit:/bin/sh /etc/rc (explicit shell invocation) and ::respawn:-/bin/sh (FDPIC binary, not a script), so the current boot path does not need kernel shebang handling. BusyBox uses symlink-style applet installation (not script wrappers: CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is disabled in the config). TRADE-OFF: future scripts with #!/bin/sh shebangs will silently fail to exec unless invoked as sh /path/to/script. The cost of BINFMT_SCRIPT is small (~1-2KB). Re-enable if any script in the rootfs needs implicit shebang dispatch.

  • Audit __init / __initdata annotations in board-level code.
    init-only code/data is freed after boot, lowering post-boot RAM footprint. Does not shrink on-disk image but matters on 4MB SSRAM.

Pending:

  • Syscall table pruning
    Selectively disable __SYSCALL entries. Under shared FDPIC linking, libc.so retains wrappers for all supported syscalls regardless of what BusyBox calls, so the kernel-side pruning yields zero benefit. Focus on uClibc feature pruning instead, which removes the libc-side wrappers and reduces the corresponding kernel code reachability via LTO dead-code elimination.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions