Quiz II Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Similar documents
Quiz II Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz II Solutions. Mean 55.4 Median 58 Standard deviation 13.0

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall 2010.

6.828 Fall 2007 Quiz II Solutions

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

CSE 451 Autumn Final Solutions mean 77.53, median 79, stdev 12.03

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

250P: Computer Systems Architecture. Lecture 14: Synchronization. Anton Burtsev March, 2019

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I Solutions. Mean 70.5 Median 72 Standard deviation 15.8 Kurtosis -0.

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

Lecture 3: O/S Organization. plan: O/S organization processes isolation

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Quiz II Solutions. q2 Grades Mean: 72.48, Median: 74.00, StDev: 14.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

6.097 Operating System Engineering: Fall Quiz II THIS IS AN OPEN BOOK, OPEN NOTES QUIZ.

CS3210: Virtual memory applications. Taesoo Kim

This is an open book, open notes exam. But no online or in-class chatting.

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Problem Set 2. CS347: Operating Systems

The Art and Science of Memory Allocation

CS 326: Operating Systems. Process Execution. Lecture 5

Scalable Locking. Adam Belay

CSC369 Lecture 2. Larry Zhang

6.033 Computer Systems Engineering: Spring Quiz I THIS IS AN OPEN BOOK, OPEN NOTES QUIZ. NO PHONES, NO COMPUTERS, NO LAPTOPS, NO PDAS, ETC.

csci3411: Operating Systems

G Operating Systems: Spring Final Exam

6.824 Distributed System Engineering: Spring Quiz I Solutions

CS5460/6460: Operating Systems. Lecture 14: Scalability techniques. Anton Burtsev February, 2014

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2003

This is an open book, open notes exam. But no online or in-class chatting.

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I Solutions

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

CS3210: Virtual memory. Taesoo Kim w/ minor updates K. Harrigan

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

W4118 Operating Systems. Junfeng Yang

This is an open book, open notes exam. But no online or in-class chatting.

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall 2008.

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Operating system organizaton

CSC369 Lecture 2. Larry Zhang, September 21, 2015

OS Structure. Kevin Webb Swarthmore College January 25, Relevant xkcd:

CS-537: Midterm Exam (Fall 2013) Professor McFlub

Operating Systems (1DT020 & 1TT802)

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

EECS 482 Introduction to Operating Systems

CS 153 Design of Operating Systems Winter 2016

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Distributed System Engineering: Spring Exam II

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

Kernel Synchronization I. Changwoo Min

RCU. ò Walk through two system calls in some detail. ò Open and read. ò Too much code to cover all FS system calls. ò 3 Cases for a dentry:

Part 1: Introduction to device drivers Part 2: Overview of research on device driver reliability Part 3: Device drivers research at ERTOS

VFS, Continued. Don Porter CSE 506

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Asynchronous Events on Linux

Synchronization I. Jo, Heeseung

CS2028 -UNIX INTERNALS

- Knowledge of basic computer architecture and organization, ECE 445


CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Native POSIX Thread Library (NPTL) CSE 506 Don Porter

CPS 310 first midterm exam, 10/6/2014

CS 61 Section Notes 5

[537] Locks. Tyler Harter

CSE421 Alternate Midterm Solutions SOLUTION SET 08 Mar 2012

Spring 2017 :: CSE 506. Introduction. Nima Honarmand

CS61 Scribe Notes Lecture 18 11/6/14 Fork, Advanced Virtual Memory

Spring 2017 :: CSE 506. Device Programming. Nima Honarmand

Stanford University Computer Science Department CS 140 Midterm Exam Dawson Engler Winter 1999

CSE 120 Principles of Operating Systems

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Ext3/4 file systems. Don Porter CSE 506

Operating Systems, Fall

PROCESS SYNCHRONIZATION

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Department of Electrical Engineering and Computer Science

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Master level: Operating systems, distributed systems, networking,

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2006

6.033 Spring 2004, Quiz 1 Page 1 of Computer Systems Engineering: Spring Quiz I

Kernel Scalability. Adam Belay

Operating System Structure

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

CS140 Operating Systems Midterm Review. Feb. 5 th, 2009 Derrick Isaacson

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Distributed System Engineering: Spring Exam I

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

