Chapter 15: Linux

Operating Systems
UNIX and Linux historyDesign goals and interfacesThe shell and pipelinesKernel structure and modulesProcesses, signals, threadsScheduling: CFS and EEVDFBooting and systemdMemory: paging, zones, SLUBI/O: devices, blk-mq, networkingFile systems: VFS, ext4Security: permissions, containersAndroid
Sercan KÜLCÜ · Giresun University · Computer Engineering

Introduction

Learning Outcomes

History and family

Trace the line from UNIX through BSD, MINIX and GNU to Linux; place distributions and Android.

Interfaces and the shell

Separate the library / system-call / kernel layers; show how pipelines are built with fork, pipe and dup2.

Processes and scheduling

Explain the kernel steps of fork and execve, signal delivery, task_struct, clone() flags and NPTL; what changed in the move from CFS to EEVDF.

Memory

Explain the address-space layout, 4/5-level page tables, memory zones, the SLUB allocator, the page cache and the OOM killer.

I/O and files

Device files, blk-mq, the network stack; the VFS, i-nodes, ext4 extents and journaling, links and /proc.

Security

Compute rwx/setuid/umask; recognize capabilities, namespaces + cgroups, SELinux/AppArmor, seccomp and the Android sandbox.

Introduction and History · Step by step

Timeline from UNIX to Linux

1969–1983UNIX is born1969UNIX, PDP-7 (Bell Labs)1971ported to the PDP-111973rewritten in C1977BSD (Berkeley)1983System V, 4.2BSD1983GNU project1984–1993?1994–2010?2011–2026?

Ken Thompson and Dennis Ritchie wrote UNIX in assembly on a PDP-7 in 1969; rewriting it in C in 1973 made it portable. AT&T gave the source to universities, and BSD was born at Berkeley.

1969–1983UNIX is born1969UNIX, PDP-7 (Bell Labs)1971ported to the PDP-111973rewritten in C1977BSD (Berkeley)1983System V, 4.2BSD1983GNU project1984–1993The search for a free UNIX1987MINIX (Tanenbaum)1988POSIX standard1989GPL license1991Linux 0.01 (Torvalds)19920.12: switch to the GPL1993Slackware, Debian1994–2010?2011–2026?

As the commercial UNIXes (System V, SunOS, AIX…) diverged, POSIX defined a common interface. Tanenbaum wrote MINIX for teaching; in 1991 Linus Torvalds developed his own kernel on MINIX and combined it with the GNU tools.

1969–1983UNIX is born1969UNIX, PDP-7 (Bell Labs)1971ported to the PDP-111973rewritten in C1977BSD (Berkeley)1983System V, 4.2BSD1983GNU project1984–1993The search for a free UNIX1987MINIX (Tanenbaum)1988POSIX standard1989GPL license1991Linux 0.01 (Torvalds)19920.12: switch to the GPL1993Slackware, Debian1994–2010Linux matures1994Linux 1.019962.0: SMP support1999Red Hat IPO20032.6 series2005git2008Android: HTC Dream2011–2026?

Linux 1.0 (1994); multiprocessing with 2.0; a preemptible kernel and the O(1)/CFS schedulers with 2.6. In 2005, after the BitKeeper dispute, Torvalds wrote git. The first Android phone shipped in 2008.

1969–1983UNIX is born1969UNIX, PDP-7 (Bell Labs)1971ported to the PDP-111973rewritten in C1977BSD (Berkeley)1983System V, 4.2BSD1983GNU project1984–1993The search for a free UNIX1987MINIX (Tanenbaum)1988POSIX standard1989GPL license1991Linux 0.01 (Torvalds)19920.12: switch to the GPL1993Slackware, Debian1994–2010Linux matures1994Linux 1.019962.0: SMP support1999Red Hat IPO20032.6 series2005git2008Android: HTC Dream2011–2026Linux everywhere2011version 3.02017Top500: 100% Linux20226.0; Rust in 6.120236.6: EEVDF20246.12: sched_ext, RT20266.x → 7.0 series

Since 2017 all of the world's 500 fastest supercomputers run Linux. The 6.x series brought Rust support, EEVDF and sched_ext; version jumps carry no meaning (7.0 follows 6.19).

Introduction and History

GNU, Linux and Distributions

Applications: desktop, server softwarePackage manager + repositories (apt, dnf, pacman)init system: systemdGNU tools + C library (glibc, musl)Linux kerneldistribution(distro)Android: Linux kernel + Bionic libc,no GNU tools
FamilyExamplesPackage
DebianDebian, Ubuntu, Mint, Pardus.deb / apt
Red HatFedora, RHEL, Rocky, Alma.rpm / dnf
ArchArch, Manjaropacman
SUSEopenSUSE, SLESzypper
LightweightAlpine (musl + BusyBox)apk

Release model: a major release every ~9–10 weeks (a 2-week merge window + rc1…rc7). The last release of each year becomes LTS: 6.6, 6.12, 6.18…

Strictly, “Linux” is only the kernel's name; the system users install is a distribution (GNU/Linux).

Introduction and History

Design Goals and the UNIX Philosophy

Simple

A few well-defined concepts: process, file, pipe.

Elegant

Small tools that do one thing combine to do big jobs.

Consistent

“Everything is a file”: disks, terminals and pipes all use the same read/write.

Powerful

Shell scripts, pipelines, regular expressions.

Flexible

Text streams are the universal interface; tools work together without knowing about each other.

For programmers

Designed by programmers for programmers: little “magic”, silent success.

The UNIX philosophy (McIlroy): Write programs that do one thing and do it well, and that work together. Write programs to handle text streams, because that is a universal interface.
/home/ali/notes.txt/dev/tty1pipesocketfd → read() / write()

POSIX standardizes this interface: the same source compiles on Linux, BSD and macOS.

The Shell and Interfaces · Step by step

Layers and Interfaces: The Journey of a printf

UsersStandard utility programsshell, editors, compilersStandard library (glibc)printf, open, fork wrappersLinux kernelprocesses, memory, files, I/OHardwareCPU, memory, disks, terminalsuser interfacelibrary interfacesystem-call interfaceuser modekernel mode1 · Applicationprintf("hello!\n");writes to the glibc buffer

The program calls printf. This is not a system call yet: glibc writes the text into a buffer in user space.

UsersStandard utility programsshell, editors, compilersStandard library (glibc)printf, open, fork wrappersLinux kernelprocesses, memory, files, I/OHardwareCPU, memory, disks, terminalsuser interfacelibrary interfacesystem-call interfaceuser modekernel mode1 · Applicationprintf("hello!\n");writes to the glibc buffer2 · glibcwrite(1, buf, 8)rax ← 1 (write), syscall

When the buffer is flushed, glibc's write() wrapper runs: it puts the system-call number (write = 1 on x86-64) in rax and the arguments in registers, and executes the syscall instruction.

UsersStandard utility programsshell, editors, compilersStandard library (glibc)printf, open, fork wrappersLinux kernelprocesses, memory, files, I/OHardwareCPU, memory, disks, terminalsuser interfacelibrary interfacesystem-call interfaceuser modekernel mode1 · Applicationprintf("hello!\n");writes to the glibc buffer2 · glibcwrite(1, buf, 8)rax ← 1 (write), syscall3 · Kernel entryentry_SYSCALL_64sys_call_table[1] → vfs_write

The CPU switches to kernel mode. The entry code uses the number to pick the handler from sys_call_table; the VFS finds the object behind file descriptor 1.

UsersStandard utility programsshell, editors, compilersStandard library (glibc)printf, open, fork wrappersLinux kernelprocesses, memory, files, I/OHardwareCPU, memory, disks, terminalsuser interfacelibrary interfacesystem-call interfaceuser modekernel mode1 · Applicationprintf("hello!\n");writes to the glibc buffer2 · glibcwrite(1, buf, 8)rax ← 1 (write), syscall3 · Kernel entryentry_SYSCALL_64sys_call_table[1] → vfs_write4 · Driverpty/tty driverterminal prints it

fd 1 is attached to a pseudoterminal (pty); the tty layer passes the data to the terminal emulator. Had it been a disk, the path would go to the page cache and the block layer.

UsersStandard utility programsshell, editors, compilersStandard library (glibc)printf, open, fork wrappersLinux kernelprocesses, memory, files, I/OHardwareCPU, memory, disks, terminalsuser interfacelibrary interfacesystem-call interfaceuser modekernel mode1 · Applicationprintf("hello!\n");writes to the glibc buffer2 · glibcwrite(1, buf, 8)rax ← 1 (write), syscall3 · Kernel entryentry_SYSCALL_64sys_call_table[1] → vfs_write4 · Driverpty/tty driverterminal prints it5 · Returnrax ← 8 (bytes written)sysret → user mode

The return value comes back in rax (8 bytes), and sysret returns to user mode. On error, glibc turns the negative value into errno and returns −1.

The Shell and Interfaces

Basic Commands and Redirection

