solution

advertisement
Exam II
CSE 341 – Principles of Operating Systems – Spring 2005
Prof. Douglas Thain
NAME:
Definitions (2 points each)
Define each of these terms using one or two sentences.
Deadlock
A set of processes is deadlocked if each process in the set is waiting for an event that only
another process in the set can cause.
Livelock
Identical to deadlock, except that each process is actively attempting to access a
resource, and is continually denied.
Safe State
A state that is not deadlocked and has some scheduling order in which every process can
allocate up to its maximum and still run to completion.
Overlay
A clumsy form of virtual memory that requires the programmer to manually load
different parts of a program as it runs.
TLB (expand the acronym and briefly explain what it does)
A Translation Lookaside Buffer caches expensive page table lookups.
Working Set
WS(K,T) is the set of pages accessed by a process in the K seconds preceding time T.
Belady’s Anomaly
The rare case where adding memory to a system increases the number of page faults.
Thrashing (careful – give a very precise definition)
When the working set of a process is too large to fit in physical memory.
The operating system has no choice but to continually page data to and from the disk.
Linear Address
On an Intel processor, the intermediate address obtained after applying segmentation,
but before applying paging.
Call Gate
A well defined routine for transferring control between protection rings.
Short Answer (5 points each)
Answer each question in several sentences or perhaps one paragraph.
A good answer can fit in the available space.
1 - What are the four conditions necessary for deadlock to occur?
Describe each in one sentence.
Mutual Exclusion
Each resource is either currently assigned to exactly one process, or is available.
Hold and Wait
Processes current holding resources and request new resources.
No Preemption
Resource already granted cannot be taken away.
Circular Wait
There must be a circular chain of processes, each waiting for a resource held by
the next.
2 – Consider a system with four processes and five types of resources. Given the
following situation, what is the smallest value of X for which the system is in a safe
state? Carefully explain the reasoning behind your answer.
Process A
Process B
Process C
Process D
Allocated
10112
11011
11010
20011
Maximum
11215
11122
21013
22014
Available
0011X
The smallest value is X=2.
If X=0, then there is no process that can allocate and complete.
If X=1, then the following can happen:
00111
Starting available vector
+
11011
B allocates and exits
=
11122
New available vector (but no other process may proceed)
If X=2, then the following can happen:
00112
Starting available vector
+
11011
B allocates and exits
=
11123
New available vector
+
10112
A allocates and exits
=
21235
New available vector
+
11010
C allocates and exits
=
32245
New available vector
+
20011
D allocates and exits
52256
Algorithm complete.
3 - Both segmentation and paging systems suffer from the problem of fragmentation.
For each type of system, describe how fragmentation can occur and explain how the
problem can be addressed.
With segmentation, external fragmentation can occur if many segments of different sizes
are created and deleted. Holes of unusual size will be left between segments. The
operating system can attack this problem by rearranging the segments to be contiguous
in memory. However, this is an expensive operation that cannot be done frequently.
With paging, all of the pages fit together nicely because they are the same size, but there
is no guarantee that programs will use all of each page that they are given. This is called
internal fragmentation. To reduce internal fragmentation, the programs themselves must
be modified to use memory in nice page size chunks. This is rarely feasible in practice.
4 – Both LRU and WS are considered to be “ideal” page replacement algorithms.
However, neither is used in a “pure” form in real operating systems.
Explain why this is. How do real systems approximate LRU and WS?
Pure LRU and pure WS require the operating system to store some information every
time memory is accessed. LRU must store the time of access, while WS must keep track
of the set of pages accessed in the last K seconds. This is impractical in real systems,
because it would double the number of actual memory accesses, thus slowing the system
by half.
Real systems approximate LRU and WS with the Clock and WSClock algorithms.
Both of these periodically examine the R bit in the page table to determine if a page has
been accessed “recently”. Because these algorithms do not require instantaneous
knowledge of memory usage, they are able to run efficiently.
Long Answer (10 points each)
Answer each question fully. Partial answers may get partial credit.
A good answer can fit in the available space. But, use the back of the page if needed.
1. Operating System Structure
Suppose that a conventional operating system has many processes running
simultaneously, so that the CPU is always busy and all physical memory is in use.
Furthermore, assume that the system is equipped with a very slow backing store that
takes about one second to service a read or write request. Now, one process attempts to
access a virtual address that is not loaded into physical memory. A page fault occurs.
Describe how the operating system handles the page fault, from the attempted memory
access until the process is able to run again. Be sure to show how the process interacts
with the kernel and how the kernel interacts with the hardware. Consider how his action
affects other processes on the system. Include all relevant data structures in the kernel
and the hardware facilities employed by the operating system.
1 – The process attempts to access a page that has no entry in the page table.
2 – The hardware detects this and causes a page fault, transferring control to the kernel.
3 – The kernel puts the process in the blocked state.
4 – Because memory is full, the kernel must choose a page to remove from memory. It
applies a page replacement algorithm such as LRU or WS in order to choose the victim.
5 – If the page is dirty, it must be written to disk. The kernel calls the disk driver to write
the page to disk, requesting an interrupt to be delivered when it is complete.
6 - The kernel allows other processes to run until the disk interrupt arrives.
7 – Now that the dirty page has been removed, the kernel calls the disk driver to load the
page requested by the faulting process. An interrupt will be delivered when complete.
8 – Again, the kernel allows other processes to run until the disk interrupt arrives.
9 – Now that the new data is loaded, the kernel updates the faulting process’ page table.
10 – The kernel moves the process back into the running state, and returns to user mode,
allowing the process to continue operation.
2. Virtual Memory Structures
The fictional VRISC-341 computer has a 42-bit virtual address, a 32-bit physical address
and 16KB page frames. Diagram the memory management tables necessary to
implement paging on this system in two different ways. Draw two diagrams. In the first,
show a single large page table. In the second, show a multi-level page table.
Be sure to carefully label all relevant information in each diagram. Show the number of
bits in each address field, the number of entries in each table, the total size (in KB, MB,
TB, etc) of each table, and the maximum amount of virtual and physical memory
available to each process.
Maximum Virtual Memory: 2^42 B = 4 TB
Maximum Physical Memory: 2^32 B = 4 GB
Single Level Page Table:
Virtual Address:
28
14
page table
2^28 entries
1 GB total
page
16 KB
Multi Level Page Table:
Virtual Address:
4
12
page table
2^4 entries
64 B total
12
14
page table
2^12 entries
16KB total
page table
2^12 entries
16KB total
page
16 KB
Download