q1_fall05_sol

q1_fall05_sol - I 6.828 FALL 2005, Quiz 1 SOLUTIONS Page 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: I 6.828 FALL 2005, Quiz 1 SOLUTIONS Page 1 of 10 Processes, stacks, and concurrency 1. [5 points]: Explain briey one benefit of having one kernel stack per process (as in v6) rather than a single kernel stack (as in JOS). Having a per-process stack allows the kernel to release the processor to another process when a system call needs to wait, for example while reading from the disk. 2. [5 points]: In v6s getblk , lines 4953 through line 4958 are protected by spl6() . Describe something that could go wrong if this protection was eliminated. These lines handle the case where the requested block is not in the buffer cache, and there are no free buffers in bfreelist in which getblk() can store the block read from disk. getblk() sets BWANTED to indicate it is waiting for a free buffer, and sleeps on &bfreelist . If the spl6() were not there, a disk interrupt might occur after the check on line 4953 but before the sleep on line 4955. The interrupt might call iodone() , which might call brelse() to put a buffer on the free list. In that case, brelse() would call wakeup(&bfreelist) and clear BWANTED before the interrupted process called sleep() . As a result the process would not wake up even though there is a free buffer. 3. [5 points]: Two v6 processes call read() at about the same time for different blocks that are not in the cache. There are many blocks on bfreelist , and no other active processes. As a result, there are two calls to getblk() , both of which allocate a free buffer in lines 4960 through 4975 at about the same time. Could the two processes end up taking the same buffer from the free list? If yes, how could that happen? If no, what prevents that from happening? No, this could not happen. In V6, context switches between processes executing in the kernel can occur only during sleep() or just before a process returns to user space. As long as no interrupt-time code removes a buffer from bfreelist (and none does) there will no problem. 6.828 FALL 2005, Quiz 1 SOLUTIONS Page 2 of 10 4. [5 points]: Suppose the B BUSY ag were eliminated from the v6 source, so that for example lines 4941 through 4946 were deleted. Explain a scenario in which incorrect behavior would result. In vague terms, the BBUSY ag indicates that a process is actively using this buffer, for example because it is waiting for the result of a disk read to be put there. Eliminating the ag could result in kernel data structures being put in an inconsistent state. For example, suppose a process calls read() , and the resulting getblk() call from bread() does not find the block in the cache. getblk() will put the buffer on the devices buffer list with the desired block number and device, but (so far) without correct contents. Then bread() will call rkstrategy() , which (among other things) sets the avforw pointer in the struct buf to 0 and then waits for the disk read to complete....
View Full Document

Page1 / 10

q1_fall05_sol - I 6.828 FALL 2005, Quiz 1 SOLUTIONS Page 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online