For the following sequence of page requests in a virtual memory

advertisement
CS 414 Operating Systems
Midterm, Spring 2001
Prof. Emin Gün Sirer
Name:_________________________________________ NETID:_________________



[16]
This is a closed book examination. It is four (4) pages long.
An incorrect answer to a true/false question will receive a negative score of –2 to offset a
correct answer. Consequently, randomly guessing answers is not a good strategy.
Show your work for partial credit.
1. Indicate if the following statements are true (T) or false (F).
_____ Hard real-time operating systems must provide fast response to interrupts.
_____ I/O buffering can increase CPU utilization.
_____ One of the ways direct memory access (DMA) improves system performance is by
reducing the number of interrupts required to complete an I/O operation.
_____ Modifying the page table base register requires a protected instruction.
_____ A cycle in a resource allocation graph (RAG, as described in the book and in lectures;
namely, each process and resource is a node, edges represent resource requests and
assignments) implies that the system is deadlocked.
_____ For large networks, a ring-shaped network topology, on average, achieves shorter routes
than a star topology.
_____ With asynchronous I/O, programs cannot make forward progress until their I/O
operations complete.
_____ The end-to-end argument indicates that deadlock detection and recovery are not critically
required when designing a banking system, as the financial auditing mechanisms of the
bank will catch any synchronization errors.
_____ Starvation is a potential drawback of a first-come first-served (FCFS) CPU scheduling
algorithm.
_____ If all processes obtain their resources in the same order, a system can never be
deadlocked.
_____ Virtual memory address translation is useful even if the total size of virtual memory,
summed over all programs, is smaller than physical memory.
_____ The maximum packet size requirement on the Ethernet is designed to ensure that
collisions are seen by all nodes on the network.
_____ UDP is a TCP-friendly protocol.
_____ TCP initiates a connection with a three-way handshake, and initially increases its window
size exponentially until encountering congestion.
_____ The size of a packet sent using the DSR protocol is O(N) in the worst case, where N is
the number of nodes in the network.
_____ The minithreads interface allows a thread to go directly from the READY state (or ready
queue) to the BLOCKED state (on a semaphore queue).
1
[8]
2. Explain why your minithreads implementation requires a separate helper thread to
clean up dead threads.
[15]
3. Given the initial starting state:
int x , y;
Semaphore_t sema1, sema2;
x = 34;
y = 50;
sema_initialize(sema1, 1);
sema_initialize(sema2, 1);
List the possible values of x for each of the following executions, after Thread1 and Thread2 have
terminated or can make no further progress. Assume that reading a variable from memory is an
atomic operation. Also assume that writing a variable back to memory is an atomic operation.
A)
Thread1:
{
x = x+1;
x = x+1;
}
B)
Thread1:
{
P(sema1);
x = x+1;
x = x+1;
V(sema1);
}
C)
Thread1:
{
P(sema1);
P(sema2);
x = x+1;
x = x+1;
V(sema2);
V(sema1);
}
Thread2:
{
x = y+1;
}
Thread2:
{
P(sema1);
x = y+1;
V(sema1);
}
Thread2:
{
P(sema2);
P(sema1);
x = y+1;
V(sema1);
V(sema2);
}
2
[20]
4. The state of a system is as shown. There are three processes P1, P2, P3, and two
resources, A and B. Determine if this system is in a safe state. Show your work.
Process
Allocated Max Need
A
B
A
B
P1
10 15
45
20
P2
0
30
40
55
P3
20 10
30
35
Available: A= 15, B=30.
[16]
5. Given the following stream of references to pages by an application, calculate the
number of page faults the application would incur with:
a. FIFO page replacement with 3 physical pages available.
b. FIFO page replacement with 4 physical pages available.
c. LRU with 3 physical pages available.
d. OPT with 3 physical pages available.
Assume that all physical pages are initially free.
Reference Stream:
321032432104232
3
[25]
6. You have been hired by Large-Concurrent-Systems-R-Us, Inc. to review their code.
Below is their atomic_swap procedure. It is intended to work as follows:
Atomic_swap should take two queues as arguments, dequeue an item from each, and enqueue
each item onto the opposite queue. If either queue is empty, the swap should fail and the queues
should be left as they were before the swap was attempted. The swap must appear to occur
atomically – an external thread should not be able to observe that an item has been removed from
one queue but not pushed onto the other one. In addition, the implementation must be concurrent
– it must allow multiple swaps between unrelated queues to happen in parallel. Finally, the
system should never deadlock.
Note if the implementation below is correct. If not, explain why (there may be more than one
reason) and rewrite the code so it works correctly. Assume that you have access to enqueue and
dequeue operations with the signatures given in the code below. You can also assume that every
queue has a semaphore field, initialized to 1, that you can access. You may assume that q1 and
q2 never refer to the same queue. You may add additional fields to the queue if you document
what they are.
extern Item *dequeue(Queue *);
extern void enqueue(Queue *, Item *);
void atomic_swap(Queue *q1, Queue *q2) {
Item *item1;
Item *item2; // items being transferred
P(q1->sema);
item1 = dequeue(q1);
if(item1 != NULL) {
P(q2->sema);
item2 = dequeue(q2);
if(item2 != NULL) {
enqueue(q2, item1);
enqueue(q1, item2);
V(q2->sema);
V(q1->sema);
}
}
}
4
Download