Class 17 CS 170 12 March 2019 On the board ------------ 1. Last time 2. Finish directories 3. mmap 4. Exam review --------------------------------------------------------------------------- 1. Last time --indexed files --directories --a directory *is* a file. its data is simply a table that maps name to inode 2. Finish directories --special names: "/", ".", ".." --given those names, we need only two operations to navigate the entire name space: --"cd name": (change context to directory "name") --"ls": (list all names in current directory) --example: [DRAW PICTURE FROM LAST TIME] --links: --hard link: multiple dir entries point to same inode; inode contains refcount "ln a b": creates a synonym ("b") for file ("a") --how do we avoid cycles in the graph? (answer: can't hard link to directories) --soft link: synonym for a *name* "ln -s /d/a b": --creates a new inode, not just a new directory entry --new inode has "sym link" bit set --contents of that new file: "/d/a" 3. mmap --recall some syscalls: fd = open(pathname, mode) write(fd, buf, sz) read(fd, buf, sz) --we've seen fds before, but what is it? --indexes into a table maintained by the kernel on behalf of the process --what's in the given entry in the table? --inumber! --inode, probably! --and per-open-file data (file position, etc.) --syscall: void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset); --means, roughly, "map the specified open file (fd) into a region of my virtual memory (at addr, or at a kernel-selected place if addr is 0), and return a pointer to it" --after this, loads and stores to addr[x] are equivalent to reading and writing to the file at offset+x. --how's this implemented?! (answer: through virtual memory, with the VA being addr [or whatever the kernel selects] and the PA being what? answer: the physical address storing the given page in the kernel's buffer cache). --have to deal with eviction from buffer cache, so kernel will need a data structure that maps from: Phys page --> {list of (proc,va) pairs} note that the kernel needs this data structure anyway: when a page is evicted from RAM, the kernel needs to be able to invalidate the given virtual address in the page table(s) of the process(es) that have the page mapped. --------------------------------------------------------------------------- exam review Ground rules: same as last time --75 minute exam --at 65 minutes, you have to stay seated; do not get up and distract your classmates. --you must hand your exam to us (we are not going to collect them). the purpose of this is to give everyone the same amount of time. --at 78 minutes, we will walk out of the room and won't accept any exams when we leave --thus you must hand in your exam at time x minutes, where: x <= 65 OR 75 <= x < 78 --exams are closed book. Also, put away electronics (phones, tablets, laptops, etc.). Material: everything we've covered: readings, labs, homeworks, lectures only exception, as usual, is if there was new material covered in review sessions (but there shouldn't have been) lecture topics I/O --architecture --how CPUs and devices interact --mechanics (explicit I/O instructions, mem-mapped I/O, interrupts, memory) --polling vs. interrupts --DMA vs. programmed I/O --device drivers virtual memory segmentation paging segmentation vs paging virtual memory on the x86 virtual address: [10bits 10bits 12bits] --entry in pgdir and page table: [20 bits more bits bottom 3 bits] --protection (user/kernel | read/write | present/not) what's a TLB? page faults mechanics costs uses page replacement policies (FIFO, LRU, CLOCK, OPT) thrashing [latter two topics more general than paging: applies to caching in general] disks geometry performance interface scheduling (skipped in lecture; see book) file systems --basic objects: files, directories, meta-data, links, inodes --how does naming work? what allows system to map /usr/homes/bob/index.html to a file object? --types of file layout --extents/contiguous, linked, FAT, indexed structure --classic Unix is a variant of indexed structure --analogy between inode and page directory --mmap questions from all of you ...