





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Exam is closed-book. There will be 10 questions in 90 minutes with short answers (usually 2 or 3 well chosen sentences). I expect knowledge of general concepts, important ideas and some details. Questions are drawn mostly from the primary text. I highlight important info in class but may draw a detail question from something described in the text but mentioned in passing in class I recommend using a top-down study strategy. Read the chapter, close the book and ask yourself, “What were the 3-5 most important ideas or concepts presented in this chapter?” A “brainstorming” approach is also useful. I do this in class as review sometimes. “Tell me everything you know about interrupts and exceptions.” Just list everything you know and then organize among the major topics you listed above. I often try to highlight or emphasize things that are particularly interesting or unusual or not well-known. In addition, I try to relate implementation details in Linux to corresponding general principles in OS (from the Dinosaur book). Another technique is to skim the chapter, looking at headings, subheadings, and so forth. You should probably know something about each section and subsection. As a random example, consider “IRQ distribution in multiprocessor systems” on page 136. Why is this an issue? Because interrupts are executed (usually) by a single processor. So there is a policy issue that arises. Which processor should respond? How is this resolved in Linux? You should at least understand the basic SMP interrupt architecture using APICs. There is a “front-end APIC” and a per-cpu “local APIC” that share a communication bus. At a further level of detail you might recall that Intel hardware has a way to direct interrupts to the “lowest priority” task but that Linux simply uses the “round-robin” arbitration circuitry present in the hardware to handle situations in which two or more tasks have the same priority. Memory Management memory allocation overview how malloc works why kernel allocation is critical everything but kernel code & static data comes from allocator process pages, descriptors, etc. page allocator (buddy system) on top is slab allocator (descriptor specific) on top is kmalloc (general purpose) vmalloc uses page allocator + slab physically discontiguous allocations (uses page table tricks) zones nodes buddy system
“power of 2 allocator” 10 lists size not available? look at next largest, split if necessary merge “buddies” on free when possible buddies: same size, contiguous, properly aligned consider 256k chunks in 1m chunks at 0 and 256 are buddies chunks at 256 and 512 are not data structure aggressive vs. lazy merging Process Address Space address space (AS): set of addressable memory locations in theory 0-4GB on 32 bit machine in Linux 0-3GB (kernel is mapped in high 1GB) in reality 0-3GB – high 128MB (used for “high mem”, vmalloc, etc.) AS mapping: valid (mapped) versus invalid (unmapped) attempts to touch unmapped location: SEGV mapping ultimately done via mmap() sys call AS lifecycle: fork -> exec -> mmap -> munmap -> brk -> shmat -> exit AS example events: create a process (fork, exec) grow the stack (automatic growth) grow the heap (via malloc) dynamic linking/loading terminate a process system v shared memory: shmat/shmdt file mapping: mmap() file mapping little known, popular with kernel hackers make file look like memory reads access file, writes flush through (eventually) compare to /proc/kmem – memory that looks like a file (!) “backing” file optimizes file access (avoids a copy) regular: file to kernel buffer, kernel to user buffer (2 copies) file mapped: file to user space (1 copy) executables are “file mapped” implements loading! “standard” read/write uses file mapping internally Note: page fault doesn’t change AS mapping page fault (faulting in a page) just allocates/loads page frame mapping must already be defined attempting to touch unmapped region -> exception (SEGV) Data structures memory descriptor (current->mm) shared (ref counted) by threads sharing AS important fields: mmap, mm_rb, mm_cache, pgd memory region descriptor (vm_area_struct; VMA) contiguous mapped range with uniform permissions
signals and system calls blocking (slow) system calls terminated by signal delivery returns EINTR possible to specify “auto restart” (BSD) specified when registering signal handler (per signal) unusual BSD feature – alternate signal stack APIs 3 separate APIs, old API still available old “unreliable” signals (signal()) bug: not masked (reentrant), default action reinstalled result: window of vulnerability not possible to reliably catch all signals sent new POSIX “reliable” signals (sigaction()) no window of vulnerability but signals still “can’t count” old semantics available as parameters of sigaction() new POSIX “realtime” signals (rt_sigaction()) possible to include a little extra info signal struct added to queue when generated subtle semantics: interactions between regular, realtime data structures signal sets: array of 2 ints as a bitmask (1 per signal) there is no signal 0 (used for testing delivery permissions) pending, blocked signal sets pending signal queue sigpending (convenience Boolean – any pending, non-blocked) sig struct – contains array of handlers, flags, masks utility routines on signal sets (ugly bit tricks!) generating signals send/force_sig_info() check permissions some signals cancel out others ultimately, setting bit in target process task struct actually, regular signals are queued (once) in Linux seems to be a code simplicity technique bit is still set if queue is full for realtime, setup info packet, enqueue delivering signals much more complex than generating default actions pretty easy executing handlers must be done in user space place a special stack frame on user-mode stack must execute all pending, non-blocked so must return to kernel after finishing handler special system call: sigreturn() returning to kernel executes code on user-mode stack! so called “trampoline code”: kernel to user to kernel to user … be familiar with sample code on page 333 be able to explain flow of control in Figure 10- be familiar with signal stackframe layout in Figure 10- kill() system call
possible to send to process group, all processes, specific process sigsuspend() – mask, wait for delivery atomically sigpending() followed by sleep() not the same! understand why … Process Scheduling basic ideas scheduling (policy), context-switch (mechanism) well-studied, lots of (complex) theory we want a simple, general purpose scheduler that does well most of the time time-slicing, quanta – each process runs for a given interval on quantum expiry process is runnable (not-blocked) but not selected gives others a chance to run (fairness) preemption (technically) – a higher priority process becoming runnable Linux is preemptive for user processes kernel (2.4) is not (2.6 has limited kernel preemption) priority – anti-fairness mechanism UNIX – “niceness” (nice command) regular users – only decrease priority (increasing niceness) root – either increase or decrease process classification interactive, batch, real-time cpu-bound, io-bound scheduling heuristics boost io-bound (like interactive) to make progress, increase responsiveness decrease cpu-bound over time syscalls nice, get/setpriority sched_get/setscheduler (policy) sched_yield POSIX scheduling classes (policies) SCHED_FIFO (run to completion – no time-slicing!) SCHED_RR (time-slicing but high priority) SCHED_OTHER (normal scheduler) real-time processes SCHED-FIFO and SCHED_RR are so called “real-time” processes always beat regular processes real-time processes have priorities (to distinguish among them) under UNIX only root can make a process real-time (sched_setscheduler()) a bit dangerous – can starve other processes, even kernel daemons support for “soft” realtime (best effort) “hard” realtime (guaranteed deadlines) is very difficult quantum length too short – wastes cpu on overhead too long – reduces responsiveness linux currently starts at about 6 ms quantum length related to priority (higher priority, longer quantum) scheduling “epoch” don’t confuse with timekeeping epoch (jan 1, 1970) epoch occurs when all runnable processes have 0 quantum quantum is refreshed for ALL processes (including blocked processes!)
vfs layer functions sometimes don’t need to call a fs-specific function sometimes have default implementations sometimes just dispatch to fs-specific version inode – metadata + data pointers (so called “block map”) inode # is unique (per-device) name of a file open file object – no disk rep, file pointer, fops, points to dentry dentry – directory entry abstraction, one line of a directory listing basically name + inode superblock – fs descriptor contains list of dirty inodes, times, blocksize, fs options, etc. unix file links hard – just another name for same file basically a dentry can’t cross filesystem or link to directory (to avoid cycles) soft, symbolic – a small file with another pathname can cross filesystems, cycles are possible dentry cache inode cache Managing I/O Devices i/o architecture cpu bus(es) devices pci, agp, scsi, isa, etc. i/o bus: control, data, address lines port: device owned addresses on i/o bus 64K possible on i special instructions for reading/writing: in, ins, out, outs memory-mapped i/o physical addresses “linked” to i/o bus port addresses no special instructions required for port access mapping may be very complex a few bits from this byte, a few from that these bits mean something only if that bit is on, etc. very non-standard and device dependent common usage: “device registers” command, status, data linux macros for port instructions: inb(), inw(), inl() … registration system for port addresses tree structure for ranges of addresses /proc/ioports i/o interface logic circuit, “port manager” translates/updates ports into controller commands device connection to PIC two styles: custom interfaces (internal or external) keyboard, graphics, disk, network GPIO parallel, serial, usb, pcmcia, scsi
device controllers electro/mechanical component of device (actuator) e.g. disk controller (geometry, spinning, head control, bad block forwarding) on board i/o memory: “i/o shared memory” think of it as a really big device data register some complicated details for accessing i/o shared memory ioremap() dma dma controller is just a device to cpu cpu communicates with cpu: get data from that device, put it in that memory interrupt when done cpu must give dmac “bus” address bus address space different from physical, linear on some architectures same as physical on ia dynamic irq allocation (per dma transfer) device files UNIX abstracts (most) devices as files (/dev) mknod() to create creates on disk inode for each device file ls –l reveals “c” (character) or “b” (block) block – min transfer is big (usually 512 bytes or larger) char – 1 or more characters per transfer network devices are different (initiate i/o independently on receipt of packet) ifconfig namespace (e.g. eth0) no device file abstraction operations associated with device “files” are device driver functions UNIX historically uses major/minor numbers for devices major #: index into array of device descriptors (one for char, one for block) minor #: not used by kernel one driver can manage several similar device instances, discriminates device #s are registered (see devices.txt in Documentation) 256 possible majors, 128 possible minors device registration – add descriptor (with functions) to device array often aliases for device files drivers can behave differently depending on filename used for open devfs – improved device filesystem in 2.4 (replaced in 2.6) eliminates major/minor no on-disk inodes tree-structured dev directory device files added/removed (plug&play) device drivers some vfs functions, some data structures (buffers, etc.), interrupt handler various levels of kernel support ioctl() device access “wildcard” basically a command interpreter (device dependent, poorly documented) used for odd functions not represented in standard VFS interface