CategoryCommandsNote
Files / directoriesls cd pwd mkdir rm -r cp mv touch find tartouch updates the timestamp; creates an empty file if none exists
Text (filters)cat less head tail grep sort uniq wc echoread stdin, write stdout: they combine in pipelines
Processes / systemps top kill chmod chown df du syncsync flushes dirty buffers to disk (syncing between machines: rsync)
Networkssh scp ping curl wget tracerouteip addr, ip route, ss, nft; they replaced the old ifconfig, route, netstat and iptables
Informationman uname free lsblk/proc is not a command but a pseudo file system: cat /proc/meminfo
# redirection: 0 = stdin, 1 = stdout, 2 = stderr
sort < input.txt > output.txt 2> errors.log   # < reads, > writes (overwrite)
echo "line" >> log.txt                        # >> appends
make 2>&1 | tee build.log &                  # stderr→stdout, pipe, background
sort's descriptor table (set up by the shell before exec):0 stdininput.txt1 stdoutoutput.txt2 stderrerrors.log

The Shell and Interfaces · Step by step

Pipelines: Data Flows Through the Stages

cat log.txtPID 2101|output (stdout)grep errorPID 2102|output (stdout)sortPID 2103|output (stdout)uniq -cPID 2104output (stdout)shell: 3 pipes + 4 child processes (fork + exec), all concurrent

The shell parses the line and creates 3 pipes and 4 processes. The processes run at the same time; each knows only its own stdin/stdout.

cat log.txtPID 2101|output (stdout)error: diskinfo: booterror: neterror: diskwarn: heaterror: neterror: diskgrep errorPID 2102|output (stdout)sortPID 2103|output (stdout)uniq -cPID 2104output (stdout)

cat writes the file's 7 lines into the pipe. If the pipe buffer (64 KiB by default) fills, the writer blocks: producer–consumer.

cat log.txtPID 2101|output (stdout)error: diskinfo: booterror: neterror: diskwarn: heaterror: neterror: diskgrep errorPID 2102|output (stdout)error: diskerror: neterror: diskerror: neterror: disksortPID 2103|output (stdout)uniq -cPID 2104output (stdout)

grep reads line by line and passes the 5 matching lines on at once. A filter is stateless; it does not hold up the flow.

cat log.txtPID 2101|output (stdout)error: diskinfo: booterror: neterror: diskwarn: heaterror: neterror: diskgrep errorPID 2102|output (stdout)error: diskerror: neterror: diskerror: neterror: disksortPID 2103|output (stdout)error: neterror: neterror: diskerror: diskerror: diskuniq -cPID 2104output (stdout)

sort, however, cannot output anything before reading all of its input (up to EOF): the last line could change the first position.

cat log.txtPID 2101|output (stdout)error: diskinfo: booterror: neterror: diskwarn: heaterror: neterror: diskgrep errorPID 2102|output (stdout)error: diskerror: neterror: diskerror: neterror: disksortPID 2103|output (stdout)error: neterror: neterror: diskerror: diskerror: diskuniq -cPID 2104output (stdout) 2 error: net 3 error: diskterminal

uniq -c counts only adjacent repeats, which is why sort comes first. Result: 2 × “error: net”, 3 × “error: disk”.

The Shell and Interfaces · Step through the code

How Does the Shell Build a Pipeline?

int fd[2];
pipe(fd);              /* 3: read, 4: write */
if (fork() == 0) {    /* child 1 */
    dup2(fd[1], 1);
    close(fd[0]); close(fd[1]);
    execlp("ls", "ls", NULL);
}
if (fork() == 0) {    /* child 2 */
    dup2(fd[0], 0);
    close(fd[0]); close(fd[1]);
    execlp("wc", "wc", "-l", NULL);
}
/* shell: close both ends */
close(fd[0]); close(fd[1]);
wait(NULL); wait(NULL);
shell0tty1tty2tty3pipe-r4pipe-wchild 101234child 201234pipe bufferw →→ r

pipe() creates a buffer in the kernel and two ends: the lowest free numbers, 3 (read) and 4 (write).

shell0tty1tty2tty3pipe-r4pipe-wchild 10tty1tty2tty3pipe-r4pipe-wchild 201234pipe bufferw →→ r

fork(): the child gets a copy of the descriptor table; both processes point to the same pipe.

shell0tty1tty2tty3pipe-r4pipe-wchild 10tty1pipe-w2tty34child 201234pipe bufferw →→ r

dup2(4, 1): stdout is now the pipe's write end. The extra ends are closed.

shell0tty1tty2tty3pipe-r4pipe-wls0tty1pipe-w2tty34child 201234pipe bufferw →→ r

execlp replaces the image with ls; the descriptor table is kept. ls writes into the pipe without knowing it.

shell0tty1tty2tty3pipe-r4pipe-wls0tty1pipe-w2tty34wc0pipe-r1tty2tty34pipe bufferw →→ r

The second child connects its stdin to the pipe's read end and becomes wc -l.

shell0tty1tty2tty34ls0tty1pipe-w2tty34wc0pipe-r1tty2tty34pipe bufferw →→ r

The shell closes both ends. Otherwise the write end would stay open, and wc would never see EOF and wait forever. Then it waits for both children.

Kernel Structure

Structure of the Linux Kernel

System callsI/O componentVirtual file system (VFS)TerminalsLine disciplineCharacter device driversSocketsNetwork protocolsNetwork device driversFile systemsGeneric block layerI/O schedulerBlock device driversMemory managementVirtual memoryPaging,page replacementPage cacheProcess managementSignal handlingProcess/threadcreation, terminationCPU schedulingInterruptsDispatcher

The system-call interface on top, interrupts and the dispatcher (context switching) at the bottom. All components run in a single address space: Linux is a monolithic kernel. The classic 4.4BSD kernel split into the same three components.

Kernel Structure · Step by step

Loadable Kernel Modules (LKMs)

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

Monolithic but modular: most drivers are loadable kernel modules (.ko). The administrator requests one with modprobe, or udev loads it automatically when the device appears.

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

modprobe finds the dependencies in /lib/modules/$(uname -r)/modules.dep and loads them first (insmod does not).

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

The finit_module() system call copies the module into the kernel; with Secure Boot on, its signature is checked. It requires the CAP_SYS_MODULE capability.

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

The kernel applies the module's relocations and binds the symbols it uses to kernel functions exported with EXPORT_SYMBOL.

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

The module_init function runs: the driver registers itself with the PCI subsystem (pci_register_driver).

user space# modprobe e1000emodules.dep: dependencieskernelfinit_module()signature checkrelocationsymbol bindingmodule_init()driver registrationPCI device matches → probe()kernel symbol tableexported with EXPORT_SYMBOLeth0 interface ready

probe() is called for the matching device and the network interface appears. lsmod lists modules, rmmod removes one. A module runs with kernel privilege: its bug can crash the whole system.

The source tree is ~40 million lines, mostly drivers. The kernel has had Rust support since 6.1, and the first Rust driver arrived in 6.8; eBPF runs small, safe, verified programs in the kernel.

Processes

What Do fork and exec Do in the Kernel?

shPID 501shPID 748lsPID 7481. fork() → new process2. execve() → same processcopy: same programimage replaced by ls

fork() in the kernel

  • Allocate a new task_struct, fill it from the parent, assign a new PID
  • Allocate a kernel stack; copy registers (return value 0 in the child)
  • Copy the page tables and mark writable pages read-only (COW)
  • Share open files: the struct file reference count goes up
  • Signal handlers, cwd and credentials are copied

execve() in the kernel

  • The ELF header is read; the old mm_struct is dropped, a new one is built and the segments are mmapped
  • A new cred is prepared according to the setuid/setgid bits
  • PC ← ld.so (the dynamic linker) or the program's entry point
  • A failed execve returns −1; by convention the child exits with _exit(127)

Old UNIX really copied data and stack on fork; Linux copies only the page tables (COW). Since exec usually follows fork at once, very few pages are ever copied.

Processes

POSIX Signals

