







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!








University of California, Berkeley College of Engineering Computer Science Division – EECS
Spring 2017 Ion Stoica
April 24, 2017 CS162 Operating Systems
Your Name:
SID AND 162 Login:
TA Name:
Discussion Section Time:
General Information: This is a closed book and one 2-sided handwritten note examination. You have 80 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points for that question. You should read all of the questions before starting the exam, as some of the questions are substantially more time consuming.
Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in a question that you believe is open to interpretation, then please ask us about it!
P1 (24 points total) True/False and Why? CIRCLE YOUR ANSWER. For each question: 1 point for true/false correct, 2 point for explanation. An explanation cannot exceed 2 sentences.
a) When two processes mmap() the same region of a file, mmap() will always return the same set of virtual addresses to both processes, which represent a shared region of memory.
Why?
The virtual addresses are not necessarily the same, both sets will point to the same physical region.
b) A TCP sender can overflow the receiver’s buffer.
Why?
Flow control will make sure the sender never sends more bytes than the receiver can store.
Why?
FAT needs to perform a disk access for every block to find the pointer to that block, while Unix File System gets the pointers to many blocks by reading an inode.
g) Using quorum consensus a writer can return before the data has been written to all replicas.
Why?
The writer returns after it hears form W replicas, where W is typically smaller than the total number of replicas, N.
h) With consistent hashing (e.g., Chord) if a new node is added to a system consisting of N > 1 nodes, this will lead to keys from every node to be moved around.
Why?
Let’s A be the new node. Only the keys of A’s successor will be moved to A.
P2 (15 points) Transactions. Consider two variables A and B which are initialized to 1, and 2, respectively:
Consider the following two transactions being attempted on A and B:
Transaction 1 Transaction 2
A=3 B=4 Commit A=5 B=6 Commit
For the following scenarios, list which ACID property was violated or “none” if the transactions obeyed ACID, explain your answer in 1 sentence:
a) (3 points) Transaction 1 successfully committed, then the computer crashed after step 2 (B=6) of transaction 2 (but before writing the commit record to the log). State after Recovery:
A 3
B 4
Correct ACID behavior. Txn 1 committed, txn 2 did not.
b) (3 points) The transactions were run on two threads (at the same time) and have both committed. Note: concurrent transactions may complete in any order. State which order your answer assumes (if any). State after Recovery:
A 3
B 4
Order (2, 1): Correct ACID behavior. Isolation only requires some serialized order (the outcome is as if one transaction ran to completion, then the next ran to completion), overwriting old commits is perfectly acceptable.
Order (1, 2): Durability (or maybe isolation) was violated. Durability: The changes from the latest committed transaction were not reflected in the final state (most recent changes were lost). Isolation is possible if you assume that B logged its changes, then A ran to completion, then B committed.
P3 (12 points) Synchronization. Consider the following C program.
int thread_count = 0;
void *thread_start(void *arg) { thread_count++; if (thread_count == 3) { char argv[] = {"/bin/echo", “162 is the best!”, NULL}; _/ Replace current process image with a new process image
int main(int argc, char *argv[]) { int i, status; for (i = 0; i < 2; i++) { pid_t pid = fork(); if (pid != 0) { thread_count++; wait(&status); } pthread_t thread = malloc(sizeof(pthread_t)); _/ start new “thread”. The new thread starts execution by invoking
a) (8 points) Provide one possible output from this C program.
Thread: 1 Thread: 2 162 is the best! Thread: 2 162 is the best! Thread: 4
b) (4 points) Is the output deterministic? If yes, give a short explanation why. If no, explain how to make the output deterministic.
Yes. Each process is serialized by its wait, and each thread is serialized by pthread_join. P4 (16 points) Queueing theory Consider a system with a single queue and a single server. The arrival rate of the requests follows a Poisson process, and the service time is exponential distributed. Thus, the system implements an M/M/1 queue. Assume that:
a) (4 points) What is the average service rate μ and arrival rate ƛ?
Service rate μ is 1/Tser, so 6 jobs per second. Utilization, u = λ/μ, so λ = u * μ = 3 jobs per second.
λ
a) (4 points) What are the average time spent in the queue Tq and the response time?
Tq = Tseru / (1-u) = (1/6)(1/2)/(1-1/2) = ⅙ seconds. Tsys = Tq + Tser = ⅙ + ⅙ = ⅓ seconds.
b) (4 points) What is the average length of the queue Lq?
By little’s law, this is lambda * Tq = 3 * ⅙ = ½ jobs.
c) (4 points) Assume that we add an additional server with the same service time ( Tser = ⅙ seconds) to help service our queue. What is the average time spent in the queue Tq and response time for the new system, assuming the same arrival rate as at point (a), and that requests are balanced equally across the two servers?
u is now half because the requests are split over the two servers. Tq = Tser(u/(1-u)) = (1/6)(1/4)/(1-1/4) = 1/18 seconds. Tsys = Tq + Tser = 1/18 + 1/6 = 4/18 seconds.
Service time to read from SSD = (1ms + 100KB/X)
Average service time = 0.51ms + 0.5(1ms + 100KB/X) = 1.25ms => 1ms + 100 KB/X = 1.5ms => X = 200MB/s
We gave partial credit to solutions that didn't include service time to read a key-value from cache.
P6 (18 points) TCP Flow Control. Assume host S uses TCP to send 1000 bytes of data to host R. We make the following assumptions:
a) (6 points) Assume no packet or acknowledgement is lost. Draw the packet diagram also indicating the bytes in R’s sending buffer and the bytes in S’s receiving buffer. For the acknowledgements indicate both the sequence of next expected byte, and the advertised window.
The first packet with the associated information is drawn for you.
Initial advertised window (AdvWindow) is equal with the receiver buffer size which is 500B. Also, while below we also show sender window (SendWin), there was no penalty for not showing it, as the problem didn’t ask for it.
b) (6 points) Draw the packet diagram assuming the acknowledgement of the first packet is lost. No other packet or acknowledgement is lost.