This is an open book, open notes exam. But no online or in-class chatting.

CS3210: Isolation Mechanisms

Transcription:

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.828 Fall 2014 Quiz II Solutions Mean 62.1 Median 65.0 Standard deviation 14.0 Kurtosis 2.6 20 15 10 5 0 0 10 20 30 40 50 60 70 80 90 1

I Ext3 1. [5 points]: Ext3 supports several modes, including journaled and ordered. Consider the workload of an application overwriting the same file n times: each iteration opens the file, writes all the blocks in the file, closes the file, and syncs the file. The file is b blocks large. For this workload, estimate how many disk writes of data blocks Ext3 will perform in journaled mode? How many in ordered mode? (Explain your answer briefly.) Answer: In journaled mode, ext3 will write each block twice (once to the log and once to its actual location), so the number of data writes is 2bn. In ordered mode, each block is only written once and the total number of writes is bn. 2. [5 points]: Describe an application that would want to use ext3 in journaled mode, and explain briefly what would go wrong if the application were to use ordered mode. Answer: An application that requires failure-atomicity for its data blocks would want to use journaled mode. For example, consider a database which uses a file to implement its transaction log. In ordered mode, the metadata of the log might be updated but the data blocks could be missing after a sync concurrent with a power failure. 2

II OS organization This question explores the differences between 3 OS organizations: monolithic, microkernel, and exokernel. 3. [5 points]: Identify a subsystem out of JOS that provides a good example of an exokernel organization and briefly explain why it is a good example. Answer: User-level copy-on-write fork is a good example of exokernel organization because it uses the user-space library operating system to provide system-level functionality. 4. [5 points]: Identify a subsystem out of JOS that provides a good example of a microkernel organization and briefly explain why it is a good example. Answer: The file server is a good example of microkernel organization because it is a user-space environment, the disk is mapped into only that environment, and other environments interact with it using IPC. 5. [5 points]: Identify a subsystem out of JOS that provides a good example of a monolithic-style subsystem and briefly explain why it is a good example. Answer: The network device driver is a good example of monolithic organization because it is implemented entirely in the kernel. 3

III Singularity In Singularity only one process can have a pointer to an object in the exchange heap. Ben proposes to modify Singularity to maintain a reference count for each object in the exchange heap and collect the object when the reference count is zero. When a process dies, he arranges to decrease the reference counter for each object in the exchange heap to which the dying process has a pointer. In Ben s design several processes can share an object in the heap. This would allow Ben to use the exchange heap, for example, for a shared buffer cache. 6. [5 points]: What problem does Singularity try to solve by disallowing shared objects in the exchange heap? (Briefly explain your answer.) Answer: Disallowing shared objects provides stronger fault isolation. If shared objects were allowed, one process could scribble over a block in the buffer cache after it had sent the block to another process via IPC. 7. [5 points]: How would you implement a shared buffer cache in Singularity as described in the paper (i.e., without Ben s modification)? (Briefly explain your answer.) Answer: You would write a user-level file server that maintains the buffer cache internally. Since objects cannot be shared, the file server would need to copy a buffer before sending it to a consuming process. 4