A signal is a software interrupt that notifies a process of an event. It can be synchronous (SIGSEGV, SIGFPE: caused by the process's own instruction) or asynchronous (SIGINT, SIGTERM: from outside). For each signal a process chooses the default action, ignoring it, or a handler (cleanup, logging).

SignalNoWhen is it raised?Default
SIGHUP1The terminal hung up; for daemons, “reload your configuration”terminate
SIGINT2Ctrl-C (to the foreground process group)terminate
SIGQUIT3Ctrl-\core dump
SIGILL4Illegal machine instructioncore dump
SIGABRT6abort(): the process terminates itself abnormallycore dump
SIGFPE8Arithmetic error such as integer division by zerocore dump
SIGKILL9kill -9; cannot be caught or ignoredterminate
SIGSEGV11Invalid memory accesscore dump
SIGPIPE13Writing to a pipe with no readersterminate
SIGALRM14alarm() timer expiredterminate
SIGTERM15The default of the kill command; a polite request to terminateterminate
SIGUSR1/210/12User-definedterminate
SIGCHLD17A child stopped or terminatedignore
SIGSTOP / SIGCONT19/18Stop (uncatchable) / continue; Ctrl-Z → SIGTSTPstop / continue

Numbers are for x86/ARM Linux. SIGKILL and SIGTERM can both be sent with the kill command; the difference is whether they can be caught.

Processes · Step by step

Signal Delivery

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stack

The user presses Ctrl-C: the tty line discipline raises SIGINT for the foreground process group. The kernel merely sets bit 2 in the target task's pending signal set.

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stackcheck on return from the kernel

The signal is not handled at once. When the process returns to user mode from a system call or an interrupt, the kernel checks for signals that are pending and unmasked.

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stack

If a handler was installed with sigaction, the kernel writes a signal frame (saved registers + a return trampoline) onto the user stack and sets the PC to the handler.

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stackasync-signal-safe calls only

The handler runs in user mode. Only async-signal-safe functions are safe inside it (e.g. write, a volatile sig_atomic_t flag); printf and malloc are not.

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stack

When the handler returns, the trampoline makes the rt_sigreturn system call and the kernel restores the registers from the frame. (sigreturn does not enter the handler; it returns from it.)

user modekernel modemain() loopinterrupted at: PC = 0x401a2chandler(SIGINT)flag = 1; return;rt_sigreturntrampoline: system calltty driverCtrl-C → SIGINTtask_structpending: 2 · mask: emptysignal frameregisters onto the user stackcontext restored, resumes where it left off

The process resumes at the interrupted instruction. Without a handler the default action would apply: termination for SIGINT.

Processes · Step through the code

Choosing Pending Signals: Code Trace

/* on return to user mode (kernel) */
void check_signals(task *t) {
    unsigned long h = t->pend & ~t->blk;
    while (h) {
        int sig = __builtin_ctzl(h) + 1;
        t->pend &= ~(1UL << (sig - 1));
        deliver(t, sig);   /* handler/default */
        h = t->pend & ~t->blk;
    }
}
/* before: sigprocmask(SIG_BLOCK, {SIGINT}) */
/* after:  sigprocmask(SIG_UNBLOCK, {SIGINT}) */
1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDSIGINT blocked

Before entering a critical section the process blocked SIGINT with sigprocmask (bit 2 of the blocked set). Signals are a bit set in each task.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDCtrl-C, kill -USR1, child exited

Three signals arrive while the process sleeps: Ctrl-C (2), kill -USR1 (10) and a child's exit (17). The kernel only sets bits in the pending set; nothing runs yet.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDready = pending & ~blocked = {10, 17}

As the process returns to user mode the kernel checks: ready = pending & ~blocked. SIGINT is pending but blocked; ready to deliver are 10 and 17.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDSIGUSR1 → handler runs

The lowest ready bit (ctz): 10. It is cleared from pending and delivered: SIGUSR1 → the handler runs. The ready set is recomputed.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDSIGCHLD → default: ignore

The lowest ready bit (ctz): 17. It is cleared from pending and delivered: SIGCHLD → default: ignore. The ready set is recomputed.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDready empty: loop ends, SIGINT still pending

The ready set is empty, the loop ends and the process continues in user mode. SIGINT is not lost: it stays in the pending set.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDunblocked: ready = {2}

The critical section is over and SIGINT is unblocked. The same check runs on return from sigprocmask: ready = {2}.

1234567891011121314151617pendingblockedready2 SIGINT · 10 SIGUSR1 · 17 SIGCHLDSIGINT → default: terminate

SIGINT is delivered; with no handler installed the default action applies: the process terminates. Blocking a signal defers it; it does not ignore it. Had the same signal arrived several times, it would have merged into one bit.

Processes

Process-Management System Calls

System callDescription
fork()Creates a new process by copying the caller (COW)
clone(), clone3()A new task with flags choosing what is shared (threads, containers)
execve()Replaces the current process image with a new program
waitpid()Waits for a child to finish and gets its exit status (reaps the zombie)
exit() / _exit()Terminates the caller (exit flushes stdio buffers)
kill()Sends a signal to a process; the signal need not mean termination
sigaction()Sets the handler or action for a signal
sigprocmask()Reads/changes the signal mask (blocked signals)
sigpending()Returns the signals pending because they are blocked
sigsuspend()Temporarily changes the mask and sleeps until a signal arrives
rt_sigreturn()Restores the saved context on return from a handler
alarm() / pause()SIGALRM after n seconds / sleep until a signal arrives
fork()copy, COWexecve()new programrunssignals, I/Oexit()resources releasedzombie (Z)status waitingwaitpid()parent reapssignals via kill()/sigaction() and timing via alarm()/pause() can step in at any stage

A system call is the only way for a user program to ask the kernel for service; Linux x86-64 has ~460 of them. The process tree is shown by pstree -p or ps -ef --forest.

Processes

The Process Descriptor: task_struct

struct task_struct__state (R, S, D…)pid, tgidprio, policyse: vruntime, deadlinemmfilesfssighand, signalcrednsproxycgroupsparent, childrenmm_structVMAs, pgd (page table)files_structfd array → struct filefs_structroot dir, cwd, umasksighand_structsignal handlerscreduid, gid, capabilitiesnsproxypid, net, mnt… namespacescss_setcgroup limitssched_entitynode in the EEVDF treethreads can share theseevery task: its own kernel stack

In Linux there is no structural difference between a process and a thread: both are a task (task_struct). The difference is which substructures they share. The PID users see is really the tgid (thread group ID). With __state D (uninterruptible sleep) a task does not die at once even on SIGKILL, which is why most waits now use TASK_KILLABLE.

Processes · Step by step

clone() and Threads

fork() = clone(SIGCHLD)parentPID 900, TGID 900childPID 901, TGID 901mm (address space)mm (address space)files (open files)files (open files)fs (root, cwd)fs (root, cwd)sighand (handlers)sighand (handlers)nsproxy (namespaces)nsproxy (namespaces)copy (COW): separate but identical at first

In glibc, fork() is a clone() called with just the SIGCHLD flag: the child gets a copy of every structure (memory via COW). Its own PID and TGID: a new process.

pthread_create()parentPID 900, TGID 900threadTID 902, TGID 900mm (address space)files (open files)fs (root, cwd)sighand (handlers)nsproxy (namespaces)everything shared: same address space

pthread_create() → clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | …). Everything is shared; the new task joins the same TGID. NPTL: every thread is a kernel task (the 1:1 model).

container: clone(CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWNET …)parentPID 900, TGID 900childPID 1 (inside)mm (address space)mm (address space)files (open files)files (open files)fs (root, cwd)fs (root, cwd)sighand (handlers)sighand (handlers)nsproxy (namespaces)new namespacescopy + new namespaces

Namespace flags (CLONE_NEWPID, CLONE_NEWNS, CLONE_NEWNET…) give the child a new view: inside, it believes it is PID 1. This is the basis of containers.

Scheduling and Booting

From CFS to EEVDF: Fair Sharing

VersionSelection rule of the fair classData structure
2.4 (2001)O(n): every pick scans all ready tasksa single list
2.6.0–2.6.22 (2003)O(1): a list per priority, active and expired arraysarray of 140 lists + bitmap
2.6.23–6.5 (2007)CFS: smallest vruntimered-black tree
6.6+ (2023)EEVDF: earliest virtual deadline among eligible tasks (v ≤ V)the same tree, augmented with subtree data
  • Unchanged: the vruntime in sched_entity, the nice → weight table (sched_prio_to_weight, nice 0 → 1024) and the tree in the run queue.
  • CFS's latency knobs (sched_latency, wakeup granularity) gave way to a single base slice (base_slice_ns); the virtual deadline is d = v + slice × 1024 / weight.
  • A latency-sensitive task can ask for a shorter slice with sched_setattr() (6.12+): a short slice means an early deadline and being picked more often.

Scheduling and Booting · Step by step

Booting: From UEFI to systemd

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• POST, initialize hardware• boot entry in NVRAM• from the ESP (FAT32) partition• load the EFI application• Secure Boot: signature check (shim)

At power-on the UEFI firmware tests the hardware and loads the EFI application from the ESP partition. With Secure Boot on, each stage verifies the next one's signature.

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• menu, kernel choice• command line: root=… quiet• vmlinuz + initramfs• load their files into memory• jump to the kernel

The bootloader loads the kernel image (vmlinuz) and the initramfs into memory and passes the command-line parameters. The kernel can also be started directly as an EFI application (UKI).

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• decompress, start_kernel()• memory, interrupts, timer• PID 0 → idle task• kernel_init (PID 1)• kthreadd (PID 2)Linux is up

The kernel decompresses itself, and start_kernel() sets up memory management, interrupts and the scheduler. The first task becomes PID 0, the idle task; kernel_init (PID 1) and kthreadd (PID 2) are created.

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• a cpio archive in RAM• needed modules: NVMe, LVM• LUKS decryption• mount the real root• switch_root → /sbin/initLinux is up

The drivers needed to mount the root file system may not be built into the kernel (NVMe, RAID, encrypted disks). The initramfs provides a temporary root in RAM, mounts the real root and does a switch_root.

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• unit files• dependency graph• parallel startup• journald, udevd, network• default.targetLinux is up

