xv6 Teaching Operating System Study Guide and Chapter Summaries – Cox, Kaashoek & Morris (RISC-V 2026) BSCS

BSCS students who study operating systems can use this guide to study “xv6: a simple, Unix-like teaching operating system”. It is the textbook that goes with xv6, a small teaching kernel written by Russ Cox, Frans Kaashoek and Robert Morris and used in MIT’s operating systems courses. The kernel is modelled on Unix Version 6 and runs on a RISC-V machine, which you can simulate on your own laptop with QEMU.

Instead of describing an operating system in general terms, the book walks through one real kernel, file by file. Its 13 chapters cover system calls, page tables, traps, interrupts, locking, scheduling, sleep and wakeup, the file system and crash recovery. It is a code-reading text, so keep the xv6 source open beside it and be comfortable with C. Used that way, it turns the operating systems topics from your lectures into code you can run, change and debug.

Book Overview

CourseOperating Systems
Degree ProgramsBSCS
LevelUniversity / Undergraduate (code-reading text, needs C)
Editionxv6 RISC-V edition; the PDF title page is dated 23 September 2026 and no revision number is printed
AuthorsRuss Cox, Frans Kaashoek, Robert Morris
PublisherMIT PDOS group (MIT CSAIL); copyright held by the Massachusetts Institute of Technology
LanguageEnglish
Total Chapters13 chapters, plus a foreword and acknowledgments
Exercises40 exercise items across Chapters 1 to 12; the final Summary chapter has none
Companion Codexv6-riscv kernel source (about 6,600 lines of C and assembly in kernel/), run under QEMU
LicenseMIT-style permission notice for the book sources, copyright 2006–2024 Cox, Kaashoek, Morris, MIT (stated in the book’s source repository)
FormatPDF and HTML, free from the official book site

Chapter List

Chapter 1: Operating system interfaces

Difficulty: Easy · Key topics: kernel, process, system call, fork, exec, file descriptor, pipe, inode, link

The chapter introduces xv6 as a kernel that runs processes and offers them a narrow Unix system call interface, then explains that interface through the shell. It shows how fork, exit, wait and exec create and replace processes, why keeping fork and exec separate lets the shell redirect input and output, and how file descriptors and dup share file offsets. It then covers pipes as kernel buffers that connect processes, and the file system with directories, inodes, links, mkdir, mknod and unlink. It closes by noting that xv6 is not POSIX and runs everything as root.

Key Points:

  • A process has user memory (instructions, data and stack) plus per-process state private to the kernel, identified by a PID.
  • fork returns the child’s PID in the parent and 0 in the child, and the two then run with separate memory and registers.
  • exec replaces the calling process’s memory with an image loaded from an ELF file and does not return if it succeeds.
  • A new file descriptor is always the lowest unused number, and fork copies the descriptor table, which is how shell redirection works.
  • Descriptors made by fork or dup share one file offset, while separate open calls do not.
  • A pipe is a small kernel buffer with a read end and a write end, and read returns 0 only after every write end is closed.
  • A file’s inode can have several names, and unlink frees it only when the link count is zero and no descriptor refers to it.

Practice Tip: Write a short user program for xv6 that forks, closes descriptor 1 in the child, opens a file, and then execs echo. Run it and check that the parent’s own output still goes to the console.

Common Mistake: Leaving the unused ends of a pipe open, so the reader never sees end-of-file and the pipeline hangs.

Important Questions:

  • Why are fork and exec separate system calls? Between the two calls the shell can change the child’s file descriptors, which gives I/O redirection without disturbing the shell’s own setup.
  • Why must cd be built into the shell? The directory change has to happen in the shell process itself, because a child process running cd would only change its own working directory.

Chapter 2: Operating system organization

Difficulty: Medium · Key topics: isolation, multiplexing, supervisor mode, monolithic kernel, microkernel, struct proc, trampoline, boot sequence

The chapter says an operating system must provide multiplexing, isolation and interaction, and argues that hardware is best hidden behind system calls instead of a library. It describes the three RISC-V privilege levels, the ecall instruction and the difference between monolithic kernels and microkernels. It then defines the xv6 process as one address space plus one thread, with a user stack and a kernel stack, and follows the boot path from the first instruction to the /init program and the shell. A section on the security model explains why the kernel panics on inconsistencies.

