0% found this document useful (0 votes)
21 views10 pages

CS4448 - Nguyen Tuan Anh - Homework 2

The document discusses page replacement algorithms and internal fragmentation in paging. It provides examples of applying FIFO, LRU and MRO page replacement algorithms. It also calculates the internal fragmentation and total wasted memory for different page sizes when loading three subroutines into memory using paging.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views10 pages

CS4448 - Nguyen Tuan Anh - Homework 2

The document discusses page replacement algorithms and internal fragmentation in paging. It provides examples of applying FIFO, LRU and MRO page replacement algorithms. It also calculates the internal fragmentation and total wasted memory for different page sizes when loading three subroutines into memory using paging.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

8.

Given that main memory is composed of only three page frames for public use, and that a program
requests pages in the following order:
a, c, b, d, a, c, e, a, c, b, d, e

a. Using the FIFO page removal algorithm, indicate the movement of the pages into and out of the
available page frames (called a page trace analysis) indicating each page fault with an asterisk (*).
Then compute the failure and success ratios.
b. Increase the size of memory so it contains four page frames for public use. Using the same page
requests as above and FIFO, do another page trace analysis and compute the failure and success
ratios.
c. What general statement can you make from this example? Explain your answer.

Answer
Main memory has three page frames for public use.
Page requests: a, c, b, d, a, c, e, a, c, b, d, e

a. Using three page frames:

Initially, all page frames are empty.

Request for page 'a':


Page Frame 1: a*

Request for page 'c':


Page Frame 1: a*
Page Frame 2: c*

Request for page 'b':


Page Frame 1: a*
Page Frame 2: c*
Page Frame 3: b*
Request for page 'd':
Page Frame 1: d* (a is replaced)
Page Frame 2: c*
Page Frame 3: b*

Request for page 'a':


Page Frame 1: d*
Page Frame 2: a* (c is replaced)
Page Frame 3: b*

Request for page 'c':


Page Frame 1: d*
Page Frame 2: a*
Page Frame 3: c* (b is replaced)

Request for page 'e':


Page Frame 1: e* (d is replaced)
Page Frame 2: a*
Page Frame 3: c*

Request for page 'a':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c*

Request for page 'c':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c*
Request for page 'b':
Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: b* (c is replaced)

Request for page 'd':


Page Frame 1: e*
Page Frame 2: d* (a is replaced)
Page Frame 3: b*

Request for page 'e':


Page Frame 1: e*
Page Frame 2: d*
Page Frame 3: b*

With three page frames, there were 8 page faults (*). The failure ratio is 8/12, and the success
ratio is 4/12.

b. Using four page frames:

Now, let's repeat the page trace analysis with four page frames.

Initially, all page frames are empty.

Request for page 'a':


Page Frame 1: a*

Request for page 'c':


Page Frame 1: a*
Page Frame 2: c*
Request for page 'b':
Page Frame 1: a*
Page Frame 2: c*
Page Frame 3: b*

Request for page 'd':


Page Frame 1: a*
Page Frame 2: c*
Page Frame 3: b*
Page Frame 4: d*

Request for page 'a':


Page Frame 1: a*
Page Frame 2: c*
Page Frame 3: b*
Page Frame 4: d*

Request for page 'c':


Page Frame 1: a*
Page Frame 2: c*
Page Frame 3: b*
Page Frame 4: d*

Request for page 'e':


Page Frame 1: e* (a is replaced)
Page Frame 2: c*
Page Frame 3: b*
Page Frame 4: d*

Request for page 'a':


Page Frame 1: e*
Page Frame 2: a* (c is replaced)
Page Frame 3: b*
Page Frame 4: d*

Request for page 'c':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c* (b is replaced)
Page Frame 4: d*

Request for page 'b':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c*
Page Frame 4: b*

Request for page 'd':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c*
Page Frame 4: d*

Request for page 'e':


Page Frame 1: e*
Page Frame 2: a*
Page Frame 3: c*
Page Frame 4: d*

With four page frames, there were still 4 page faults (*). The failure ratio is 4/12, and the
success ratio is 8/12.
c. General Statement:
The general statement we can make from this example is that increasing the number of
available page frames in main memory can significantly reduce the number of page faults
when using the FIFO (First-In-First-Out) page replacement algorithm. With three page
frames, there were 8 page faults, resulting in a failure ratio of 8/12. However, when the
number of page frames was increased to four, the number of page faults reduced to 4,
resulting in a lower failure ratio of 4/12.

13. Calculate the cache hit ratio using the formula presented in this chapter,
assuming that the total number of requests is 2,056, and 777 of these requests
are found in the cache

Answer
To calculate the cache hit ratio, you can use the following formula:

Cache Hit Ratio = (Number of Cache Hits / Total Number of Requests) * 100%

Cache Hit Ratio = (777 / 2,056) * 100%

Cache Hit Ratio = (777 / 2,056) * 100% ≈ 37.79%

So, the cache hit ratio is approximately 37.79%. This means that out of 2,056 total requests,
777 were found in the cache, indicating that roughly 37.79% of the requests were satisfied by
the cache without needing to access the main memory or storage.

15. Given three subroutines of 550, 290, and 600 words each, if segmentation is
used, then the total memory needed is the sum of the three sizes (if all three
routines are loaded). However, if paging is used then some storage space is
lost because subroutines rarely fill the last page completely, and this results in
internal fragmentation. Determine the total amount of wasted memory due
to internal fragmentation when the three subroutines are loaded into memory
using each of the following page sizes:
a. 100 words
b. 600 words
c. 700 words
d. 900 words

Answer

Given:

Subroutine 1 size: 550 words


Subroutine 2 size: 290 words
Subroutine 3 size: 600 words
We'll calculate the internal fragmentation for each page size:

a. Page Size: 100 words


Subroutine 1:

Pages required = Ceiling(550 / 100) = 6 pages


Internal fragmentation = 100 - (550 % 100) = 50 words (last page is partially filled)

Subroutine 2:

Pages required = Ceiling(290 / 100) = 3 pages


Internal fragmentation = 100 - (290 % 100) = 10 words (last page is partially filled)

Subroutine 3:

Pages required = Ceiling(600 / 100) = 6 pages


Internal fragmentation = 100 - (600 % 100) = 0 words (last page is fully used)
Total internal fragmentation for a page size of 100 words:
50 (Subroutine 1) + 10 (Subroutine 2) + 0 (Subroutine 3) = 60 words

b. Page Size: 600 words


Subroutine 1:

Pages required = Ceiling(550 / 600) = 1 page


Internal fragmentation = 600 - (550 % 600) = 50 words (last page is partially filled)
Subroutine 2:

Pages required = Ceiling(290 / 600) = 1 page


Internal fragmentation = 600 - (290 % 600) = 310 words (last page is partially filled)
Subroutine 3:

Pages required = Ceiling(600 / 600) = 1 page


Internal fragmentation = 600 - (600 % 600) = 0 words (last page is fully used)
Total internal fragmentation for a page size of 600 words:
50 (Subroutine 1) + 310 (Subroutine 2) + 0 (Subroutine 3) = 360 words

c. Page Size: 700 words


Subroutine 1:

Pages required = Ceiling(550 / 700) = 1 page


Internal fragmentation = 700 - (550 % 700) = 150 words (last page is partially filled)
Subroutine 2:

Pages required = Ceiling(290 / 700) = 1 page


Internal fragmentation = 700 - (290 % 700) = 410 words (last page is partially filled)
Subroutine 3:

Pages required = Ceiling(600 / 700) = 1 page


Internal fragmentation = 700 - (600 % 700) = 100 words (last page is partially filled)
Total internal fragmentation for a page size of 700 words:
150 (Subroutine 1) + 410 (Subroutine 2) + 100 (Subroutine 3) = 660 words

d. Page Size: 900 words


Subroutine 1:

Pages required = Ceiling(550 / 900) = 1 page


Internal fragmentation = 900 - (550 % 900) = 350 words (last page is partially filled)
Subroutine 2:

Pages required = Ceiling(290 / 900) = 1 page


Internal fragmentation = 900 - (290 % 900) = 610 words (last page is partially filled)
Subroutine 3:

Pages required = Ceiling(600 / 900) = 1 page


Internal fragmentation = 900 - (600 % 900) = 300 words (last page is partially filled)
Total internal fragmentation for a page size of 900 words:
350 (Subroutine 1) + 610 (Subroutine 2) + 300 (Subroutine 3) = 1260 words

Ex17.

Answer
a/ FIFO meas first in first out so in this page replacement algorism the page frame which was loaded
first will be swapped out
b/ LRO means least recently used and from the given table page frame 2 was the least recently used.
We can say that it is ide from a longer time as compared to others so in LRU page 2 will be swapped
out

c. Page frame 3 will be swapped out by MRO because it has been referenced most recently. We can
know this by seeing the time when last referenced

Ex19

Answer

(a) From the given Segment Map Tables for Job1 and Job2,the following segments which are located
at memory location 2048, 6144 and 9216 are shared by Job1 and Job2.

(b)

New SMT for Job1:

Segment Memory
Number Location

0 4096

1 6144

2 9216

3 1024

4 8192

New SMT for Job 2:

Segment Memory
Number Location

0 1024

1 6144

2 9216

You might also like