You are on page 1of 4

Exam 2 (Nov.

13, 1997)

1.
(a) 8 pts.
<Answer>
Unlike the normal page table the i-th entry contains
information on the page occupying page frame i.
This is used with an associative memory (i.e. TLB)
and on a miss in the associative memory (i.e. TLB miss)
the inverted page table is searched [Tanenbaum p.107].

(b) 8 pts.
<Answer>
Use a hash table

2.
(a) 8 pts.
<Answer>
It is not always true that the more page frames the memory has,
the fewer page faults a program will get.

Ex.) FIFO can cause more page faults with 4 page frames
than with 3 page frmaes for some reference string
[Tanenbaum pp.114-115] (4 pts.).

Stack algorithms:
Page replacement algorithms with the property
that M(m,r) is included in M(m+1,r) for all m, r, and reference
strings, where M is an array keeping track of the state of memory
, m is the number of page frames, and r is an index
into the reference string of the process [Tanenbaum pp. 116-117].
In other words, the set of pages
in memory with m page frames is always a subset of
the set of pages that would be in memory with m + 1 page frames.

(b) 8 pts.
<Answer>
"LIFO (Last-In-First-Out) page replacement algorithm
is a stack algorithm"

There are various ways we prove the above claim.

Sample proof)
Assumption: The memory is initially empty.
M1: the system with m page frames
M2: the system with m + 1 page frames
P1: the set of pages in memory of M1
P2: the set of pages in memory of M2
f : an index into a given reference string
when the m_{th} page fault occurs

Proof by induction on r, an index into the reference string.


When r = 1: P1 is a subset of P2
...
When r = f: P1 is a subset of P2
Hence, P1 is a subset of P2 if r is less than or equal to f. --> Claim A

When r is greater than or equal to f+1


we want show that P1 is a subset of P2 for all r.
Base case: r = f+1
If page fault does not occur in M1 when r = f + 1, then
neither does it in M2 since M2 has read a new page
into memory whenever M1 reads it into its memory.
So, still P1 is a subset of P2.
If page fault occurs in M1, then
the last-in page of P1 is replaced with a new page
but in M2 the new page is just inserted to P2
without any page evicted.
So, still P1 is a subset of P2.

Induction step:
Inductive Hypothesis -
P1 is a subset of P2 when r = n, where n is greater than f.

If page fault does not occur in M1 when r = n + 1 then


it means that the referenced page was in P1 when r = n.
So, P2 also has the page. <- by Inductive Hypothesis
If page fault occurs in M1 then we should consider
two cases.
Case I: M2 does not need to replace any page in memory
(i.e. the new page was already in P2).
So, the new page put into P1 is also in P2.
Thus, P1 is a subset of P2. <- by Inductive Hypothesis
Case II: M2 needs to replace the last-in page with a new page.
In this case, the page evicted by M2 cannot be in P1.
After evicting the last-in page, M2 reads the page
that M1 reads.
Thus, still P1 is a subset of P2. <- by Inductive Hypothesis

Hence, P1 is a subset of P2 when r = n + 1, where r is


greater than f (q.e.d.) ---> Claim B

Therefore, Last-In-First-Out page replacement algorithm


is a stack algorithm. <-- by claim A and claim B.

3.
(a) 8 pts.
Replace the page that has not been used for the longest
period of time.
<Answer>
1, 2, 3, 4, 5, 3, 1, 6, 7, 8, 7, 9, 4, 5, 4, 5, 2, 9
PF PF PF PF PF PF PF PF PF PF PF PF PF
13 page faults

(b) 8 pts.
Replace the page that has the longest forward distance.
<Answer>
1, 2, 3, 4, 5, 3, 1, 6, 7, 8, 7, 9, 4, 5, 4, 5, 2, 9
PF PF PF PF PF PF PF PF PF PF
10 page faults

4.
<16 pts.>
<Answer>

There is an example showing that muliple-resource type banker's


scheme cannot be implemented by indvidual application of
the single-resource type scheme to each resource type.
- Example
Suppose the snapshot of a system is as follows:

Allocated MAX Available


R1 R2 R1 R2 R1 R2
P1 1 0 2 2 1 1
P2 0 1 2 2

Considering the single-resource type scheme to


each resource (i.e. R1 and R2), the system would seem
to be in a safe state; however, if both P1 and P2 requests its
maximum needs of R1 and R2 then it will result in deadlock.

5.
(a) 4 pts.
<Answer>
It can happen that Process A locks account 100 and then tries to get a lock
for account 200 which cannot be locked by Process A
since account 200 has been already locked by another process waiting
for account 100.

(b) 4 pts.
<Answer>
Order accounts (i.e. resource) numerically.
Only after a process locks the lower-numbered
(or the higher-numbered) account first, it locks
the other account.

(c) 4 pts.
<Answer>
- Mutual exclusion
- Hold and wait
- Non-preemption
- Circular wait

(d) 4 pts.
<Answer>
Circular wait condition

6.
(a) 8 pts.
<Answer>
Yes.
There are many ways that make all the processes finish jobs.
Ex.)
<P0,P2,P1,P3,P4>, <P0,P4,P1,P2,P3>, <P2,P0,P1,P3,P4>, ...

(b) 8 pts.
<Answer>
Yes.
P0 can still finish its job
since its resource is already allocated,
even though the sytem grants (0,4,2,0) to P1.
Finishing P0, we have (1,1,1,2) as Available vector
and P4 can get its needs.
Now P1, P2, and P3 can finish its job.
Thus, after granting P1's request
the system is still in a safe state.
7.
(a) 8 pts.
The operating system should erase the block
before releasing it from a security point of view
; however, from a performance point of view
it is not desirable since it needs additional
disk writes.

(b) 8 pts.
Yes.
We can use file names like /usr/bin/csh.

You might also like