Key Points:

  • Operating systems must provide multiplexing, isolation and interaction between programs.
  • RISC-V has machine, supervisor and user modes; xv6 runs briefly in machine mode and then drops to supervisor mode with mret.
  • ecall enters the kernel at a kernel-chosen address and sret returns to user mode.
  • xv6 is a monolithic kernel, while a microkernel moves most services into user-level server processes.
  • A process is one address space plus one thread, and each process has a user stack and a kernel stack (p->kstack).
  • User addresses stop at MAXVA (0x3fffffffff), and the trampoline and trapframe pages sit at the very top.
  • The kernel assumes user code may be malicious but its own code is correct, and calls panic() when it finds an inconsistency.

Memory Tip: Learn the boot path as one chain: _entry, start, main, userinit, forkret, /init, shell. Draw it once from memory, then check it against the source.

Common Mistake: Thinking monolithic means large and tangled. It only means the whole kernel runs as one program in supervisor mode, and xv6 is monolithic even though it is tiny.

Important Questions:

  • Why does each process have a separate kernel stack? The kernel can then keep running even if the process has wrecked its user stack, and user code cannot touch kernel data held on that stack.
  • Why must the kernel choose the entry point for system calls? If an application could pick the entry point, it could jump past the kernel’s argument checks.

Chapter 3: Page tables

Difficulty: Hard · Key topics: Sv39, PTE flags, satp, TLB, kernel address space, walk, mappages, kalloc, exec

The chapter explains how RISC-V Sv39 paging turns a virtual address into a physical one through a three-level tree of 512-entry page-table pages, and what the PTE flag bits control. It then lays out the xv6 kernel address space, with RAM direct-mapped from 0x80000000, device registers below it, a doubly mapped trampoline page and guard pages under kernel stacks. The code sections follow walk, mappages and the kalloc free list, the layout of a process address space, and kexec, which loads an ELF file and checks its headers carefully.

Key Points:

  • Sv39 uses 39 of the 64 address bits: three 9-bit indexes select PTEs and 12 bits are the offset inside a 4096-byte page.
  • A PTE holds a 44-bit physical page number and the flags PTE_V, PTE_R, PTE_W, PTE_X and PTE_U.
  • A missing or invalid PTE raises a page-fault exception; the CPU caches PTEs in the TLB, and sfence.vma flushes it.
  • The kernel direct-maps RAM from 0x80000000 and maps device registers below it, so a physical address can be used as a kernel virtual address.
  • Invalid guard pages below kernel stacks and below the user stack turn an overflow into a fault instead of silent corruption.
  • walk finds a PTE (allocating page-table pages if asked), mappages installs mappings, and kalloc hands out whole pages from a free list.
  • kexec builds the new image first and frees the old one last, so a failed exec can still return -1.

Practice Tip: Pick a virtual address, write down its three 9-bit indexes and its 12-bit offset by hand, then follow the loop in walk in kernel/vm.c and confirm it visits the same entries.

Common Mistake: Forgetting that the TLB caches old translations. A changed page table without sfence.vma can leave a stale mapping in use.

Important Questions:

  • Why is a three-level page table more economical than one flat table? Unused ranges simply have no lower-level pages, so a process that uses a few pages near address zero needs only a few page-table pages instead of an array of 2^27 entries.
  • Why does kexec free the old address space only at the end? Once the old image is gone the system call can no longer return an error to the process, so every possible failure must happen before that point.

Chapter 4: Traps and system calls

Difficulty: Hard · Key topics: trap, stvec, sepc, scause, trampoline, trapframe, uservec, usertrap, syscall, copyin, kernelvec

The chapter defines a trap as a system call, an exception or a device interrupt, and lists the RISC-V control registers and the exact steps the hardware takes. It follows a trap from user space through the trampoline code in uservec, the C function usertrap, and back out through userret and sret. It then traces a write system call, from the ecall in the user library to the dispatch table in syscall, and shows how the kernel safely fetches arguments and copies data across the user/kernel boundary. A last section covers traps taken inside the kernel.