PID 1 is now systemd: it starts services in parallel according to the dependencies in the unit files and reaches the target (multi-user.target or graphical.target).

UEFIfirmwareGRUB2 /systemd-bootKernelvmlinuzinitramfstemporary rootsystemdPID 1Sessiongetty, gdm, sshd• agetty → login → bash• or a gdm graphical session• sshd for remote login• systemd --user• systemd-analyze: timingLinux is up

On the console agetty → login → shell; on the desktop gdm; remotely sshd. The classic UNIX chain init → getty → login → sh is still recognizable.

Memory Management

The Virtual Address Space of a Process

Kernel spacethe same in every process; not accessible in user modenoncanonical holethese addresses cannot be usedStack ↓main, local variables; random start with ASLRmmap region ↓libc.so, ld.so, mapped files, thread stacksHeap ↑ brkmalloc's small requests; grows with brkbsszero-initialized globalsdatainitialized globalstext (code)read-only + executable; shared between processesNULL page unmapped → SIGSEGVx86-64, 4 levels (48 bits):user 2⁴⁷ B = 128 TiBkernel 128 TiB5 levels, LA57 (57 bits):user 2⁵⁶ B = 64 PiBcat /proc/PID/maps

Each region is described by a VMA (vm_area_struct); VMAs are kept in a “maple tree” inside the mm_struct. The stack and mmap grow down and the heap grows up; the gap between them is only virtual and costs no physical memory.

Memory Management

Sharing, Mapped Files and Memory Calls

Process AProcess BPhysical memorytextpage cachedata Astack Adata Bstack Bstack Adata.db (mapped)data Atextstack Bdata.db (mapped)data Btextgreen arrows: shared frames
CallFunction
brk / sbrkGrows/shrinks the heap (data segment) by moving its end
mmapMaps a file, a device or anonymous memory into the address space
munmapRemoves a mapping and returns the memory to the system
mprotectChanges a region's permissions (r/w/x)
madviseGives the kernel a usage hint (e.g. MADV_DONTNEED)
msyncWrites a shared mapping's dirty pages to the file

MAP_SHARED: writes are visible in the file and to other processes. MAP_PRIVATE: copy on write; the file does not change. glibc malloc serves small requests from the heap and requests ≥ 128 KiB directly with mmap.

Memory Management · Step by step

Page-Table Walk: 4 and 5 Levels

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 BPUD table512 entries × 8 BPMD table512 entries × 8 BPTE table512 entries × 8 B48-bit address: 4 × 9-bit indices + 12-bit offset

On x86-64 a 4 KiB page → a 12-bit offset. The remaining 36 bits are split across four tables of 512 entries (9 bits) each. Bits 63–48 copy bit 47 (a canonical address).

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 BPMD table512 entries × 8 BPTE table512 entries × 8 B

The CR3 register points to the process's top-level table (PGD); CR3 changes on a context switch. Index 254 → the address of the PUD table.

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 B[232]PMD table512 entries × 8 BPTE table512 entries × 8 B

PUD[232] points to a PMD table. (A 1 GiB huge page could also end here.)

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 B[232]PMD table512 entries × 8 B[225]PTE table512 entries × 8 B

PMD[225] points to a PTE table. (A 2 MiB huge page / THP ends here.)

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 B[232]PMD table512 entries × 8 B[225]PTE table512 entries × 8 B[181]

PTE[181]: the present bit, frame number, and R/W, U/S, NX, dirty (D) and accessed (A) bits. Present = 0 means a page fault.

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 B[232]PMD table512 entries × 8 B[225]PTE table512 entries × 8 B[181]4 KiB frameframe0x3c5a1+ 0xe88physical address = 0x3c5a1e88

The frame number is joined with the offset: physical address = frame × 4096 + offset.

virtual address 0x00007f3a1c2b5e88sign = 0bits 63–48PGD = 254bits 47–39PUD = 232bits 38–30PMD = 225bits 29–21PTE = 181bits 20–12offset = 0xe88bits 11–0CR3PGD table512 entries × 8 B[254]PUD table512 entries × 8 B[232]PMD table512 entries × 8 B[225]PTE table512 entries × 8 B[181]4 KiB frameframe0x3c5a1+ 0xe88physical address = 0x3c5a1e88TLB: the next access skips 4 memory reads

Four extra reads on every access are expensive: the TLB caches the translation. Five-level paging (LA57, Linux 4.14+) inserts a P4D level for 57-bit addresses. Linux's generic model has 5 levels; when the hardware uses fewer, levels are folded.

Memory Management

Representing Physical Memory

NUMA node 0 (pglist_data)ZONE_DMA0–16 MiB (legacy ISA)ZONE_DMA320–4 GiB (32-bit DMA)ZONE_NORMALthe rest of RAMZONE_MOVABLEmovable pagesin each zone:free_area[0…10] (buddy lists)LRU lists, watermarksmem_map: the struct page array70: free80: free150: mapped200: free64 B per 4 KiB page→ 1.56% of RAMaddress_space (file)folio: manages contiguouspages as one unit (5.16+)free list

Linux describes physical memory as a node → zone → page hierarchy. On a multisocket machine each CPU prefers to allocate from its own node (NUMA). 64-bit systems have no ZONE_HIGHMEM; it survives only in 32-bit kernels. Each zone's free_area array holds the buddy allocator's free lists for orders 0–10 (4 KiB–4 MiB); see /proc/buddyinfo.

Memory Management

The SLUB Object Allocator

Buddy allocator: page frames (alloc_pages)kmem_cache: task_structkmem_cache: dentry (192 B)kmem_cache: kmalloc-64kmem_cache: inode_cacheinside the dentry cache:CPU 0 active slablock-free fast pathpartial slabthose with free objectsfull slabfully in useslab = 1 or a few contiguous pages

The kernel allocates many small objects of the same size (task_struct, dentry, inode); allocating a page for each would be wasteful. SLUB keeps object caches; kmalloc uses size classes from 8 B to 8 KiB. SLOB (6.4) and SLAB (6.8) were removed: SLUB is the only allocator. For large areas that need not be physically contiguous, vmalloc.

Memory Management · Step through the code

The SLUB Free List: Code Trace

void *slab_alloc(kmem_cache *c) {
    void *obj = c->freelist;      /* head of list */
    if (!obj)
        obj = new_slab(c);        /* slow path */
    c->freelist = *(void **)obj;   /* next */
    return obj;
}
void slab_free(kmem_cache *c, void *obj) {
    *(void **)obj = c->freelist;   /* inside the object */
    c->freelist = obj;
}
/* a,b = alloc; free(a); c,d,e,f = alloc */
slab page (4 KiB)+0free+1024free+2048free+3072freefreelist → +0 → +1024 → +2048 → +3072 → NULL

A new slab: a 4 KiB page cut into four 1 KiB objects. Free objects form a list; the “next” pointer is stored not in a separate structure but inside the free object itself.

slab page (4 KiB)+0a+1024free+2048free+3072freefreelist → +1024 → +2048 → +3072 → NULLa = alloc()

slab_alloc: the head of the list (+0) is taken, and freelist advances to the next pointer stored in it (+1024). No lock, no page allocation: a few instructions.

slab page (4 KiB)+0a+1024b+2048free+3072freefreelist → +2048 → +3072 → NULLb = alloc()

b gets +1024; freelist points to +2048.

slab page (4 KiB)+0free+1024b+2048free+3072freefreelist → +0 → +2048 → +3072 → NULLfree(a)

a is freed: the old head (+2048) is written into the object's first 8 bytes and freelist becomes +0. The list works like a stack (last in, first out).

slab page (4 KiB)+0c+1024b+2048free+3072freefreelist → +2048 → +3072 → NULLc = alloc()

c takes the +0 that a just released: most likely still in the CPU cache, so a “hot” object.

slab page (4 KiB)+0c+1024b+2048d+3072efreelist → NULLd, e = alloc()

d takes +2048 and e takes +3072. The next pointer inside +3072 was NULL: the slab is full and freelist is empty.

slab page (4 KiB)+0c+1024b+2048d+3072e2:+0f2:+1024free2:+2048free2:+3072freefreelist → 2:+1024 → 2:+2048 → 2:+3072 → NULLf = alloc()

For f the list is empty: the slow path. A new page comes from the page (buddy) allocator, is cut into four objects, and the first goes to f. The common case fast, the rare case correct.

Memory Management · Step by step

Page Cache, Reclaim and OOM

5 GiBanonymous (apps)8 GiBpage cachefree 2 GiBRAM 16 GiBfree memory2 GiBhighlowmin(magnified)kswapd0background reclaimMGLRU generationsgen 0 (cold) … gen 3 (hot)zswap → swapcold anonymous pagesdirect reclaimthe allocating process waitsOOM killerhighest oom_score → SIGKILLswap: 0 GiBzswap + swap space

Free memory is wasted memory: Linux uses unused RAM as the page cache for file data. “available” in free -h also counts the reclaimable part of this cache.