IV Scalable locks The following code is an implementation of MCS locks, which was handed out in lecture: 1 static inline void 2 mcs_init(mcslock_t *l) 3 { 4 l->v = NULL; 5 } 6 7 static inline void 8 mcs_lock(mcslock_t *l, volatile struct qnode *mynode) 9 { 10 struct qnode *predecessor; 11 12 mynode->next = NULL; 13 predecessor = (struct qnode *)xchg((long *)&l->v, (long)mynode); 14 15 if (predecessor) { 16 mynode->locked = 1; 17 asm volatile("":::"memory") // memory barrier 18 predecessor->next = mynode; 19 while (mynode->locked) 20 nop_pause(); 21 } 22 } 23 24 static inline void 25 mcs_unlock(mcslock_t *l, volatile struct qnode *mynode) 26 { 27 if (!mynode->next) { 28 if (cmpxchg((long *)&l->v, (long)mynode, 0) == (long)mynode) 29 return; 30 while (!mynode->next) 31 nop_pause(); 32 } 33 ((struct qnode *)mynode->next)->locked = 0; 34 } 5

This code creates the following structure when two cores are waiting for a given lock: v: mcslock_t locked: 1 next: qnode locked: 1 next: 0 qnode 8. [5 points]: Using the picture, explain how MCS locks avoid collapse when a lock is contended by many cores. Answer: Collapse is avoided because the unlocking node writes to mynode->next->locked, which is only being read by a single CPU. Thus only one CPU issues a request for the recently invalidated cache line, and the cost of releasing the lock is independent of the number of CPUs waiting for the lock. The instruction asm volatile("":::"memory") (line 17) is a memory barrier, which tells the compiler to not reorder memory accesses past this barrier. 9. [5 points]: Describe a race if this instruction was omitted and the compiler was allowed to reorder instructions past the memory barrier. Answer: The race happens when the instruction on line 16 is ordered past line 18. In this case, the acquirer is inserted into the list while locked remains unset. If the lock holder calls mcs unlock before the acquirer executes the reordered line 16, the releaser will set locked to 0, and then the acquirer will set locked to 1 and spin on it forever. 6

V Virtual machines 10. [5 points]: Extended page tables translate guest physical to host physical addresses. Suppose we have two kernels (K 1 and K 2 ), which each map guest virtual addresses 0 to n to guest physical addresses 0 to n, where n is 4 Mbyte. What mapping should a virtual machine monitor setup using extended page tables for K 1 and K 2 so that the monitor can multiplex and run both kernels? Answer: One solution is the following: the EPT for K 1 is the identity map, and the EPT for K 2 adds n to each guest physical address. 11. [5 points]: In IX, when a network application calls run_io how many protection boundary changes (e.g., ring 3 to ring 0, non-root to root) happen? (Briefly explain your answer.) Answer: There are two protection boundary changes: from ring 3 non-root to ring 0 non-root when io_run is called, and back to ring 3 non-root when it returns. 12. [5 points]: In IX, when IX reads or writes the NIC queue, how many protection boundary changes happen? (Briefly explain your answer.) Answer: There are no protection boundary changes, because the NIC queues are memory-mapped into IX s address space. 7

VI Multitasking and Locks in JOS Alyssa P Hacker has successfully implemented fine-grained locks for her lab 4 challenge in 6.828. The page allocator, the console driver, the scheduler, and the inter-process communication (IPC) code each have their own spin lock. Later, when testing her fork code with 4 CPUs, Alyssa writes the following code fragment: if((a = fork()) == 0) { ipc_recv(&a, 0, 0); cprintf("process One!\n"); exit(); } if((b = fork()) == 0) { ipc_recv(&b, 0, 0); cprintf("process Two!\n"); exit(); } ipc_send(a, 0, 0, 0); ipc_send(b, 0, 0, 0); cprintf("process Three!\n"); 13. [5 points]: Assume that there are no other environments running. In what order will the strings be printed? (Explain briefly why.) Answer: There is a race condition: process one and process two will likely be picked up by the spare CPU cores when they are awakened (at the same time) by a timer interrupt. We can t say anything about the order. 8

VII Disk block cache Consider the following block cache code in JOS: 1 #define PTE_SYSCALL (PTE_P PTE_W PTE_U) 2 3 // Write the cached block at virtual address addr back to disk 4 void 5 flush_block(void *addr) 6 { 7 uint32_t blockno = ((uint32_t)addr - DISKMAP) / BLKSIZE; 8 9 if (addr < (void*)diskmap addr >= (void*)(diskmap + DISKSIZE)) 10 panic("flush_block of bad va %08x", addr); 11 12 if (!va_is_mapped(addr)!va_is_dirty(addr)) 13 return; 14 15 // Write the disk block and clear PTE_D. 16 addr = ROUNDDOWN(addr, BLKSIZE); 17 ide_write(blockno * BLKSECTS, (void*) addr, BLKSECTS); 18 sys_page_map(0, addr, 0, addr, uvpt[pgnum(addr)] & PTE_SYSCALL); 19 } 20 21 // Sync the entire file system. A big hammer. 22 void 23 fs_sync(void) 24 { 25 int i; 26 for (i = 1; i < super->s_nblocks; i++) 27 flush_block(diskaddr(i)); 28 } 29 30 static void 31 bc_pgfault(struct UTrapframe *utf) 32 { 33 <Sanity checks on faulting address and the super block...> 34 <Allocate new page...> 35 36 if ((r = ide_read(blockno * BLKSECTS, addr, BLKSECTS)) < 0) 37 panic("in bc_pgfault, ide_read: %e", r); 38 39 if ((r = sys_page_map(0, addr, 0, addr, uvpt[pgnum(addr)] & PTE_SYSCALL)) < 0) 40 panic("in bc_pgfault, sys_page_map: %e", r); 41 } Recall that the x86 automatically sets the dirty bit in the page table entry of any page that is written by software. 9

Ben Bitdiddle is working on the block cache for lab 5, but doesn t know that his implementation of sys page map() is buggy. When Ben s sys page map() maps a page, the page table entry is not modified if the physical address of the mapped page is unchanged. 14. [5 points]: For testing purposes, Ben writes an program that simply reads every file in the file system. Ben notices that, after running his test program, a call to fs sync() takes several seconds to complete even though no data was written. Why does fs sync() take so long? Answer: Because of the buggy sys page map(), the dirty bit remains set on many file mappings and fs sync() writes all of them back to disk. 10

VIII File descriptors in JOS Ben Bitdiddle would like to implement a new function, called reset_fds(), which will close all of a JOS environment s open file descriptors. 15. [5 points]: How should this function be implemented in JOS? What functionality should be added to the kernel (e.g. via a system call) and what modifications should be made to user space? Answer: No modifications should be made to the kernel, because an exokernel doesn t know anything about file descriptors. The new function reset_fds() should be added to the library operating system, probably in lib/fd.c. Ben s implementation of reset_fds() contains the following line of code: memset(fdtable, 0, MAXFD*PGSIZE); (Recall that the arguments to memset are the start address, fill value, and length to be filled.) Ben writes a program to test reset_fds() and runs it from the shell. Unfortunately, two bad things happen when the test program calls reset_fds(): the program page faults, and console input and output stop working in the shell. 16. [5 points]: Why does the test program page fault? Answer: Not every FD is in use, and if FD n is not in use then no memory is mapped at virtual address FDTABLE+n*PGSIZE. 17. [5 points]: Why do console input and output stop working in the shell? Answer: The pages representing open file descriptors are zeroed out. Because these pages are shared (with PTE_SHARE), the struct Fds for standard input and output are zeroed out for every user environment launched by init. The correct solution would have been to use sys_page_unmap or fd_close instead. 11

IX 6.828 We d like to hear your opinions about 6.828, so please answer the following questions. (Any answer, except no answer, will receive full credit.) 18. [1 points]: Grade 6.828 on a scale of 0 (worst) to 10 (best)? Answer: 40 30 20 10 0 0 2 4 6 8 10 19. [2 points]: Any suggestions for how to improve 6.828? Answer: Issue code reviews more promptly. Include more papers. Include fewer papers. Implement VGA. Better classroom. More lectures. Final project topic selection meetings. Discussion of lab solutions. Better online notes. The final is too early in the morning. More tests. More lecture time on labs. Homework could be more meaningful. Encourage more students to do lab 7. Instructions on what parts of the papers are important. Better communication about test time/format. More time on gdb, tools, etc. Less time on xv6. More portable toolset. Post hw solutions. More design in the labs. Group meetings to discuss labs. Provide less code. Hold office hours closer to lab deadline. Relate papers more to other things, and each other. Add recitations. Move final into in-class exam. Only 1 quiz. Make it harder. Fewer papers, but in more-depth discussion. Add diagrams to lecture notes. Lower the pace. More time with staff. More Linux. Microquizzes. Lecture videos. Split labs and give more deadlines. Less stepping through code. 20. [1 points]: What is the best aspect of 6.828? Answer: Labs. Writing an operating system. 21. [1 points]: What is the worst aspect of 6.828? Answer: Debugging. Quizzes. End of Quiz II Enjoy the break! 12