Key Points:

  • A trap is a system call, an exception or a device interrupt, and xv6 handles every trap in the kernel.
  • On a trap the CPU only saves the pc in sepc, sets the mode and jumps to stvec; software must switch page table, stack and registers.
  • The trampoline page is mapped at the same address in user and kernel page tables so uservec keeps running after satp changes.
  • sscratch frees one register so uservec can start saving the 32 user registers into the trapframe.
  • A system call number goes in a7, arguments go in registers from a0, and the result comes back in a0.
  • The kernel never dereferences user pointers directly; copyin, copyout and copyinstr translate through the user page table.
  • Traps from kernel code go to kernelvec and kerneltrap, which expect only device interrupts and panic on anything else.

Practice Tip: Run xv6 under QEMU with gdb attached, set a breakpoint on syscall, and use a backtrace to see how one write call got there from the shell.

Common Mistake: Assuming the CPU switches to the kernel page table and kernel stack on a trap. It does neither, and that is exactly why the trampoline and trapframe pages exist.

Important Questions:

  • Why does the system call path add four to the saved program counter? After ecall the saved pc still points at the ecall instruction, and user code must resume at the next instruction.
  • What keeps a device interrupt from hitting uservec while the kernel is already running? The CPU disables interrupts when the trap starts, and usertrap turns them on again only after it has pointed stvec at kernelvec.

Chapter 5: Page faults

Difficulty: Medium · Key topics: page fault, stval, lazy allocation, sbrk, vmfault, copy-on-write, demand paging, mmap

The chapter lists the three kinds of RISC-V page fault and the registers that report them, then shows how the kernel can use faults to change what an address means. xv6 uses faults for one purpose, lazy allocation: sbrk with the lazy flag only raises the process size, and vmfault allocates, zeroes and maps a page when the process first touches it. The chapter also covers eager allocation and how shrinking skips pages never touched. Real-world sections explain copy-on-write fork, demand paging, paging to disk and memory-mapped files.

Key Points:

  • There are load, store and instruction page faults; scause gives the kind and stval holds the address that could not be translated.
  • With lazy sbrk the kernel only raises the process size, and vmfault allocates the physical page on first access.
  • Eager allocation can report an error, but a lazy fault with no free memory can only kill the process.
  • uvmunmap skips PTEs without PTE_V, because lazily allocated pages may never have been touched.
  • The process page table is the only record of which physical pages the process owns.
  • Copy-on-write fork shares pages read-only and copies one only when a store faults, which needs reference counts on physical pages.
  • Demand paging and paging to disk mark PTEs invalid and fetch pages on a fault, and work best when programs have good locality of reference.

Practice Tip: Read vmfault and write one line for each check it makes before it calls kalloc. Then ask what could go wrong if the address-range check were missing.

Common Mistake: Treating every page fault as a bug. Here a fault is the normal way lazy memory arrives, and the faulting instruction is simply run again.

Important Questions:

  • Why is lazy allocation useful? A program can ask for a worst-case amount of memory without paying for pages it never uses; a one-gigabyte request would otherwise force the kernel to zero 262,144 pages up front.
  • How does copy-on-write fork work? Parent and child map the same pages read-only, and a write faults; the kernel copies that page, maps the copy writable and resumes (xv6 itself does not implement this).

Chapter 6: Interrupts and device drivers

Difficulty: Medium · Key topics: driver, top half, bottom half, UART, PLIC, devintr, console, timer interrupt, DMA, polling

The chapter defines a driver and its two halves: a bottom half called from system calls such as read and write, and a top half that runs when the interrupt arrives. The console driver is the worked example. Characters arrive from the memory-mapped UART, devintr asks the PLIC who interrupted, consoleintr builds a line in a buffer, and consoleread wakes up with the full line. Output uses sleep so the CPU is not wasted. The chapter then covers concurrency in drivers and timer interrupts, and ends by comparing programmed I/O, DMA and polling.