8.3 GiBanonymous (apps)6 GiBpage cacheRAM 16 GiBfree memory0.7 GiBhighlowmin(magnified)kswapd0background reclaimMGLRU generationsgen 0 (cold) … gen 3 (hot)zswap → swapcold anonymous pagesdirect reclaimthe allocating process waitsOOM killerhighest oom_score → SIGKILLswap: 0 GiBzswap + swap space

The application grew and free memory dropped below the low watermark: kswapd wakes and frees clean cache pages in the background (dirty ones are written to disk first).

9 GiBanonymous (apps)4.7 GiBpage cache1.3 GiBRAM 16 GiBfree memory1.3 GiBhighlowmin(magnified)kswapd0background reclaimMGLRU generationsgen 0 (cold) … gen 3 (hot)zswap → swapcold anonymous pagesdirect reclaimthe allocating process waitsOOM killerhighest oom_score → SIGKILLswap: 1 GiBzswap + swap space

MGLRU (6.1) sorts pages into access generations; the coldest generation goes first. Cold anonymous pages have no file: zswap compresses them in RAM and, if needed, writes them to swap.

11.5 GiBanonymous (apps)3.2 GiBpage cacheRAM 16 GiBfree memory0.3 GiBhighlowmin(magnified)kswapd0background reclaimMGLRU generationsgen 0 (cold) … gen 3 (hot)zswap → swapcold anonymous pagesdirect reclaimthe allocating process waitsOOM killerhighest oom_score → SIGKILLswap: 2 GiBzswap + swap space

Allocation outpaces reclaim and free memory is below the min watermark: the allocating process does direct reclaim itself and stalls (latency rises).

4.6 GiBanonymous (apps)2 GiBfree 8.4 GiBRAM 16 GiBfree memory8.4 GiBhighlowmin(magnified)kswapd0background reclaimMGLRU generationsgen 0 (cold) … gen 3 (hot)zswap → swapcold anonymous pagesdirect reclaimthe allocating process waitsOOM killerhighest oom_score → SIGKILLswap: 2 GiBzswap + swap spacemem_hog (PID 7311)killed

If nothing else works, the OOM killer kills the process with the highest oom_score (usually the largest) with SIGKILL; oom_score_adj can influence the choice. If a cgroup limit is exceeded, the victim is picked from that group only.

Input/Output

Devices Are Files: Major and Minor Numbers

$ ls -l /dev     # selected lines
brw-rw---- 1 root disk   8, 0 sda
brw-rw---- 1 root disk   8, 1 sda1
brw-rw---- 1 root disk 259, 0 nvme0n1
crw-rw-rw- 1 root root   1, 3 null
crw-rw-rw- 1 root tty    5, 0 tty
  • c character device: byte stream, usually uncached (terminals, /dev/null, mice)
  • b block device: fixed-size blocks, random access; uses the page cache and I/O scheduler
  • Network interfaces (eth0) aren't in /dev; they're used via sockets
  • devtmpfs + udev create nodes dynamically as devices appear
open("/dev/sda1")i-node: type bmajor 8, minor 1block device table7 → loop8 → sd (SCSI disk)259 → blkext (NVMe)minor: 0 = whole disk, 1 = partition 116 minors per disk: sdb = 16

“major, minor” replaces the size column. The major number selects the driver, the minor the unit it manages. Applications reach disks and terminals with the same open/read/write.

Input/Output

Structure of the Linux I/O System

System calls: open, read, write, ioctl, mmap, send, recvVFS (virtual file system)Socket layerCharacter devicestty + line disciplinecharacter driverBlock devicesext4 / XFS / Btrfspage cacheblock layer: blk-mqI/O schedulerblock driver (NVMe)Network devicesTCP / UDPIP + netfilterqueueing discipline (qdisc)network driver (NAPI)Hardware: terminal, NVMe SSD, network card

The three device types go down three separate paths. Classic BSD had a similar split; System V's STREAMS module stack never entered the mainline Linux kernel. On the network path data travels in sk_buff structures; XDP/eBPF can process packets at the driver level.

Input/Output

The Driver Interface: file_operations and Terminals

static const struct file_operations my_fops = {
    .owner          = THIS_MODULE,
    .open           = my_open,
    .release        = my_release,     /* close */
    .read           = my_read,
    .write          = my_write,
    .unlocked_ioctl = my_ioctl,
    .poll           = my_poll,
    .mmap           = my_mmap,
};
cdev_init(&cdev, &my_fops);  /* major:minor → fops */
Old UNIX entriesLinux equivalent
k_open, tty_open, pr_open, ip_open.open
k_close, tty_close, pr_close….release
mem_read, k_read, tty_read.read
mem_write, tty_write, pr_write….write
k_ioctl, tty_ioctl, pr_ioctl….unlocked_ioctl
Terminal I/O (termios): tcgetattr/tcsetattr read and write terminal parameters: canonical mode (line editing, ICANON) or raw mode, ECHO. cfset/cfget[io]speed set the input/output baud rate; today mostly for serial ports, since terminals are pseudoterminals (pty).

The classic textbook table lists separate entry points per driver (k_*, tty_*, pr_*, ip_*); Linux gathers them into one structure of function pointers. The VFS routes every read() to the driver's .read.

Input/Output

The Block Layer: blk-mq and I/O Schedulers

The Linux block layer blk-mq is multiqueue: each CPU writes to its own software queue, and requests pass through an optional I/O scheduler (none, mq-deadline, bfq, kyber) before being spread over the device's hardware queues. The active scheduler is read and changed per device in /sys/block/<device>/queue/scheduler.

Input/Output · Step by step

Networking: Sockets and Connection Setup

ServerClientsocket() → fd 3bind(:80)listen(3, 128)accept() → fd 4read(4) / write(4)socket() → fd 3connect(server:80)write(3) / read(3)close(3) → FIN

The server creates a socket (fd 3), binds it to port 80 (bind) and opens a listen queue with listen. A socket is a file descriptor too.

ServerClientsocket() → fd 3bind(:80)listen(3, 128)accept() → fd 4read(4) / write(4)socket() → fd 3connect(server:80)write(3) / read(3)close(3) → FINaccept blocked: waiting for a connection

The server blocks in accept. The client creates its own socket.

ServerClientsocket() → fd 3bind(:80)listen(3, 128)accept() → fd 4read(4) / write(4)socket() → fd 3connect(server:80)write(3) / read(3)close(3) → FINSYNSYN-ACKACK

With connect, the client kernel performs the three-way handshake (SYN, SYN-ACK, ACK); the application never sees these packets.

ServerClientsocket() → fd 3bind(:80)listen(3, 128)accept() → fd 4read(4) / write(4)socket() → fd 3connect(server:80)write(3) / read(3)close(3) → FINSYNSYN-ACKACKthe kernel completed the handshake,accept returns a new socket

Once connected, accept returns a new socket (fd 4); fd 3 keeps listening. Servers with many clients manage thousands of sockets with epoll or threads.

ServerClientsocket() → fd 3bind(:80)listen(3, 128)accept() → fd 4read(4) / write(4)socket() → fd 3connect(server:80)write(3) / read(3)close(3) → FINSYNSYN-ACKACKthe kernel completed the handshake,accept returns a new socketGET / HTTP/1.1200 OK …

Data flows with write/read: the kernel puts it in sk_buffs, adds TCP/IP headers, and the driver writes it to the card's ring. close sends a FIN.

File Systems

The Directory Tree and Mounting

/binbootdevetchomelibprocsystmpusrvarmnt→ usr/bin→ usr/libvirtualvirtualdevtmpfsalibinlibshareusbvfat (USB)photos/ docs/mount /dev/sdb1 /mnt/usb
  • /usr/bin: commands (/bin is now a link to it)
  • /etc: text configuration files
  • /dev: device files
  • /usr/lib: shared libraries, /usr/lib/modules: kernel modules
  • /usr: read-only, shareable software (bin, lib, share)
  • /home: user directories; /root: the administrator's
  • /var: variable data (logs, spools, caches)
  • /proc, /sys: the kernel's pseudo file systems
  • /boot: the kernel and initramfs
  • /tmp: temporary (tmpfs on most distributions)

Instead of Windows-style drive letters there is a single tree: another file system is mounted on any directory. The layout follows the FHS standard; most distributions moved /bin and /lib under /usr (“usrmerge”).

File Systems

The VFS: Descriptors, Open Files and i-nodes

Process A (fd)0tty1tty2tty3→ file#14child A′ (fork)0tty1tty2tty3→ file#14Process C0tty1tty2tty3→ file#24struct file #1f_pos = 150 O_RDONLYrefcount = 2struct file #2f_pos = 0refcount = 1dentry"x.txt"inode 1234size, mode, extentsext4 → diskVFS objects:superblock: a mounted file systeminode: the file itselfdentry: name → inode (cache)file: an open-file session

In Linux an open file is a struct file (f_pos, flags, reference count); the per-process table lives in task_struct → files_struct, and after fork() both processes point to the same struct file. The objects' operation tables (super_operations, inode_operations, file_operations) route each call to ext4's, XFS's, Btrfs's, NFS's or procfs's own function; dentries are kept in the dcache.

