Linux Internals

A tour of the Linux kernel — task_struct and scheduling, memory and the page cache, VFS, the network stack, /proc and /sys, systemd, eBPF, and essential debugging tools.

Advanced 3 min readLesson 16 of 16

Linux runs most of the world's servers, every Android phone, and nearly all cloud infrastructure. This lesson connects the OS concepts from earlier lessons to the real Linux implementation and the tools engineers use to look inside a running system.

Kernel subsystems at a glance

System call interfaceProcess mgmttask_struct · schedulerMemory mgmtpage tables · page cacheVFSext4 · XFS · btrfs · procNetworkingsockets · TCP/IP · netfilterDevice drivers + block layerArchitecture code (x86, ARM, RISC-V)

Processes and threads: one structure

Linux doesn't fundamentally distinguish processes from threads. Both are tasks (struct task_struct), created with clone(). Flags decide what's shared: CLONE_VM (memory), CLONE_FILES (descriptors), CLONE_THREAD (the same thread group). A "thread" is just a task that shares everything with its siblings; getpid() returns the thread group ID.

Scheduling uses per-CPU run queues with the fair scheduler (CFS, now EEVDF), real-time classes (SCHED_FIFO, SCHED_RR) and SCHED_DEADLINE. See CPU scheduling.

/proc and /sys: the kernel as files

Shell
cat /proc/cpuinfo                # CPU details
cat /proc/meminfo                # memory breakdown (Cached, Dirty, AnonPages…)
cat /proc/loadavg                # load averages, running/total tasks
ls -l /proc/$$/fd                # open file descriptors of this shell
cat /proc/<pid>/status           # state, threads, VmRSS, context switches
cat /proc/<pid>/maps             # memory mappings
cat /sys/block/nvme0n1/queue/scheduler    # I/O scheduler
echo 1 > /proc/sys/net/ipv4/ip_forward    # tune the kernel (sysctl)

Memory: what "free" really means

$ free -h
               total   used   free   shared  buff/cache  available
Mem:            31Gi   9.1Gi  1.2Gi  0.4Gi   21Gi        21Gi

Linux deliberately fills unused RAM with the page cache. Look at available (an estimate of how much can be given to applications without swapping), not "free". Dirty pages are written back by flusher threads; vm.dirty_ratio controls how much may accumulate.

The network stack

Socket APIsend / recv / epollTCP / UDPcongestion control (CUBIC, BBR), buffersIP + netfilterrouting, iptables/nftables, conntrack, NATQueueing disciplinestc: shaping, fq_codelDriver + NICNAPI polling, RSS multi-queue, offloads

Kubernetes networking, Docker port mapping and firewalls are built from these pieces: virtual ethernet pairs (veth), bridges, network namespaces, and netfilter/iptables or eBPF rules.

systemd: PID 1

Most distributions use systemd as init. It starts services in parallel based on dependencies, supervises and restarts them, puts each service in its own cgroup, and collects logs in the journal.

Shell
systemctl status nginx
systemctl restart nginx
journalctl -u nginx --since "10 min ago" -f
systemd-analyze blame          # what slowed down boot

eBPF: programmable kernel

eBPF lets you load small, verified programs into the kernel and attach them to events — system calls, function entries, network packets, tracepoints — without writing kernel modules. A verifier guarantees they terminate and can't crash the kernel.

Uses: observability (bpftrace, BCC tools), networking (Cilium, Cloudflare's DDoS protection, XDP packet processing at line rate), and security (Falco, seccomp-style policies).

Shell
# Which files are being opened, system-wide, live:
sudo bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s %s\n", comm, str(args->filename)); }'

The debugging toolbox

QuestionTool
What's using CPU?top, htop, pidstat 1
Where is the CPU time going in my code?perf top, perf record -g + flame graphs
What is this process doing / why is it stuck?strace -p PID, cat /proc/PID/stack, gdb -p
Memory pressure?free, vmstat 1, /proc/meminfo, smem
Disk bottleneck?iostat -x 1, iotop, biolatency
Network issues?ss -tanp, ip addr, tcpdump, nstat
What happened at boot or in a service?dmesg -T, journalctl
Open files and socketslsof -p PID

Kernel development in brief

The Linux kernel is around 35+ million lines of C (with Rust now accepted for some drivers). Changes go through mailing lists and subsystem maintainers, a new release ships roughly every 9–10 weeks, and long-term support (LTS) branches are maintained for years. Modules can be loaded at runtime (lsmod, modprobe).

Key takeaways
  • Linux tasks (task_struct) represent both processes and threads; clone flags decide sharing.
  • /proc and /sys expose kernel state as files; sysctl tunes the kernel.
  • Free RAM becomes page cache; judge memory by "available", not "free".
  • systemd supervises services, cgroups and logs.
  • eBPF safely extends the kernel for tracing, networking and security.
  • Debug systematically with top/perf/strace/iostat/ss and the USE method.