Key Points:

  • A driver has a bottom half that runs in a process’s kernel thread and a top half that runs at interrupt time.
  • Devices appear as memory-mapped registers, and the xv6 UART registers start at physical address 0x10000000.
  • devintr reads scause and asks the PLIC which device interrupted, then calls uartintr for the UART.
  • Buffering in cons.buf decouples typing from reading, so input is not lost when no process is waiting (I/O concurrency).
  • uartwrite sleeps instead of busy-waiting, and the interrupt handler wakes it when the UART can accept another byte.
  • An interrupt handler must not assume anything about the process it interrupted, so it cannot safely call copyout for that process.
  • The timer interrupt advances ticks on one CPU only and makes the running process yield.

Practice Tip: Add a temporary print to consoleintr, type a short line into xv6, and watch it fire once per character. Then find where consoleread finally wakes up.

Common Mistake: Writing interrupt-handler code that waits or touches the current process’s user memory. Handlers should do little and hand the rest to the bottom half.

Important Questions:

  • How does programmed I/O differ from DMA? With programmed I/O the CPU moves each byte through device registers, while with DMA the device reads and writes RAM itself and the driver only starts it with one register write.
  • Why does xv6 need timer interrupts? They keep the kernel’s idea of time and force a running process to yield, so a compute-bound process cannot hold a CPU forever.

Chapter 7: Locking

Difficulty: Hard · Key topics: race, critical section, spinlock, amoswap, deadlock, lock ordering, push_off, memory barrier, sleep-lock

The chapter starts from the sources of concurrency in a kernel: multiple CPUs, thread switching and interrupt handlers. A list push that loses an update shows what a race is, and a lock is introduced as the tool that protects invariants. It builds the spinlock on the atomic amoswap instruction, discusses coarse and fine-grained locking, deadlock and lock ordering, and why spinlocks must disable interrupts. Sections on memory ordering, atomic operations and sleep-locks follow, and the real-world section covers Pthreads and lock-free designs.

Key Points:

  • A race is concurrent access to a location where at least one access is a write, and a lock makes critical sections run one at a time to protect invariants.
  • acquire loops on an atomic swap (amoswap on RISC-V), and release uses an atomic store of zero.
  • Every code path that holds several locks must take them in the same global order, or two CPUs can deadlock.
  • xv6 spinlocks are not re-entrant, and holding catches a CPU that tries to take a lock it already holds.
  • acquire calls push_off before setting the lock, so an interrupt handler cannot spin on a lock held by its own CPU.
  • The acquire and release atomics contain memory barriers, so compilers and CPUs cannot move accesses across the critical section.
  • A sleep-lock yields the CPU while waiting and suits long operations, but it cannot be used in interrupt handlers or inside spinlock sections.

Practice Tip: Write the chapter’s list push in a small C program with POSIX threads. Run it with several threads, first without a mutex and then with one, and count how many elements go missing.

Common Mistake: Believing code is race-free because tests pass. The chapter stresses that races are hard to trigger, so correctness must come from the locking rules.

Important Questions:

  • Why does xv6 turn interrupts off while a spinlock is held? If an interrupt handler on the same CPU tried to take a lock that the interrupted code holds, it would spin forever and the CPU would deadlock.
  • When should you use a sleep-lock instead of a spinlock? Use a sleep-lock for long operations such as disk I/O, because waiters give up the CPU, while spinlocks suit short critical sections.

Chapter 8: Scheduling

Difficulty: Hard · Key topics: context switch, swtch, struct context, scheduler thread, sched, yield, p->lock, mycpu, myproc, round robin

The chapter explains how xv6 multiplexes many processes onto few CPUs through voluntary switches in blocking system calls and involuntary switches forced by the timer. A kernel thread never switches straight to another process; it switches to its CPU’s scheduler thread, which looks for a RUNNABLE process. The assembly routine swtch saves and restores the callee-saved registers held in struct context. The chapter explains why p->lock is held across the switch, how new processes start in forkret, and how mycpu and myproc find per-CPU state.

Key Points:

  • Voluntary switches happen when a process blocks in a system call, and involuntary ones are forced by timer interrupts.
  • swtch saves and restores only the callee-saved registers (ra, sp and s0 to s11) held in a struct context.
  • A process switches to its CPU’s scheduler thread, never directly to another process, and the scheduler picks the next RUNNABLE one.
  • A process gives up the CPU by taking p->lock, updating p->state and calling sched; the lock is released on the other side of the switch.
  • A new process begins by “returning” from swtch into forkret, which allocproc arranged.
  • mycpu indexes an array using the tp register, which holds the hart id, and interrupts must stay off while its result is used.
  • The xv6 policy is plain round robin, while real kernels add priorities, fairness and throughput goals.