File Systems

File and Directory System Calls, stat

File callFunction
open, creatOpen / create, return an fd
closeClose the descriptor
read, writeRead / write at the position
lseekMove the position
stat, fstat, lstatGet information (lstat: the link itself)
pipe, dup2Create a pipe / duplicate an fd
fcntlLocks, flags, etc.
mkdir, rmdirCreate / remove a directory (if empty)
link, unlinkAdd / remove a name
rename, chdirMove (atomically) / change cwd
getdents64Read directory entries
stat fieldMeaning
st_devDevice the file resides on
st_inoi-node number
st_modeType + permission bits
st_nlinkNumber of hard links
st_uid, st_gidOwner and group
st_sizeSize in bytes
st_atimeLast access time
st_mtimeLast content change
st_ctimeLast i-node change (not creation!)
st_blocksNumber of 512 B blocks allocated
stat("a.txt", &st)directory: a.txt → 812i-node 812st_ino, st_mode, st_nlink, st_size, times …

opendir/readdir/closedir are not system calls but library functions built on getdents64. The creation time is available only through the newer statx() (stx_btime).

File Systems · Step by step

File Locking

0123456789101112131415A: shared lock 4–7byteshared (read) locks may overlap; an exclusive (write) lock may overlap no lock

Process A puts a shared (read) lock on bytes 4–7: fcntl(fd, F_SETLK, &fl) with l_type = F_RDLCK, l_start = 4, l_len = 4.

0123456789101112131415A: shared lock 4–7B: shared lock 6–9byteshared (read) locks may overlap; an exclusive (write) lock may overlap no lock

B asks for a shared lock on 6–9: shared locks may overlap freely, so the request is granted.

0123456789101112131415A: shared lock 4–7B: shared lock 6–9C: shared lock 2–11byteshared (read) locks may overlap; an exclusive (write) lock may overlap no lock

C puts a shared lock on 2–11; bytes 6–7 are now covered by three locks.

0123456789101112131415A: shared lock 4–7B: shared lock 6–9C: shared lock 2–11byteD: exclusive (write) lock on byte 9 → blocks with F_SETLKWshared (read) locks may overlap; an exclusive (write) lock may overlap no lock

D asks for an exclusive (F_WRLCK) lock on byte 9: it conflicts with B's and C's locks. F_SETLK fails at once; F_SETLKW waits until the locks go away. If the kernel detects a wait cycle it returns EDEADLK.

These locks are advisory: a process that never asks for the lock can still write. For whole files there is flock(); for thread-safe use, OFD locks bound to the open file.

File Systems

ext2/ext4 Disk Layout and the i-node

Disk partition:bootblock group 0block group 1block group 2…block group nsuperblockgroup descriptorsblock bitmapi-node bitmapi-node tabledata blocksi-node (256 B)mode (type + perms)uid, gid, sizeatime, mtime, ctimelink count12 direct blockssingle indirectdouble indirecttriple indirect12 × 4 KiB = 48 KiB+ 1024 × 4 KiB = 4 MiB+ 1024² × 4 KiB = 4 GiB+ 1024³ × 4 KiB = 4 TiBext4: extent tree4 extents fit in the i-node:(logical block, length, physical block)0, 2048, 34816 → 8 MiB in one entryone extent at most 32768 blocks= 128 MiB; file ≤ 16 TiBa few large contiguous piecesinstead of indirect blocks

ext2 split the classic UNIX layout (boot block, superblock, i-nodes, data) into block groups: an i-node and its data are kept close in the same group, and the superblock is backed up. With indirect blocks the theoretical limit is ~4 TiB (2 TiB in ext2 because of the i_blocks field). The root directory's i-node number is always 2.

File Systems · Step by step

ext4 Journaling

Memory (page cache)JournalHome locations on diskdata Di-node M1bitmap M2extent M3dirty pages

One write() + fsync() changes several blocks: the data (D) plus metadata such as the i-node, the block bitmap and the extent. A crash after writing one but not another leaves the file system inconsistent.

Memory (page cache)JournalHome locations on diskdata Di-node M1bitmap M2extent M3dirty pagesdata D

In the default data=ordered mode the data blocks are written to their home locations first, so metadata never points at a block of garbage.

Memory (page cache)JournalHome locations on diskdata Di-node M1bitmap M2extent M3dirty pagesdata DT42 descriptorM1M2M3T42 commit

The metadata blocks are written to the journal as one transaction (T42), ending with a commit record. Once the commit reaches the disk, the transaction is durable.

Memory (page cache)JournalHome locations on diskdata Di-node M1bitmap M2extent M3dirty pagesdata DT42 descriptorM1M2M3T42 commitM1M2M3checkpoint: journal space freed

Checkpoint: the metadata is written to its home locations and the journal space is reused (a circular buffer).

Memory (page cache)JournalHome locations on diskdata Di-node M1bitmap M2extent M3dirty pagesdata DT42 descriptorM1M2M3T42 commitM1M2M3crash after commit → T42 is replayed at mountcrash before commit → T42 is ignored; the old consistent state

After a crash, instead of a full fsck scan the journal is read: committed transactions are replayed, incomplete ones discarded. Consistency in seconds.

Other modes: data=journal (data goes to the journal too; safest, slowest) and data=writeback (no ordering guarantee). XFS also journals metadata; Btrfs stays consistent with copy on write instead of a journal.

File Systems · Step by step

Directories and Path Resolution

open("/home/ali/notes.txt")/ (i-node 2).2..2etc524289home131073usr786433home (131073)ali (131074)

An absolute path starts at the root: the root directory's i-node (2) is read and its data blocks are searched for “home” → 131073. The x (search) permission is checked for every directory.

open("/home/ali/notes.txt")/ (i-node 2).2..2etc524289home131073usr786433home (131073).131073..2ali131074ayse131090ali (131074)

“ali” is looked up in the data of the “home” directory → 131074.

open("/home/ali/notes.txt")/ (i-node 2).2..2etc524289home131073usr786433home (131073).131073..2ali131074ayse131090ali (131074).131074..131073photos132011notes.txt132010

