TD2 Solution
TD2 Solution
Exercise 1
I)
a)
1) Size of the logical address space (virtual memory space) is:
224 = 16MB (address on 24 bits therefore the number of combinations or addresses =224) 2)
Offset= 9 bits (since 29=512 the size of a page, so 9 bits are needed to address the 512 slots) 3)
24 – 9 = 15 bits (logical address=[p,offset], offset=9, then p=24-9=15bits)
4) 20 bits ( M.M size=1MB=220 bits So the number of bits for addressing this space 220 is 20 bits ) 5) 20 –
9 = 11 bits (since total bits for a physical address =20 then offset=9 So 20-9=11bits for the frame) 6) 2 15
= 32KB (the number of bits to address the pages is 15 then the number of all page addresses = 215 which
represents the number of elements in the page table = the entries of Page Table)
b) Yes. The program needs 2000 bytes of data (vector) and 1024 bytes of code, so a total of 3024 bytes in
memory.
The number of occupied pages: [3024 / 512] = 6 pages. In the last page, there remain 512 – 464 = 48 free
bytes (464=3024-(512*5)), which causes an internal fragmentation.
Exercise 2
Program size=460 Byte
Page size=100 Byte → program size with pages= 5 pages
Main Memory size= 200 Byte → M.M frames number = 2 frames
Waste calculation formula: page size- (pgm size mod page size)
Number of wasted space =100 -mod (460/100)=40 Byte (internal fragmentation at last page) The reference chain:
10 11 104 170 73 309 185 245 246 434 458 364 corresponding to the following page numbers: 0 0 1 1 0 3 1 2 2 4 4 3
NB: to find the number of the corresponding page, you have to make the integer division of the reference number
by the size of the page, for example:
For the reference 10: 10/100=0
A) FIFO
0 0 1 1 0 3 1 2 2 4 4 3
Frame 0 0 0 0 0 3 3 3 3 4 4 4
0
Frame 1 1 1 1 1 2 2 2 2 3
1
Frame 0 0 0 0 0 0 1 1 1 4 4 4
0
Frame 1 1 1 3 3 2 2 2 2 3
1
1
Number of page fault is = 7
Page fault rate =7/12 *100= 58%
C) OPTIMAL
0 0 1 1 0 3 1 2 2 4 4 3
Frame 0 0 0 0 0 3 3 3 3 3 3 3
0
Frame 1 1 1 1 1 2 2 4 4 4
1
2. Mask method
2. The initial value of the mask is one byte (00000000). The most significant bit is set to 1 each time this page is
used.
3. At each period (N ms), a right shift is made of the byte associated with each page.
2
4. The victim page is the page with the lowest mask value when the algorithm is launched.
LRU algorithm;
Min: integer;
Min← byte-min(number-page-load-mm);
Found← unique-test(min);
Victim-num ←Selection(min,list-page-load);
Finish;
3)
Stack method Counter method Mask method
Stack size increases the number of counters increases by increasing the size of
with the size of the central memory the main memory we will
increase the number of
the required bytes
Exercise 4
Access Segment Page Offset Result
1. Load data 0 1 1 6145
2. Load data 1 1 10 10
3. Load data 3 3 2047 Page Fault
4. Save data 0 1 4 Protection fault
5. Data storage 3 1 2 2050
6. Save data 3 0 14 28686
7. Jump to the address 1 3 100 16484
8. Load data 0 2 50 Page Fault
9. Read data 2 0 5 Page table fault
10. Jump to the address 3 0 60 Protection Fault
The details :
We have the page size= 2kb= 2*1024=2048 B
Physical address= frame*page size + offset
The access rights must be checked for each case.
3
1) Access: Load data with: segment=0, page=1 and d=1
From the segment table: the actual page (box)=3
So the physical address= 3*2048+1=6145
2) Access: Load data with: segment=1, page=1 and d=10
From segment table: actual page (frame)=0
So the physical address= 0*2048+10=10
3) Access: Load data with: segment=3, page=3 and d=2047
From segment table: real page (frame)=virtual page is on disk
So: page fault
4) Access: save data with: segment=0 or access is read-only => protection fault
5) ) Access: data storage with: segment=3, page=1 and d=2
From the segment table: the actual page (box)=1
So the physical address= 1*2048+2=2050
6) ) Access: save data with: segment=3, page=0 and d=14
From the segment table: the actual page (box)=14
So the physical address= 14*2048+14=28686
7) ) Access: Jump to the address with: segment=1, page=3 and d=100
From the segment table: the actual page (box)=8
So the physical address= 8*2048+100=16484
8) ) Access: Load data with: segment=0, page=2 and d=50
From the segment table: the actual page (frame)=on disk
So: Page Fault
9) ) Access: Read data with: segment=2, page=0 and d=5
From the segment table: the page table is not in MC
So: Page table fault
10) ) Access: Jump to the address with: segment=3, page=0 and d=60
From the segment table: access is read and write only
So: Protection fault
Exercise 5