Memory Tip: Think of swtch as a return into someone else’s past. It loads ra from the other thread’s saved context, so it resumes right after that thread’s own last call to swtch.

Common Mistake: Assuming the code that takes a lock must also release it. Here p->lock is taken before swtch and released by a different thread after it.

Important Questions:

  • Why does xv6 switch through a scheduler thread? A direct switch could leave no stack to run on, for example when the old process has just exited or no other process is ready to run.
  • Why does swtch not save the caller-saved registers? The RISC-V calling convention makes the compiler save any caller-saved register it needs before the call to swtch.

Chapter 9: Sleep and Wakeup

Difficulty: Hard · Key topics: sleep, wakeup, wait channel, lost wake-up, condition lock, pipe, zombie, wait, exit, kill, p->lock

The chapter introduces sleep and wakeup as the way kernel threads wait for conditions, using a wait channel that is just an agreed address. It explains the lost wake-up problem and how sleep_prepare, the condition lock and the loop around sleep avoid it. Pipes are the worked example, with a circular buffer and separate channels for readers and writers. The chapter then covers wait, exit and kill, including zombies and reparenting to init, lists everything p->lock protects, and compares xv6 with condition variables and wait queues.

Key Points:

  • A wait channel (chan) is an opaque value, normally the address of some object that both the sleeper and the waker know.
  • A lost wake-up happens when the condition becomes true between the check and the sleep; sleep_prepare records the intent so wakeup can cancel that sleep.
  • wakeup wakes every process on the channel, so sleepers always re-check their condition inside a loop.
  • Pipe counters nread and nwrite never wrap: full means nwrite == nread + PIPESIZE and empty means nwrite == nread.
  • An exiting process stays a ZOMBIE until its parent’s wait collects it, and orphans are handed to init.
  • kill only sets p->killed, and the victim exits itself when it next enters or leaves the kernel.
  • wait_lock must be taken before any process lock, which fixes the lock order for wait and exit.

Memory Tip: Remember the sleeping pattern as lock, check, prepare, unlock, sleep, and then on waking lock and check again. The check always sits in a while loop, never an if.

Common Mistake: Using if instead of while around a sleep. After a spurious wake-up the condition may be false again and the code would carry on with bad data.

Important Questions:

  • What is a lost wake-up and how does xv6 prevent it? It is a wakeup that finds nobody asleep because the sleeper had checked the condition but not yet slept; xv6 holds a condition lock and uses sleep_prepare so the sleep returns immediately if a wakeup arrived first.
  • Why can kill not destroy the victim process directly? The victim may be running on another CPU in the middle of sensitive kernel updates, so kill sets a flag and the victim exits at a safe point.

Chapter 10: File system

Difficulty: Hard · Key topics: buffer cache, inode, i-number, block allocator, directory, path name, file descriptor layer, link, ialloc, bmap

The chapter lists the file system’s challenges and divides the implementation into seven layers, from the virtio disk up to file descriptors. It shows the disk layout with boot block, superblock, log, inodes, bitmap and data blocks. Walking up the layers, it covers the LRU buffer cache with sleep-locks, the bitmap block allocator, on-disk and in-memory inodes with iget, ilock and iput, file content through direct and indirect blocks, directories, path lookup in namex, and the open-file table. It ends with sys_link and create, and how xv6 cleans up orphaned inodes after a crash.

Key Points:

  • The seven layers are disk, buffer cache, logging, inode, directory, pathname and file descriptor.
  • The disk holds an unused block 0, the superblock, the log, the inodes, the free bitmap and then data blocks, and an xv6 block is two 512-byte sectors.
  • The buffer cache keeps at most one buffer per disk block, locks each with a sleep-lock, and recycles the least recently used buffer.
  • An inode stores type, nlink, size and block addresses, using direct blocks first and one indirect block after them, hidden behind bmap.
  • iget returns an unlocked reference-counted pointer and ilock loads and locks it, a split that avoids deadlock in lookups such as “.”.
  • A directory is an inode whose content is struct dirent entries, each with an inode number and a name of at most 14 characters.
  • iput frees an inode on its last reference when no name remains, so even read-only calls need transactions, and ireclaim frees orphans at boot.

