Skip to content
systemcoding.dev
Kernels

A Map of the Linux Kernel Source Tree and Its Top-Level Directories

A guided map of the Linux 6.12 kernel source tree, from arch/ to mm/ and net/, with when each top-level directory is worth opening and when it is not.

6 min read
Summarize in AI
Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, Rust and GNU logos.

Why you need a map before you read code

The Linux kernel source is tens of millions of lines. Nobody reads it top to bottom, and nobody needs to. The tree is organized by responsibility, so if you know what a directory owns, you can predict where a feature lives and skip most of the rest. This post walks through the top-level directories of Linux 6.12 LTS, says what each one is for, and says when it is the wrong place to look.

Get a source tree first. The examples assume a clone of the stable repository, but a tarball from kernel.org works the same way:

Shell
git clone --depth 1 --branch v6.12 \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
ls -d */
Text
arch/          block/         certs/         crypto/
Documentation/ drivers/       fs/            include/
init/          io_uring/      ipc/           kernel/
lib/           LICENSES/      mm/            net/
rust/          samples/       scripts/       security/
sound/         tools/         usr/           virt/

The listing prints one directory per line when piped; the columns here are just for reading. Twenty-four directories cover everything.

The directories, each with its limits

arch/

Everything specific to a processor architecture: arch/x86, arch/arm64, arch/riscv and about twenty others. Boot code, the system call entry path, page table setup, interrupt controllers and low-level locking primitives live here. Open it when you need to know what actually happens on the first instruction after a trap. Do not open it to understand a feature that works the same on every CPU, such as the scheduler's policy; that is in kernel/sched/.

drivers/

By far the largest directory, holding the code for devices: drivers/net, drivers/gpu, drivers/usb, drivers/i2c, drivers/block, drivers/tty and many more. It is also the best place to learn kernel idioms, because a small driver such as drivers/char/mem.c shows registration, file operations and device numbers in one file. Do not start here to learn how a subsystem works; the subsystem core (for example net/ or block/) defines the contract that drivers implement.

fs/

Individual file systems (fs/ext4, fs/btrfs, fs/xfs, fs/nfs) and the virtual file system layer in the top of fs/ itself: namei.c for path lookup, read_write.c for read and write, inode.c, dcache.c. Open it to follow a system call into a file. Skip it for block-device concerns like I/O scheduling, which belong to block/.

kernel/

The core that does not depend on a specific architecture: kernel/sched/ (the scheduler), kernel/fork.c, kernel/exit.c, kernel/signal.c, kernel/time/, kernel/locking/, kernel/printk/, kernel/bpf/. This is where a process's life is written down. It does not hold memory management, despite the name.

mm/

Memory management: the page allocator (page_alloc.c), the slab allocators, mmap.c, memory.c (page faults), vmscan.c (reclaim), swap*.c, oom_kill.c. If a question starts with "how does Linux decide...?" about RAM, it ends here.

net/

The network stack: net/core, net/ipv4, net/ipv6, net/netfilter, net/unix, net/socket.c. It stops at the device: the NIC driver itself is in drivers/net/ethernet.

block/

The block layer: request queues, blk-mq, I/O schedulers, bio handling. Storage drivers plug into it from drivers/nvme, drivers/scsi and so on.

include/

Headers. include/linux/ holds the kernel-internal API (list.h, spinlock.h, sched.h); include/uapi/ holds headers shared with user space, which means anything in uapi/ is a stable promise. include/linux/ is not a stable promise for out-of-tree code.

init/

Start-up glue. init/main.c contains start_kernel(), the function that sets up the rest of the system, and kernel_init(), which finally runs PID 1. Short and worth reading once.

lib/

Generic helpers: string functions, sort.c, rbtree.c, radix-tree and XArray, crc32, vsprintf.c (the source of printk formatting), and kernel unit tests.

security/

Linux Security Modules: SELinux, AppArmor, Smack, Landlock, Yama, plus the capability and keyring code.

crypto/

The in-kernel crypto API: algorithms, templates and the user-space interface used by dm-crypt and IPsec.

ipc/

System V and POSIX message queues, semaphores and shared memory.

io_uring/

The asynchronous I/O interface, which moved out of fs/ into its own directory in v5.19.

sound/

ALSA and the audio drivers.

virt/

The generic parts of KVM. The architecture-specific parts are in arch/x86/kvm and the like.

rust/

The Rust infrastructure: the kernel crate, bindings generation and helper code. Rust drivers live under drivers/.

Documentation/

Plain text and reStructuredText docs, rendered at docs.kernel.org. Documentation/process/ explains how to submit patches, and Documentation/admin-guide/ covers parameters and configuration.

scripts/

Build and developer tools: Kconfig and Kbuild helpers, checkpatch.pl, get_maintainer.pl, diffconfig, config, code generators. A tool you will use on day one lives here.

tools/

User-space programs built from the kernel tree: tools/perf, tools/testing/selftests, tools/bpf, tools/lib. These are not kernel code but they are versioned with it.

samples/

Small working examples for kernel features, such as samples/kprobes and samples/bpf. Good for reading, not for copying into production.

certs/, usr/, LICENSES/

Module signing certificates, the initramfs generator usr/gen_init_cpio, and the license texts.

Finding a symbol's home in practice

Knowing directories is half the job; the other half is confirming. The git grep command is fast on a clean tree because it searches only tracked files:

Shell
git grep -n "SYSCALL_DEFINE3(read," -- fs/
git grep -n "static int __ref kernel_init" -- init/
Text
fs/read_write.c:722:SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
init/main.c:1458:static int __ref kernel_init(void *unused)

Line numbers move between releases, so treat them as examples and expect different ones on your checkout. The first hit shows how a system call is declared with a macro rather than as a plain function, and the second is the function that eventually executes PID 1.

Two files at the top level

MAINTAINERS lists every subsystem, its maintainers, mailing lists and the files it covers. scripts/get_maintainer.pl reads it. Kconfig and Makefile at the top bind the tree together: the top Makefile defines the version (VERSION, PATCHLEVEL, SUBLEVEL) and every build target.

A routine for finding where a feature lives

When you have a behavior and need its code, work from the outside in. Start from the user-visible interface: a system call name, a /proc or /sys file, a log message or a configuration option. A system call leads to a SYSCALL_DEFINEn line, usually in fs/, kernel/ or mm/. A /proc file leads to a proc_create call or a seq_file show function. A log message is the most reliable of all, because the exact string is in the source: search for a distinctive fragment of the text and the print statement leads you to the function that emitted it. A Kconfig option leads, through the Makefile in its directory, to the object files it enables.

From that first hit, read upward to the callers and downward to the helpers, staying inside one subsystem until the question is answered. Resist the urge to read drivers/ for an answer about policy, or arch/ for an answer about a generic data structure.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.