The assignment is to be handed in class. No late assignments will be accepted.
What is reentrant code? Explain why sharing a reentrant module is easier when segmentation is used than when pure paging is used.
[Answer]
A reentrant or pure code does not change during execution
and thus can be shared by different processes.
The user's view of memory in segmentation corresponds to a number of segments
having names and variable lengths.
Thus, sharing reentrant code becomes easier in case of segmentation since
only that portion of code which needs to be shared can be made shareable
by assigning it to a particular segment rather than making a fixed chunk of
memory shareable which might consist of the desired as well as undesired
code for sharing.
[Answer]
Consider a paging system with the page table stored in memory.200 nanoseconds: 100 nonaseconds to access the page table and 100 nanoseconds to access the word in memory.
Effective access time:
0.75 * (100 nanoseconds) + 0.25 * (200 nanoseconds) = 125 nanoseconds
Assume the maximum acceptable page-fault rate is P.
0.2 microsec = (1 - P)*0.1 microsec + (0.4P)*10 millisec + (0.6P)*25 millisec
0.1 = -0.1P + 4000 P + 15000 P
0.1 = (19000 -0.1) P (approximately)
P = 0.00000526
----------------------
[Answer]
Thrashing is caused by under allocation of the minimum number of pages
required by a process, forcing it to continuously page fault.
The system can detect thrashing by evaluating the level of CPU
utilization as compared to the level of multiprogramming.
It can be eliminated by reducing the level of multiprogramming.
Given memory partitions of 300K, 350K, 190K, 600K, 250K and 700K(in order), how would each of the
a. First-fit
b. Next-fit
c. Best-fit
d. Worst-fit
algorithms place processes of 255K, 450K, 185K, 310K, 650K(in order)? For first-fit algorithm, searching starts
at the beginning of the set of holes every time. For next-fit algorithm, searching starts at the beginning of the set
of holes the first time.
[Answer]
[First Fit]:------------------------
255K in 300K partition (45K hole), 450K in 600K partition (150K hole), 185K in 350K partition(165K hole), 310K in 700K partition(390K hole), 650K must wait.
[Next Fit]:
255K in 300K partition (45K hole), 450K in 600K partition (150K hole), 185K in 250K partition (65K hole), 310K in 700K partition(390K hole), 650K must wait.
[Best Fit]:
255K in 300K partition (45K hole), 450K in 600K partition (150K hole), 185K in the 190K partition (5K hole), 310K in 350K partition(40K hole), 650K in 700K partition (50K hole).
[Worst Fit]:
255K in 700K partition (445K hole), 450K in 600K Partition (150K hole), 185K in 445K hole after occupied by 255K process(260K hole), 310K in 350K partition (40K hole), 650K must wait.
var A: array[1..200]of array [1..200] of integer;
Where A[1][1] is at location 200, in a paged memory system with pages of size 200. A small process is in page 0(location 0 to 199) for manipulating the matrix; thus, every instruction fetch will be from page 0.
For three page frames, how many page faults are generated by the following array-initialization loops, using LRU repacement, and assuming page frame 1 has the process in it, and the other two are initially empty:
a. for j:= 1 to 200 do
for i:= 1 to 200 do
A[i][j]:=0;
b. for i:= 1 to 200 do
for j:= 1 to 200 do
A[i][j]:=0;
[Answer]
By default, the array is stored row-major;
that is, the first data page contains A[1,1], A[1,2], ..., A[1,200]
and the second page contains A[2,1], A[2,2], ..., A[2,200] and so on.
Therefore, each row (i) ocuppies one page and there are 200 pages in total.
[a]. Since the frame size is 3, every time a page other than 0 is accessed,
there is a page fault. In this loop since i is varying for every access,
there will be 200 page faults every time a different i (a page) is accessed.
It is accessed 200 times (looping 200 times for each j).
Thus there will be 40,000 page faults. The page reference string is:
0,1,0,2,0,3,0,...,0,200,
0,1,0,2,0,3,0,...,0,200,
... (200 times)
[b]. In this loop for a particular value of i, 'j's are looping.
Since all the data for every i are stored in the
same page, there will be one page access for every i,
thus resulting in 200 page faults. The page reference string is:
0,1,0,2,0,3,4, ..., 0,200
Consider the following page reference string:
A B C D B A E F C D B C G E B A B D F G
How many page faults would occur for the following replacement algorithms, assuming
four frames? Remember all frames are initially
empty, so your first unique pages will all cost one fault each. Please show complete working and how you have arrived
at the answer.
[Answer]
a. LRU (15/20)|
A |
B |
C | D | B | A | E | F | C | D | B | C | G | E | B | A | B | D | F | G |
| A | A | A | A | A | A | A | A | A | D | D | D | D | E | E | E | E | E | F | F |
| B | B | B | B | B | B | B | C | C | C | C | C | C | C | A | A | A | A | G | |
| C | C | C | C | E | E | E | E | B | B | B | B | B | B | B | B | B | B | ||
| D | D | D | D | F | F | F | F | F | G | G | G | G | G | D | D | D | |||
| * | * | * | * | * | * | * | * | * | * | * | * | * | * | * |
b. NUR (15/20)
|
A |
B |
C | D | B | A | E | F | C | D | B | C | G | E | B | A | B | D | F | G |
| >A1 | >A1 | >A1 | >A1 | >A1 | >A1 | E1 | E1 | E1 | E1 | E0 | >E0 | G1 | G1 | G1 | G0 | >G0 | D1 | D1 | D0 |
| B1 | B1 | B1 | B1 | B1 | >B0 | F1 | F1 | F1 | F0 | F0 | >F0 | E1 | E1 | E0 | E0 | >E0 | F1 | F0 | |
| C1 | C1 | C1 | C1 | C0 | >C0 | >C1 | >C1 | B1 | B1 | B1 | >B1 | >B1 | A1 | A1 | A1 | >A1 | G1 | ||
| D1 | D1 | D1 | D0 | D0 | D0 | D1 | >D0 | C1 | C1 | C1 | C1 | >C0 | B1 | B1 | B1 | >B0 | |||
| * | * | * | * | * | * | * | * | * | * | * | * | * | * | * |
C. OPT (10/20)
|
A |
B |
C | D | B | A | E | F | C | D | B | C | G | E | B | A | B | D | F | G |
| A | A | A | A | A | A | E | F | F | F | F | F | F | F | F | F | F | F | F | G |
| B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | |
| C | C | C | C | C | C | C | C | C | C | G | E | G | A | A | A | A | A | ||
| D | D | D | D | D | D | D | D | D | D | D | D | D | D | D | D | D | |||
| * | * | * | * | * | * | * | * | * | * |
For the following reference string:
A C F B C E B C F D A E F F C D A A D E
[Answer]
Frames = 3:
The window and stack are separated by an empty row.
|
A |
C |
F |
B |
C |
E |
B |
C |
F |
D |
A |
E |
F |
F |
C |
D |
A |
A |
D |
E |
|
A |
C |
F |
B |
C |
E |
B |
C |
F |
D |
A |
E |
F |
F |
C |
D |
A |
A |
D |
E |
|
|
A |
C |
F |
B |
C |
E |
B |
C |
F |
D |
A |
E |
E |
F |
C |
D |
D |
A |
D |
|
|
|
A |
C |
F |
B |
C |
E |
B |
C |
F |
D |
A |
|
|
F |
C |
|
|
A |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
E |
|
|
C |
C |
|
|
* |
* |
* |
* |
|
* |
|
|
* |
* |
* |
* |
* |
|
* |
* |
* |
|
|
* |
Total page faults = 14 of 20
---------------------------------------
Frames = 4:
The window and stack are separated by an empty row.
|
A |
C |
F |
B |
C |
E |
B |
C |
F |
D |
A |
E |
F |
F |
C |
D |
A |
A |
D |
E |
| A | C | F | B | C | E | B | C | F | D | A | E | F | F | C | D | A | A | D | E |
| A | C | F | B | C | E | B | C | F | D | A | E | E | F | C | D | D | A | D | |
| A | C | F | B | C | E | B | C | F | D | A | F | C | A | ||||||
| A | A | F | F | F | E | B | C | F | D | A | E | E | F | C | C | C | |||
| D | A | F | F | ||||||||||||||||
| * | * | * | * | * | * | * | * | * | * | * | * |
Total page faults = 12 of 20
In the following problem, main memory consists of 64 10-bit words. The contents of main memory are as follows:
|
Address |
Contents |
Address |
Contents |
Address |
Contents |
Address |
Contents |
|
0 |
778 |
16 |
681 |
32 |
315 |
48 |
75 |
|
1 |
488 |
17 |
842 |
33 |
733 |
49 |
468 |
|
2 |
50 |
18 |
147 |
34 |
713 |
50 |
538 |
|
3 |
64 |
19 |
611 |
35 |
423 |
51 |
173 |
|
4 |
411 |
20 |
508 |
36 |
23 |
52 |
14 |
|
5 |
389 |
21 |
333 |
37 |
667 |
53 |
915 |
|
6 |
121 |
22 |
795 |
38 |
191 |
54 |
877 |
|
7 |
793 |
23 |
285 |
39 |
590 |
55 |
25 |
|
8 |
470 |
24 |
234 |
40 |
17 |
56 |
911 |
|
9 |
293 |
25 |
238 |
41 |
866 |
57 |
505 |
|
10 |
29 |
26 |
318 |
42 |
639 |
58 |
0 |
|
11 |
152 |
27 |
687 |
43 |
594 |
59 |
65 |
|
12 |
480 |
28 |
801 |
44 |
172 |
60 |
408 |
|
13 |
830 |
29 |
192 |
45 |
88 |
61 |
268 |
|
14 |
16 |
30 |
611 |
46 |
741 |
62 |
654 |
|
15 |
168 |
31 |
45 |
47 |
816 |
63 |
237 |
Note: the addresses in the problems below are virtual addresses. The normal convention is to place the most significant portion of the address in the most significant bits of the address. Thus, the virtual addresses below will be formatted as follows:
paging
page # | word #
Consider an operating system using paging. Main memory is
divided into 4-word page frames. In a page table descriptor, the low order bits
contain the frame in which the page resides. To the left of the frame number is
the residency bit and the remaining bits are used by the operating system
(protection, whether the page has been modified, etc.).
Thus the page descriptor looks like:
OS ResidencyBit Frame#
The page table pointer for a process points to address 27. Give the results of the following memory references by that process:
a. 60
b. 18
c. 47
d. 25
[Answer]
Page frame size = 4 Total number of page frames = 16 Page descriptor = 27 + page# Physical address = frame# * 4 + word#Thus, 4 bits are required to represent a frame number. A page descriptor looks like: xxxxx x xxxx OS residency frame # Also since page frames are 4 words long, the low order 2 bits of an address contain the word within the page. The remaining bits contain the index into the page table.
xxxxxxxx xx
page # word within page
[a.] 60 =00001111 00
Thus, page# = 15, word# = 0
Page descriptor is at address 27 + 15 = 42
Contents of address 42 are 639
639 = 10011 1 1111
The residency bit is 1. Thus the page is resident, and thus no page fault occurs.
The frame number is 15.
Physical address = 15 * 4 + 0 = 60
contents of address 45: 408
[b.] 18 = 00000100 10
Thus, page# = 4, word# = 2
Page descriptor is at address 27 + 4 = 31
Contents of address 31 are 45
45 = 00001 0 1101
The residency bit is 0. Thus a page fault occurs.
[c.] 47 = 00001011 11
Thus, page# = 11, word# = 3
Page descriptor is at address 27 + 11 = 38
Contents of address 38 are 191
191 = 00101 1 1111
The residency bit is 1. Thus the page is resident, and thus no page fault occurs.
The frame number is 15.
Physical address = 15 * 4 + 3 = 63
contents of address 63: 237
[d.] 25 = 000000110 01
Thus, page# = 6, word# = 1
Page descriptor is at address 27 + 6 =33
Contents of address 33 are 733
733 = 10110 1 1101
The residency bit is 1. Thus the page is resident, and thus no page fault occurs.
The frame number is 13.
Physical address = 13 * 4 + 1 = 53
contents of address 53: 915