Practice Tip: Follow open with O_CREATE from sys_open down through create, ialloc, dirlink and writei, writing down which layer each function belongs to.

Common Mistake: Treating a file name and a file as the same thing. A name is only a directory entry pointing at an inode, so one file can have many names and still work after one is unlinked.

Important Questions:

  • Why does a directory entry store an inode number and not the inode itself? One inode can be named in several directories through links, and an open descriptor must keep working after its name is removed.
  • Why are iget and ilock separate calls? iget lets code keep long-term references, such as open files and working directories, without holding a lock, and it avoids deadlock when a lookup meets the directory entry “.”.

Chapter 11: Logging

Difficulty: Medium · Key topics: crash recovery, log, commit, transaction, group commit, begin_op, end_op, log_write, absorption, recovery

The chapter opens with a truncation example to show how a crash between two disk writes can leave the file system inconsistent. xv6’s answer is a simple log: a system call records its block writes in the log, writes a commit record, copies the blocks to their home locations, and then clears the log. Recovery replays a committed log and ignores an incomplete one. The chapter covers the log layout, group commit, the fixed log size, and the code in begin_op, log_write and end_op, and compares logging with the older fsck approach.

Key Points:

  • Logging makes a system call’s disk writes atomic with respect to crashes: after recovery either all of them appear or none.
  • The commit point is the write of the log header block with a non-zero count.
  • Recovery replays a committed log, ignores an uncommitted one, and then clears the log.
  • Group commit combines several system calls into one transaction, so a returned write may not be on disk yet and sync waits for it.
  • log_write stands in for bwrite, pins the buffer in the cache, and absorbs repeated writes to one block into a single log slot.
  • begin_op reserves MAXOPBLOCKS of log space, and large writes are split into several smaller transactions.
  • A commit runs write_log, write_head, install_trans and then writes a zero count to the header.

Memory Tip: Remember the commit as four steps in a fixed order: copy blocks into the log, write the header (the point of no return), install the blocks, clear the header.

Common Mistake: Believing a successful write means the data is already safe on disk. With group commit it is only durable after the transaction commits, which sync waits for.

Important Questions:

  • What happens if the machine crashes before versus after the log header is written? Before it, the count is zero and recovery ignores the log as if the operation never started; after it, recovery replays every logged block.
  • Why does a fixed-size log limit what a system call may do? No call may write more distinct blocks than fit in the log and begin_op waits until enough space is free, so large writes are broken into smaller pieces.

Chapter 12: Concurrency revisited

Difficulty: Medium · Key topics: locking patterns, reference counts, lock-like patterns, data races, memory ordering, parallelism, contention

The chapter gathers the awkward cases that earlier chapters only hinted at. It shows the common pattern of one lock for the set of cached items plus one lock per item, and locks acquired in one function or CPU and released in another. It explains why freeing an object with an embedded lock needs reference counts, and why even a single shared flag like p->killed needs a lock. Further sections cover lock-like uses of state flags and reference counts, the few places with no locks, and which operations can run in parallel.

Key Points:

  • Cached items need one lock for the set of identities (such as bcache.lock) and one lock per item.
  • A lock guards a sequence that must appear atomic, and that sequence may start and end in different functions, threads or CPUs.
  • An object that contains its own lock can be freed safely only when a reference count shows no other user is waiting.
  • A data race on even one variable such as p->killed is undefined behavior in C, and the compiler may cache the value in a register.
  • Reference counts and flags such as p->state and the counts in file, inode and buf act like locks that stop an object being freed early.
  • One physical page can be guarded by kmem.lock, then a pipe’s lock, and finally by no lock at all once it is user memory.
  • Locks buy correctness at the cost of parallelism, so measure real workloads before redesigning.

Memory Tip: For every shared object ask two questions: what protects it right now, and does that protection change during its lifetime?

Common Mistake: Assuming a plain read or write of a single shared flag needs no lock. Without one, the C language gives no guarantee about what the other thread sees.