“notes.txt” in the “ali” directory → 132010. (A relative path would start at the process's cwd.)

open("/home/ali/notes.txt")/ (i-node 2).2..2etc524289home131073usr786433home (131073).131073..2ali131074ayse131090ali (131074).131074..131073photos132011notes.txt132010i-node 132010-rw-r--r-- alisize 2 KiBextent: 1 block→ struct file, fd 3

The last component's i-node is read, permissions are checked, and a struct file is created and an fd returned.

open("/home/ali/notes.txt")/ (i-node 2).2..2etc524289home131073usr786433home (131073).131073..2ali131074ayse131090ali (131074).131074..131073photos132011notes.txt132010i-node 132010-rw-r--r-- alisize 2 KiBextent: 1 block→ struct file, fd 3directory entry (ext2/4): i-node no · record length · name length · type · namea deleted entry is merged into the previous one's record length; large directories use an htree (hash tree)

If every step needed a disk read it would be slow: the dentry cache (dcache) keeps name → i-node mappings in memory, so hot paths resolve without touching the disk.

File Systems

Hard and Symbolic Links

/home/alia.txt500s777/home/ali/backupb.txt500i-node 500link count = 2hard linki-node 777 (link)target: "a.txt"by pathdata blocks
$ ln a.txt backup/b.txt    # hard
$ ln -s a.txt s            # symbolic
$ ls -li
500 -rw-r--r-- 2 ali ali 9 a.txt
777 lrwxrwxrwx 1 ali ali 5 s -> a.txt
  • Hard link: the same i-node, and the link count goes up. rm a.txt removes only the name; the data is freed when the count reaches 0 (and no open fd remains).
  • A hard link cannot cross file-system boundaries or point to a directory.
  • Symbolic link: holds the target's path; it can point to another file system or a directory. If the target is deleted, the link dangles.

File Systems · Step through the code

Link Count and unlink: Code Trace

int fd = open("a.txt", O_CREAT|O_RDWR, 0644);
write(fd, "data", 4);
link("a.txt", "b.txt");      /* hard link */
symlink("a.txt", "s.txt");   /* symbolic */
unlink("a.txt");
int r1 = open("b.txt", O_RDONLY);
int r2 = open("s.txt", O_RDONLY);
unlink("b.txt");
close(r1);
close(fd);
directorya.txt812i-node 812 · "data"link count = 1open files = 1a.txt created, 4 bytes written

open allocates a new i-node (812) and adds the entry “a.txt → 812” to the directory: link count 1. fd 3 is open: open-file count 1.

directorya.txt812b.txt812i-node 812 · "data"link count = 2open files = 1b.txt: a second name for the same i-node

link only writes a new directory entry: b.txt → 812. No data is copied; the link count is 2. a.txt and b.txt are equals; neither is the “original”.

directorya.txt812b.txt812s.txt813i-node 812 · "data"link count = 2open files = 1i-node 813 (link)contents: "a.txt"s.txt: a separate file holding the path

symlink creates a separate i-node (813) whose contents are just the path “a.txt”. 812's link count does not change.

directoryb.txt812s.txt813i-node 812 · "data"link count = 1open files = 1i-node 813 (link)contents: "a.txt"name a.txt removed, data remains

unlink("a.txt") removes the name and drops the link count to 1. The data is still reachable through b.txt.

directoryb.txt812s.txt813i-node 812 · "data"link count = 1open files = 2i-node 813 (link)contents: "a.txt"b.txt opened

b.txt opens fine: r1 = 4, open-file count 2.

directoryb.txt812s.txt813i-node 812 · "data"link count = 1open files = 2i-node 813 (link)contents: "a.txt"s.txt → "a.txt" → missing

Opening s.txt, the kernel follows the path inside it (“a.txt”); that name is gone. The symbolic link dangles: r2 = −1, ENOENT.

directorys.txt813i-node 812 · "data"link count = 0open files = 2i-node 813 (link)contents: "a.txt"no names left, but two fds open

The last name is gone too: link count 0. But two descriptors are open, so the i-node and data are not freed yet; ls no longer shows the file.

directorys.txt813i-node 812 · "data"link count = 0open files = 1i-node 813 (link)contents: "a.txt"r1 closed

close(r1): open-file count 1. Reads and writes through fd 3 still work.

directorys.txt813i-node 812 freei-node 813 (link)contents: "a.txt"links 0 and open 0: blocks freed

The last descriptor is closed: both counters are 0, so the i-node and data blocks are freed. The “open, then unlink at once” idiom for temporary files relies on this.

File Systems

Beyond ext4: XFS, Btrfs and Others

File systemKey featureTypical use
ext4Journaling, extents, mature with a fast fsckDefault on most distributions
XFSParallel I/O, large files, delayed allocationRHEL default, large servers
BtrfsCopy on write, snapshots, checksums, compression, subvolumesFedora, openSUSE default
F2FSFlash-friendly, log-structuredAndroid phones
tmpfsEntirely in RAM (page cache + swap)/tmp, /run, /dev/shm
NFS, SMBNetwork file systemsShared home directories
root v1root v2nodenodenode′B1B2B3B4B4′when B4 changes only the path is copied;root v1 = a snapshot

Thanks to the VFS they all work with the same system calls; findmnt or df -T shows which file system is mounted where.

File Systems

/proc and /sys: Windows into the Kernel

$ cat /proc/loadavg
0.42 0.37 0.30 2/1234 98765
$ grep -E "MemTotal|MemAvailable" /proc/meminfo
MemTotal:       16303452 kB
MemAvailable:    9876544 kB
$ ls /proc/self
cmdline  cwd  environ  exe  fd  maps  status  …
$ cat /sys/block/nvme0n1/queue/scheduler
[none] mq-deadline kyber bfq
$ sysctl vm.swappiness        # = /proc/sys/vm/swappiness
vm.swappiness = 60
/proc

Per-process directories (/proc/PID/status, maps, fd/) and kernel statistics. ps, top and free read their data here. /proc/sys: tunable kernel parameters.

/sys (sysfs)

The device model: every device, driver and bus is a directory; one value per file. /sys/fs/cgroup is the cgroup v2 interface.

Security · Step by step

chmod and umask Arithmetic

$ chmod 754 script.shsgtrwxrwxrwxrequested0754000111101100rwxr-xr--result0754000111101100rwxr-xr--

Each octal digit is three bits: 7 = 111 = rwx, 5 = 101 = r-x, 4 = 100 = r--.

$ chmod g+w,o-r script.shsgtrwxrwxrwxbefore0754000111101100rwxr-xr--g+w: OR 0200020000000010000o-r: AND ~0040004000000000100result0770000111111000rwxrwx---

Symbolic mode changes the existing bits: the group write bit is added and the others' read bit removed → 0770.

$ umask 022 ; touch a ; mkdir dsgtrwxrwxrwxfile request0666000110110110umask0022000000010010result0644000110100100rw-r--r--

A new file asks for 666 and a directory for 777; the bits in umask are cleared: 666 & ~022 = 0644, directory 777 & ~022 = 0755. (Bit clearing, not subtraction!)

$ umask 027 ; touch a ; mkdir dsgtrwxrwxrwxfile request0666000110110110umask0027000000010111result0640000110100000rw-r-----

A stricter umask: file 666 & ~027 = 0640 (rw-r-----), directory 777 & ~027 = 0750 (rwxr-x---). Others see nothing.

$ chmod 4755 passwd ; chmod 1777 /tmpsgtrwxrwxrwxsetuid + 7554755100111101101rwsr-xr-xsticky + 7771777001111111111rwxrwxrwt

4xxx setuid: the running process takes the file owner's identity → rwsr-xr-x. 2xxx setgid (on a directory: new files inherit the group). 1xxx sticky bit: everyone writes in /tmp, but a file can be deleted or renamed only by the file's owner, the directory's owner or root (a suitably privileged process) → rwxrwxrwt.

Check: stat -c "%a %A" file shows the octal and symbolic modes together; umask -S prints the mask symbolically.

Security

Access Control, root and Capabilities

  1. euid = 0 (root) → allow (execution needs at least one x bit)
  2. euid = file owner → look only at the owner bits
  3. egid or a supplementary group = file group → group bits
  4. otherwise the other bits

The first matching class wins: for a ----rw-rw- file, its owner ali cannot read it while others can.

Capabilities: with setcap cap_net_raw+ep /usr/bin/ping, ping opens a raw socket without being setuid root.
CallFunction
chmodChanges a file's permission mode
chownChanges owner and group
accessTests access with the real uid/gid
getuid, geteuidReal / effective uid
getgid, getegidReal / effective gid
setuid, setresuidChanges the uid (dropping privilege)
setgidChanges the gid
umaskPermission mask for new files

User and group IDs live in /etc/passwd and /etc/group; password hashes are kept in /etc/shadow, readable only by root. sudo grants authorized users root rights per command.

Security · Step through the code

File Permission Check: Code Trace

int has_perm(cred *c, inode *f, int req) {
    int bit, m = f->mode;       /* r4 w2 x1 */
    if (c->euid == 0)           /* root */
        return !(req & 1) || (m & 0111);
    if (c->euid == f->uid)
        bit = (m >> 6) & 7;     /* owner */
    else if (in_group(c, f->gid))
        bit = (m >> 3) & 7;     /* group */
    else
        bit = m & 7;            /* other */
    return (bit & req) == req;
}
report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: — · —

report.txt: owner ali, group team, mode 0640 = rw-r-----. veli is in the team group; can is not.

report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: ali (uid 1000) · wallow

ali owns the file: the owner bits are chosen, bit = 6 (rw-). 6 & 2 == 2: allowed.

report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: veli (uid 1001) · wdeny (EACCES)

veli is in the team group: the group bits are chosen, bit = 4 (r--). 4 & 2 ≠ 2: denied.

report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: veli (uid 1001) · rallow

veli is in the team group: the group bits are chosen, bit = 4 (r--). 4 & 4 == 4: allowed.

report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: can (uid 1002) · rdeny (EACCES)

can is neither the owner nor in the group: the other bits are chosen, bit = 0 (---). 0 & 4 ≠ 4: denied.

report.txt: owner ali, group team, mode 0640ownerrw-groupr--other---request: root (uid 0) · reuid 0: permission bits ignoredallow

root (euid 0): for reading and writing the permission bits are not checked at all; allowed. Only execution requires at least one x bit.

report.txt: owner ali, group team, mode 0066owner---grouprw-otherrw-request: ali (uid 1000) · rdeny (EACCES)

Take mode 0066 (----rw-rw-): can and veli may read, but ali falls into the owner class, which has no bits: denied. The first matching class wins; the other bits are never consulted.

Security · Step by step

Containers: Namespaces + cgroups

One Linux kernel (host)Host processessystemd (PID 1)sshd (PID 820)containerdapp → PID 48213Containerpid nsmnt nsnet nsuts nsipc nsuser nscgroup nstime ns

The runtime (runc, crun) creates new namespaces with clone()/unshare(): its own PID numbers, mount tree, network stack, host name, IPC, user mapping (root inside is an ordinary uid outside), cgroup and clock views.

One Linux kernel (host)Host processessystemd (PID 1)sshd (PID 820)containerdapp → PID 48213Containerpid nsmnt nsnet nsuts nsipc nsuser nscgroup nstime nsroot: overlayfsimage layers (ro) + upper (rw)

Inside the mount namespace, pivot_root switches to the image's root file system. The root is usually overlayfs: read-only image layers + a writable upper layer private to the container.

One Linux kernel (host)Host processessystemd (PID 1)sshd (PID 820)containerdapp → PID 48213Containerpid nsmnt nsnet nsuts nsipc nsuser nscgroup nstime nsroot: overlayfsimage layers (ro) + upper (rw)cgroup v2cpu.max · memory.max · pids.max

cgroup v2 limits resources: cpu.max = "50000 100000" (half a CPU), memory.max = 512M, pids.max = 100. Namespaces decide what is seen; cgroups decide how much is used.

One Linux kernel (host)Host processessystemd (PID 1)sshd (PID 820)containerdapp → PID 48213Containerpid nsmnt nsnet nsuts nsipc nsuser nscgroup nstime nsroot: overlayfsimage layers (ro) + upper (rw)cgroup v2cpu.max · memory.max · pids.maxsecuritydrop capabilities, seccomp, LSM

The attack surface is shrunk: unneeded capabilities are dropped, and no_new_privs, a seccomp filter (dozens of risky system calls blocked) and an AppArmor/SELinux profile are applied.

One Linux kernel (host)Host processessystemd (PID 1)sshd (PID 820)containerdapp → PID 48213Containerpid nsmnt nsnet nsuts nsipc nsuser nscgroup nstime nsroot: overlayfsimage layers (ro) + upper (rw)cgroup v2cpu.max · memory.max · pids.maxsecuritydrop capabilities, seccomp, LSMexecve(app)PID 1 inside

Finally execve: the application is PID 1 inside and PID 48213 on the host. All share the same kernel: much lighter than a VM, but a kernel bug affects every container.

Security

seccomp and Linux Security Modules (LSM)

applicationseccompDACcapabilitiesLSM hooksobjectopen("/etc/shadow")allow / errno / killrwx, uid, gidCAP_DAC_OVERRIDE?SELinux, AppArmoraccess grantedif any stage says “no”: EPERM / EACCES (seccomp may kill the process)
SELinux

Label-based mandatory access control (MAC): every process and file has a type, and the policy says what each type may do to which. RHEL, Fedora, Android.

AppArmor

Path-based profiles: “this program may access only these files”. Easy to write. Ubuntu, SUSE, Debian.

Landlock (5.13+)

An unprivileged process sandboxes itself: “from now on I may write only under ./data”.

seccomp-BPF

Filters the system calls a process may make; used by Chrome, systemd services, Docker and Android apps.

Android and Summary · Step by step

Android: Binder, Zygote and the Sandbox

Apps (APK)Android framework (Java/Kotlin API)ART runtime + native libraries (Bionic)HAL (hardware abstraction)Linux kernel + Binder, SELinuxzygoteframework preloadedsystem_serveruid 1000 (system)

Android runs on the Linux kernel but has no GNU user space: the C library is Bionic, and apps run on ART. Added to the kernel: Binder IPC, power management (wakelocks), mandatory SELinux.

Apps (APK)Android framework (Java/Kotlin API)ART runtime + native libraries (Bionic)HAL (hardware abstraction)Linux kernel + Binder, SELinuxzygoteframework preloadedsystem_serveruid 1000 (system)

At boot init starts the zygote process; zygote loads the framework classes and resources once and waits.

Apps (APK)Android framework (Java/Kotlin API)ART runtime + native libraries (Bionic)HAL (hardware abstraction)Linux kernel + Binder, SELinuxzygoteframework preloadedsystem_serveruid 1000 (system)com.example.appuid 10123 · untrusted_appfork() + identity

When an app launches, zygote fork()s: the loaded pages are shared via COW, which speeds up startup. The child switches to the app's unique uid, SELinux context and seccomp filter.

Apps (APK)Android framework (Java/Kotlin API)ART runtime + native libraries (Bionic)HAL (hardware abstraction)Linux kernel + Binder, SELinuxzygoteframework preloadedsystem_serveruid 1000 (system)com.example.appuid 10123 · untrusted_appfork() + identity/dev/bindersingle copy +caller uid

The app calls a service (location, camera) through Binder: the kernel moves the data into the receiver's mapped buffer with a single copy and passes along the caller's uid, which the service uses to check permissions.

Apps (APK)Android framework (Java/Kotlin API)ART runtime + native libraries (Bionic)HAL (hardware abstraction)Linux kernel + Binder, SELinuxzygoteframework preloadedsystem_serveruid 1000 (system)com.example.appuid 10123 · untrusted_appfork() + identity/dev/bindersingle copy +caller uid/data/data/com.example.appuid 10123 onlylmkd: kill background apps

Sandbox: every app is a separate Linux user, and its data is open only to itself. When memory runs low, the user-space lmkd uses PSI signals to kill unimportant background apps.

Summary

Summary: The Course's Concepts in Linux

TopicConceptIn Linux
StructuresSystem calls, monolithic kernelsyscall, LKM, eBPF
ProcessesPCB, creation, IPCtask_struct, fork/exec/wait, signals, pipes
ThreadsKernel threading modelclone(), NPTL 1:1
SchedulingFair sharing, real timeEEVDF, FIFO/RR/DEADLINE, sched_ext
SynchronizationLocks, condition variablesfutex, spinlock, RCU
DeadlocksDetection and preventionlockdep, fcntl EDEADLK
MemoryAllocation, fragmentationzones, buddy lists, SLUB
Virtual memoryPaging, replacement4/5-level tables, COW, MGLRU, zswap, OOM
File systemsi-nodes, directories, journalingVFS, ext4, XFS, Btrfs
I/ODrivers, schedulingdevice files, blk-mq, io_uring
MultiprocessorsLoad balancing, NUMAper-CPU queues, scheduling domains
SecurityAccess control, isolationrwx, capabilities, namespaces, SELinux, seccomp
DesignSeparating mechanism and policycgroups, sched_ext: policy in user space

Summary

Review Questions

  1. Which structures does fork() copy in the kernel, and which does it share? What does COW save?
  2. How does the shell set up ls | wc -l? What happens if the parent does not close the pipe ends?
  3. What is the difference between a process and a thread in Linux? Explain with clone flags.
  4. What changed in the fair class in Linux 6.6, and what stayed the same?
  5. What are the four 4-level table indices and the offset of the address 0x00007f3a1c2b5e88?
  6. Why is SLUB better than allocating pages directly for objects like task_struct?
  7. With umask 027, what permissions do a new file and a new directory get?
  8. What is the difference between a hard link and a symbolic link? What happens when the target is deleted?
  9. How is consistency restored after a crash with ext4 ordered journaling?
  10. Container = namespaces + cgroups: what does each provide? How does it differ from a VM?
Answers
  1. A new task_struct, PID and kernel stack are created; page tables are copied and writable pages made read-only; open files are shared by bumping the struct file reference count. With COW pages are copied only when written; when exec follows fork, almost nothing is copied.
  2. pipe() → fork; child 1 does dup2(write, 1) + exec ls; child 2 does dup2(read, 0) + exec wc. If the parent keeps the write end open, wc never sees EOF and waits forever.
  3. There is no structural difference: both are a task_struct. A thread shares the address space, files and handlers via CLONE_VM, CLONE_FILES, CLONE_SIGHAND and CLONE_THREAD, and sits in the same TGID.
  4. The selection rule changed: instead of the smallest vruntime, the earliest virtual deadline among eligible tasks (v ≤ V). vruntime, the nice weights and the red-black tree stayed; a base slice replaced the latency knobs.
  5. PGD = 254, PUD = 232, PMD = 225, PTE = 181, offset = 0xe88.
  6. Same-size objects are packed side by side in a slab: no internal fragmentation, O(1) allocation and freeing, and a lock-free fast path with per-CPU lists.
  7. File 666 & ~027 = 0640 (rw-r-----), directory 777 & ~027 = 0750 (rwxr-x---).
  8. A hard link is a second name for the same i-node; the data survives deletion of the target name. A symbolic link is a separate file holding the path; it dangles when the target is deleted. A hard link cannot cross file systems.
  9. Data is written first to its home location and metadata to the journal, then the commit. At mount, committed transactions are replayed and uncommitted ones discarded; no full fsck is needed.
  10. Namespaces isolate the view (PID, network, mounts…); cgroups limit resource usage. Containers share the host kernel: light, but weaker isolation than a VM.

Summary

References

  • A. S. Tanenbaum, H. Bos, Modern Operating Systems, 4th ed. (2014) / 5th ed. (2023), Pearson — Chapter 10: Case Study 1: Unix, Linux and Android.
  • A. Silberschatz, P. B. Galvin, G. Gagne, Operating System Concepts, 10th ed., Wiley, 2018 — Chapter 20: The Linux System.
  • R. Love, Linux Kernel Development, 3rd ed., Addison-Wesley, 2010.
  • M. Kerrisk, The Linux Programming Interface, No Starch Press, 2010; man7.org manual pages.
  • The Linux Kernel Documentation, docs.kernel.org — scheduler (EEVDF, sched-ext), admin-guide/mm (MGLRU, zswap), block (blk-mq), filesystems (vfs, ext4), userspace-api (seccomp, landlock).
  • Android Open Source Project, source.android.com — architecture, Binder, the application sandbox.
  • D. M. Ritchie, K. Thompson, “The UNIX Time-Sharing System”, Communications of the ACM, 1974.

The End

Chapter 15: Linux
Previous: Chapter 14: Operating-System Design · This is the last chapter of the course.
1 / 1