First 1 hour Scribe == Mid-term brief review == 1.Processes and Threads 1a. No, threads consumes less overhead. 1b. Yes, SJF minimizes avg response time. 1c. No.(Everyone did this correctly) 1d. Longest Job First or switch out the process before the last instruction. 1e, Yes, time quantum is long enough. 1f, Yes, longest job is at the head of the queue. 2.Synchronization and Deadlocks 2a, n is 5. When n is 6, then every one can hold a resource and request another one, then deadlock happened. For n is 5, there's always one can finish 2 resource and releases them. 2b, +--+ +--+ |P1|---------------->|R1| | |<----------------| | +--+ +--+ +--+ +--+ |P2|---------------->|R2| | |<----------------| | +--+ +--+ +--+ +--+ |P3|---------------->|R3| | |<----------------| | +--+ +--+ +--+ +--+ |P4|---------------->|R4| | |<----------------| | +--+ +--+ +--+ +--+ |P5|---------------->|R5| | |<----------------| | +--+ +--+ +--+ +--+ |P6|---------------->|R6| | |<----------------| | +--+ +--+ 2c, Sequence is: 2.1 - 2.6, 1.1 - 1.4, 1.8, 1.9, 2.7 - 2.9 3Memory Management 3a, Better performance. 3b, page table size: big leads to longer search time. Internal Fragmentation: big leads to severer internal fragmentation. I/O time: big leads to less I/O time. 3c, Yes, reduces the internal fragmentation. 3d, Only Internal fragmentation would happen. 3e, less memory and better sharing, to solve the problem: copy on write. 4 Pintos 4a, A new system call. TCB needs to be copied. The memory needs to be copied. The file needs to be copied. Return different values. 4b, The constants: Ret, Argc, Argv, and NULL. So it's totally 16B that won't change. Then the space on a page is 4096 - 16 = 4080B. Each Char with \0 asks for 2B for storage and 4B for pointers. Then 6B together. Thus, 6*n = 4080, => n = 680, this meets the alignment. Extra credit 365.2425 == Lecture == Q: What's a file? and What's the notion of a file? A: File is a named collection of related data. Logical Address space -> self-contained contiguous allocated. Abstract data type. Q: What are the attributes of a file? A: It's metadata including: File name, file size, file location(device, location)[], access metadata(create time, access time), permissions(who, what), identifier(kernel's notion of a file), type. Q: What are the most basic operations on a file? A: Create(filename), Delete(filename), <- destroy the file entirely. Read(...), Write(...), Lock(...), Truncate(offset) <- used to only clear the data/content comparing to delete. Q: What are the advanced operations? A: Rename(...), Copy(...), Append(...), Seek(...) Q: What are the different access methods for read/write? A: 1. Direct Access, e.g. read(n, ...), where n is an offset. 2. Sequential Access, e.g. read(...), where kernel keeps a pointer for next read. Kernel keeps a read pointer and write pointer for file operations. Q: Why filename is always needed for file operations? A: Say read(filename, offset, ...) The reasons that filename is always needs are: 1. Rename of the file can keep the pointer still valid. 2. Searching for a file is expensive. Q: Why open/close are not in basic file operations? A: open/close are like caching the file. What they return is called file descriptor, which is a process notion of file. e.g, read(file descripor, offset,...) Q: Is there only a file table? A: There are two file tables, one is per process file table, which has file descriptor, pointers to the file, file mode and etc. The other one is system wide file table, which keeps track of all the files in the system. Q: When 2 processes open the same file, and one calls delete, what should the OS do? A: Delete the metadata associated with the file, but keep the content valid. This is why we need the system wide file table, which helps resolve delete semantics, buffering, and reduces memory usage.