Important Questions:

  • Why does the block cache need two kinds of lock? A block that is not cached has no buffer to lock, so one lock guards the set of cached blocks and each buffer has its own lock for its contents.
  • Where does xv6 share data without a dedicated lock, and why is that still correct? In fork the parent writes the child’s memory and the child reads it later, and the barriers in acquire and release make the writes visible when the child starts.

Chapter 13: Summary

Difficulty: Easy · Key topics: summary, essential ideas, design choices, Unix interface

This closing chapter is only a few lines long. It says the text introduced the main ideas of operating systems by studying one system, xv6, line by line. It separates code lines that carry the essence of an idea, such as context switching, the user/kernel boundary and locks, from lines that only illustrate one implementation, such as the scheduling algorithm, the on-disk data structures and the logging scheme. It adds that the ideas were shown through the Unix interface but carry over to other designs. The references and index follow it.

Key Points:

  • Some xv6 code lines embody the essence of an idea, and every one of them matters.
  • Context switching, the user/kernel boundary and locks are the book’s examples of essential ideas.
  • Other code only illustrates one way of doing things, and a better scheduler, file layout or logging scheme could replace it.
  • The ideas are taught through the Unix interface but apply to the design of other operating systems.

Common Mistake: Reading xv6’s simple choices, such as round-robin scheduling or its basic log, as the best possible designs instead of one clear illustration.

Important Questions:

  • What kind of code lines does the summary say are essential? The ones that embody a main idea, for example context switching, the user/kernel boundary and locks.
  • Which parts of xv6 could be designed differently without changing the idea? The scheduling algorithm, the on-disk data structures for files and the logging scheme are named as replaceable examples.

How to Study This Book

The book has 13 numbered chapters and declares no parts, so read it in order. It is a code-reading text: each chapter tells you which files to open first (for example kernel/proc.c or kernel/vm.c), and the text only makes sense after you have looked at that code. Clone the xv6 RISC-V source, build it, and run it under QEMU, which is the machine the book targets. You need working C, and some RISC-V assembly will be introduced as you go, but keep the RISC-V privileged architecture manual nearby for the exact register details.

Start with Chapters 1 and 2. Chapter 1 needs almost no kernel knowledge, so read it with a shell open and try the fork, exec, pipe and redirection examples yourself. Chapter 2 gives the map for the rest of the book: privilege modes, the process, and the boot path. Make sure you can explain what happens from the first instruction to the shell prompt before moving on.

Chapters 3, 4 and 5 form the memory and trap core and depend on each other. Chapter 4 relies on the trampoline and trapframe pages introduced with page tables in Chapter 3, and Chapter 5 is a short follow-on that uses a page fault for lazy allocation. Expect to spend the most time on Chapters 3 and 4, and redo the Sv39 address split by hand until it feels natural.

Chapter 6 mentions locks and sleep before explaining them, so skim those parts the first time and come back after Chapter 9. Chapter 7 on locking is the turning point of the book. Read it carefully before Chapters 8, 9 and 10, because every later chapter says which lock protects what, and the lock-ordering rules in Chapter 7 are what make those descriptions fit together.

Read Chapters 8 and 9 as a pair. Scheduling explains why p->lock is held across swtch, and sleep and wakeup then build blocking waits on top of it. In Chapter 9, save the Process Locking section for last, after the code for wait, exit and kill. This edition uses the sleep_prepare, sleep and wakeup interface and kernel names such as kfork, kexit and kexec, while older xv6 copies and older lab handouts use different names, so always match the book to the code version you are reading.

Read Chapter 10 up to the inode layer, then Chapter 11 on logging, and then come back to the system-call section of Chapter 10, because those calls only make sense once you know about transactions. Chapter 12 is mainly revision: it revisits examples from the earlier chapters, so read it after Chapter 11 and use it to test whether you understand each lock. Chapter 13 takes a few minutes. The book has 40 exercise items, and many ask you to change xv6 itself, such as adding a system call, copy-on-write fork or symbolic links, which is the best way to find out what you have not understood.

It is also worth knowing what the book leaves out. xv6 runs only on the QEMU virt machine, has no users or permissions (everything runs as root), no networking, no threads inside a process, and one round-robin scheduler, and the book itself says xv6 is not POSIX compliant. Pair it with a concepts book for scheduling policies and exam-style theory.


Used In These Programs

This book is used for the Operating Systems course in: BS Computer Science. Browse all Operating Systems books or all Computer Science books.

Who Should Read This

This book is for BSCS students whose operating systems course includes a kernel project, lab work or a serious look at real kernel code. It was written for MIT’s operating systems classes, so it assumes you can read C and are ready to read a few thousand lines of kernel source with the text beside you. It also suits self-learners who want to see how fork, paging, locking and a crash-safe file system are built. It is not a gentle first overview of operating system concepts and it does not teach exam-style theory such as scheduling policies in depth. For that, start with Operating Systems: Three Easy Pieces, which explains policies and concepts in plain language, or Think OS, which approaches the topic from a C programmer’s side, and then come back to xv6 to see one kernel put all of it together.


Applicable Universities

This book is useful for students at Pakistani universities offering BS Computer Science with an operating systems course, including Punjab University, Virtual University, COMSATS, FAST, UET, NUST, and other HEC-recognized institutions.

Official Copy of xv6 Book

MIT publishes the complete xv6 book as a free PDF, and an HTML version is on the same site. Click below to open the official PDF, then get the xv6 RISC-V source from the authors’ GitHub page so you can read the two side by side.

→ Visit Official Page

FAQs

Is the xv6 book free?

Yes. MIT offers the PDF and an HTML version at no cost. The licence is stated in the book’s source repository, not inside the PDF: it is an MIT-style permission notice, copyright 2006–2024 Russ Cox, Frans Kaashoek and Robert Morris, which allows using, copying, modifying and distributing the book as long as the notice is kept. The xv6 source code carries the same kind of notice. This page links to the official file and does not host it.

Which edition is this?

It is the current RISC-V edition. The PDF title page is dated 23 September 2026, and no revision number is printed. The foreword still calls the text a draft for a class on operating systems. Kernel names in this edition include kfork, kexit and kexec, so older copies of xv6 and older lab handouts may use different function names.

How many chapters and exercises does it have?

There are 13 numbered chapters plus a foreword. Chapters 1 to 12 end with exercises, 40 items in all, and the file system chapter has the most at 11. The last chapter is a one-page summary with no exercises. Many exercises ask you to change xv6 itself rather than answer a written question.

Is it good for complete beginners?

No. It expects you to read C, to know what a process and a page table are in outline, and to be ready for some RISC-V assembly. If you are new to operating systems, read a concepts book such as Operating Systems: Three Easy Pieces first and then use xv6 to see how a real kernel implements those ideas.

Do I need the xv6 source code and a RISC-V computer?

You need the source code, because the book is meant to be read beside it and points you to the files and functions to read. You do not need RISC-V hardware, because xv6 is written for the machine that QEMU simulates with its virt option, and you can run it on an ordinary laptop.

Does it cover virtual memory, scheduling, locking and file systems?

Yes. It covers Sv39 page tables, traps and system calls, lazy allocation, device interrupts, spinlocks and sleep-locks, context switching, sleep and wakeup, a layered file system and a write-ahead log. It does not cover networking, user accounts and permissions, threads inside a process or scheduling beyond round robin, and the book says that xv6 is not POSIX compliant.

Related Books

xv6 gives you a whole working Unix-like kernel, small enough to read from start to finish, together with a book that explains why each part is built the way it is. Browse more Computer Science books for the rest of your semester.

xv6: a simple, Unix-like teaching operating system (RISC-V edition, PDF dated 23 September 2026) by Russ Cox, Frans Kaashoek and Robert Morris, Massachusetts Institute of Technology. The book sources are copyright 2006–2024 Russ Cox, Frans Kaashoek and Robert Morris, Massachusetts Institute of Technology, and are offered under a permission notice in the MIT licence style (see the LICENSE file at github.com/mit-pdos/xv6-riscv-book). Official sources: https://mit-pdos.github.io/xv6-riscv-book/ and https://pdos.csail.mit.edu/6.828/xv6. This page links to the official site and does not host or copy the book.

Leave a Comment