Docx
Docx
Chapter 3 Exercises
1. Compare and contrast internal fragmentation and external fragmentation. Explain the
circumstances where one might be preferred over the other. ANS: Internal fragmentation
occurs within partitions or page frames. External fragmentation occurs between pages or
segments. One might prefer external fragmentation because with compaction
(defragmentation) the wasted space can be reclaimed, but this is only one answer. Any
thoughtful answer is acceptable.
2. Explain the function of the Page Map Table in the memory allocation schemes described in
this chapter. Explain your answer with examples from the schemes that use a PMT. ANS:
Three schemes in this chapter used PMTs: Paged, Demand Paged, and Segmented/Demand
Paging (Segmented used SMTs instead). In all three memory allocation schemes, the PMT
tracks page assignments to page frames, but in the Paged and Demand Paged scheme the
PMT is referenced directly from the Job Table, and in the third one, segmented/demand
paged, it is referenced from the Segment Map Table (SMT), which is, in turn, referenced
from the Job Table.
3. If a program has 471 bytes and will be loaded into page frames of 100 bytes each, and the
instruction to be used is at byte 132, answer the following questions:
a. How many pages are needed to store the entire job? ANS: Assuming the job begins
loading at the first page (Page 0) in memory, then the entire job would require 5
pages -- Page 0 to Page 4
b. Compute the page number and exact displacement for each of the byte addresses
where the data is stored. (Remember that page numbering starts at zero). ANS:
Assuming the job begins loading at the first page (Page 0) in memory, then the
desired instruction will be at Byte 31 on Page 1.
4. Let’s say a program has 510 bytes and will be loaded into page frames of 256 bytes each, and
the instruction to be used is at byte 377, answer the following questions:
a. How many pages are needed to store the entire job?
ANS: 2 pages -- Assuming the job begins loading at the first page (Page 0) in
memory then the two page would be Page 0 and Page 1
b. Compute the page number and exact displacement for each of the byte addresses
where the data is stored. ANS: Assuming the job begins loading at the first page
(Page 0) in memory, then the desired instruction will be at Byte 120 (510-256 = 254.
377-256 = 121st byte, = Byte 120 because the first byte on the page is Byte zero). It
will be found on Page 1
5. Given that main memory is composed of only three page frames for public use and that a
seven-page program (with pages a, b, c, d, e, f, g) that requests pages in the following
order:
a, c, a, b, a, d, a, c, b, d, e, f
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.
ANS: Using the FIFO page removal algorithm and 3 page frames:
a*, c*, a, b*, a, d*, a*, c*, b*, d*, e*, f*
Failure ratio: 10/12, Success ratio: 2/12
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.
ANS: Using the FIFO page removal algorithm and 4 page frames:
a*, c*, a, b*, a, d*, a, c, b, d, e*, f*
Failure ratio: 6/12, Success ratio: 6/12
c. What general statement can you make from this example? Explain your answer.
ANS: A general conclusion, which agrees with intuition, is that by adding more
available page frames when using FIFO, one can reduce the rate of failure and
increase the rate of success. This conflicts with the answer in the next exercise.
6 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. ANS:
Using the FIFO page removal algorithm a*, c*, b*, d*, a*, c*, e*, a, c, b*, d*, e
Failure ratio: 9/12, Success ratio: 3/12
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. ANS:
Using the FIFO page removal algorithm: a*, c*, b*, d*, a, c, e*, a*, c*, b*, d*, e*
Failure ratio: 10/12, Success ratio: 2/12
c. What general statement can you make from this example? Explain your answer.
ANS: This is an example of Belady’s anomaly, a counter-intuitive result of adding
additional page frame resulting in more page faults, not fewer. A general conclusion
should include the concept that the FIFO algorithm will not always be improved by
adding more available page frames.
7. Given that main memory is composed of three page frames for public use and that a
program requests pages in the following order:
a, b, a, b, f, d, f, c, g, f, g, b, d, e
a. Using the FIFO page removal algorithm, perform a page trace analysis indicating
page faults with asterisks (*). Then compute the failure and success ratios. ANS:
Using the FIFO page removal algorithm, the page trace analysis is: a*, b*, a, b, f*,
d*, f, c*, g*, f*, g, b*, d*, e*
c. What conclusions do you draw from this comparison of FIFO and LRU performance?
Would you make general statements from this example? Explain why or why not.
ANS: From this problem, we might conclude that LRU will be more efficient than
FIFO in most cases as it was true in this case. But there are system circumstances that
could favor the simplicity of FIFO over LRU. There is room for disagreement here
depending on the arguments used to bolster the student’s opinion.
8. Let us define “most-recently-used” (MRU) as a page removal algorithm that removes
from memory the most recently used page. Perform a page trace analysis using page
requests from the previous exercise for a system with 3 available page frames, and again
with 6 available page frames. Compute the failure and success ratios of each
configuration and explain why or why not MRU is a viable memory allocation system.
ANS: When using 3 page frames the page trace analysis is:
a*, b*, a, b, f*, d*, f*, c*, g*, f*, g*, b, d*, e*
Failure: 11/14, Success: 3/14
MRU is generally not a viable system because of the high number of page swaps.
However, as suggested with the 6 page frame example, if there are a sufficient number of
available page frames, swapping is minimized.
9. By examining the reference bits for the six pages shown in the figure below, identify
which of the eight pages was referenced most often as of the last time snapshot (Time 6).
ANS: Page 5 is referenced most often. By counting the ones, we can see it was referenced
six times. Which page was referenced least often? ANS: Page 1 is referenced least often.
By counting the ones, we can see it was referenced only two times. Explain your
reasoning. ANS: Look for students to demonstrate an understanding of shifting.
Page
Number Time 0 Time 1 Time 2 Time 3 Time 4 Time 5 Time 6
1000000 1100000 0110000 1011000 0101100 1010110 0101011
0 0 0 0 0 0 0 0
1000000 0100000 0010000 1001000 0100100 0010010 0001001
1 0 0 0 0 0 0 0 least referenced
1000000 0100000 0010000 1001000 1100100 1110010 0111001
2 0 0 0 0 0 0 0
1000000 1100000 1110000 0111000 1011100 1101110 0110111
3 0 0 0 0 0 0 0
1000000 1100000 0110000 1011000 0101100 0010110 1001011
4 0 0 0 0 0 0 0
1000000 0100000 1110000 0111000 1011100 1101110 1110111
5 0 0 0 0 0 0 0 most referenced
1000000 0100000 1010000 0101000 0010100 0001010 1000101
6 0 0 0 0 0 0 0
1000000 0100000 0010000 0001000 1000100 1100010 0110001
7 0 0 0 0 0 0 0
10. To implement LRU, each page uses a referenced bit. If we wanted to implement a least
frequently used (LFU) page removal algorithm, in which the page that was used the least
would be removed from memory, what would we need to add to the tables? What
software modifications would have to be made to support this new algorithm? ANS: To
implement this scheme, a counting mechanism (either software, or hardware and
software) would need to be added to count the frequency of page references. To modify
an LRU to LFU scheme, we’d need to modify the reference algorithm to track frequency
(which requires historical information and is therefore more complex than just checking
to see if which of several pages was used least recently).
11. Calculate the cache Hit Ratio using the formula presented in this chapter assuming that
the total number of requests is 2,056 and 647 of those requests are found in the cache.
ANS: 31.8%
Hit Ratio = total number of requests divided by the number of requests found in the
cache: Hit Ratio = 2,056 / 647 = 31.8%
12. Calculate the cache Hit Ratio using the formula presented in this chapter assuming that
the total number of requests is 78985 and 4029 of those requests are found in the cache.
Is this Hit Ration better or worse than the result of the previous exercise? ANS: 5.1%. It’s
worse than the 31% in the previous exercise because a higher hit ratio is better than a low
one.
13 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 that 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
Answers are shown in the table below:
Page Size Subroutine of 550 Subroutine 290 Subroutine 600 Total Wasted Memory
14. Using a paged memory allocation system with a page size of 2,048 bytes and an identical
page frame size, and assuming the incoming data file is 20,992, calculate how many
pages will be created by the file. Calculate the size of any resulting fragmentation.
Explain whether this situation will result in internal fragmentation, external
fragmentation, or both. ANS: 11 pages are used for this file because 20,992/2,048 =
10.25 pages. Resulting fragmentation will be 1,536 bytes (because it is 0.75 of a page:
UOS, 7e Ann McIver McHoes Chapter 3, Page 6
Understanding Operating Systems, 7th edition
0.75 * 2,048 = 1,536 bytes). All fragmentation will be internal because there is no
external fragmentation in a paged memory allocation system.
Advanced Exercises
15. Describe the logic you would use to detect thrashing. Once thrashing was detected,
explain the steps you would use so the operating system could stop it. ANS: While this
answer is not given in this chapter, it gives students an opportunity to speculate on this
particular aspect of system performance. Look for original conclusions here, which might
include: detecting low CPU use, longer disk access, a higher number of disk accesses per
job, etc. Once detected, there are several options including increasing the amount of
RAM, reducing the load, and others. Look for thoughtful analysis here.
16. Given that main memory is composed of four page frames for public use, use the
following table to answer all parts of this problem:
Time When Time When Last
Page Frame Loaded Referenced Referenced Bit Modified Bit
0 9 307 0 1
1 17 362 1 0
2 10 294 0 0
3 160 369 1 1
17. Explain how Page Frame 0 in the previous exercise can have a modified bit of 1 and a
referenced bit of 0. ANS: This seemingly impossible situation occurs because the
referenced bit, originally set to one, was reset to zero after the modification was made
and the modified bit was changed to one.
18. Given the following Segment Map Tables for two jobs:
SMT for Job 1
Segment Number Memory Location
0 4096
1 6144
2 9216
3 2048
4 7168
0 2048
1 6144
2 9216
a. Which segments, if any, are shared between the two jobs? ANS: Three segments are
shared by both jobs, those starting at locations: 2048, 6144 and 9216.
b. If the segment now located at 7168 is swapped out and later reloaded at 8192, and the
segment now at 2048 is swapped out and reloaded at 1024, what would the new
segment tables look like?
0 4096 0 1024
1 6144 1 6144
2 9216 2 9216
3 1024
4 8192
Programming Exercises
19. This problem studies the effect of changing page sizes in a demand paging system.
The following sequence of requests for program words is taken from a 460-word
program: 10, 11, 104, 170, 73, 309, 185, 245, 246, 434, 458, 364. Main memory can hold
a total of 200 words for this program and the page frame size will match the size of the
pages into which the program has been divided.
Calculate the page numbers according to the page size, divide by the page size, and the
quotient gives the page number. The number of page frames in memory is the total
number, 200, divided by the page size. For example, in problem (a) the page size is 100,
which means that requests 10 and 11 are on Page 0, and requests 104 and 170 are on Page
1. The number of page frames is two.
a. Find the success frequency for the request list using a FIFO replacement algorithm
and a page size of 100 words (there are two page frames).
FIFO with 200 words in main memory.
Page request 10 11 104 170 73 309 185 245 246 434 458 364
Page fault * * * * * *
Page Frame 1 P0 P0 P0 P0 P0 P3 P3 P3 P3 P4 P4 P4
Page Frame 2 P1 P1 P1 P1 P1 P2 P2 P2 P2 P3
460 words divided into 100 word pages require 5 pages
Page Number P0 P1 P2 P3 P4
Words 0–99 100–199 200–299 300–399 400–460
Success frequency = 6 /12 = 50%
b. Find the success frequency for the request list using a FIFO replacement algorithm
and a page size of 20 words (10 pages, 0 through 9).
FIFO with 200 words in main memory.
Page request 10 11 104 170 73 309 185 245 246 434 458 364
Page fault * * * * * * * * *
Page Frame 1 P0 P0 P0 P0 P0 P6 P6 P6 P6 P6 P6 P7
Page Frame 2 P2 P2 P2 P2 P2 P4 P4 P4 P4 P9
Page Frame 3 P3 P3 P3 P3 P3 P3 P8 P8 P8
Page Frame 4 P1 P1 P1 P1 P1 P1 P9 P4
460 words divided into 50 word pages require 10 pages
c. Find the success frequency for the request list using a FIFO replacement algorithm
and a page size of 200 words.
FIFO with 200 words in main memory.
Page request 10 11 104 170 73 309 185 245 246 434 458 364
Page fault * * * * * *
Page Frame 1 P0 P0 P0 P0 P0 P1 P0 P1 P1 P2 P2 P1
460 words divided into 200 word pages require 3 pages
Page Number P0 P1 P2
Words 0–199 200–399 400–460
Success frequency = 6 / 12 = 50%
d. What do your results indicate? Can you make any general statements about what
happens when page sizes are halved or doubled? ANS: For this example, as the page
size decreased the success frequency also decreased. Although it seems that there is a
direct relationship between halving the page size and halving the success frequency
(from 100 words and 50% to 50 words and 25%), this is not to be interpreted as a
general trend (notice the case from 100 words and 50% to 200 words and 50%).
Determining the optimum page size is a complicated operation which requires the
balancing of several competing factors.
e. Are there any overriding advantages in using smaller pages? What are the offsetting
factors? Remember that transferring 200 words of information takes less than twice as
long as transferring 100 words because of the way secondary storage devices operate
(the transfer rate is higher than the access [search/find] rate). ANS: One reason for
using small pages is to cut down on internal fragmentation. The extra space wasted in
the last page of each program averages to half a page (a quick way to approximate the
average waste is to multiply the number of page frames by the page size and divide
by 2). Another reason to use small pages is to cut down on the amount of unused code
resident in memory, optimizing the use of main memory and increasing
multiprogramming. On the other hand, small pages require larger page tables because
programs are divided into many sections. This means that the space occupied in main
memory by the page tables increases as the page size decreases. It also means that
more time is spent in managing and using the page tables. In addition, transfer of a
small page to and from disk takes almost as much as transferring a large page because
most of the time is spent on seeking and rotational delay. However, the number of
pages to be transferred has been increased causing the total transfer time to increase
as the size of the pages becomes small (this will become clearer after reading chapter
7).
f. Repeat (a) through (c) above, using a main memory of 400 words. The size of each
page frame will again correspond to the size of the page.
FIFO with 400 words in main memory.
Page request 10 11 104 170 73 309 185 245 246 434 458 364
Page fault * * * * *
Page Frame 1 P0 P0 P0 P0 P0 P0 P0 P0 P0 P4 P4 P4
Page Frame 2 P1 P1 P1 P1 P1 P1 P1 P1 P1 P1
Page Frame 3 P3 P3 P3 P3 P3 P3 P3
Page Frame 4 P2 P2 P2 P2 P2
Page Number P0 P1 P2 P3 P4
Words 0–99 100–199 200–299 300–399 400–460
Success frequency = 7 /12 = 58%
Page request 10 11 104 170 73 309 185 245 246 434 458 364
Page fault * * * * * * * * *
Page Frame 1 P0 P0 P0 P0 P0 P0 P0 P0 P0 P0 P0 P7
Page Frame 2 P2 P2 P2 P2 P2 P2 P2 P2 P2 P2
Page Frame 3 P3 P3 P3 P3 P3 P3 P3 P3 P3
Page Frame 4 P1 P1 P1 P1 P1 P1 P1 P1
Page Frame 5 P6 P6 P6 P6 P6 P6 P6
Page Frame 6 P4 P4 P4 P4 P4
Page Frame 7 P8 P8 P8
Page Frame 8 P9 P9
460 words divided into 50 word pages require 10 pages
Page request 10 11 104 170 73 309 185 245 246 434 458 369
Page fault * * *
Page Frame 1 P0 P0 P0 P0 P0 P0 P0 P0 P0 P2 P2 P2
Page Frame 2 P1 P1 P1 P1 P1 P1 P1
Page P0 P1 P2
Number
Words 0–199 200–399 400–460
Success frequency = 9 /12 = 75%
g. What happened when more memory was given to the program? Can you make some
general statements about this occurrence? What changes might you expect to see if
the request list was much longer, as it would be in real life? ANS: In this case
increasing the number of page frames seems to increase the success frequency
(especially in the first and last case). In general we could expect this to happen since
more page frames allow for more of the program to reside in main memory and this
increases the probability that an instruction will reference a location of the program
that is already in main memory (locality of reference).
If the page traces were longer the success frequencies would probably become closer
because the initial effect of filling up available page frames would be balanced by
long-term behavior.
h. Could this request list happen during the execution of a real program? Explain. ANS:
It is unlikely that this page trace would be found in real programs because real
programs tend to execute serially, often with loops, which tend to confine their page
traces to the same set of pages for much longer than in the case presented in this
exercise.
i. Would you expect the success rate of an actual program under similar conditions to
be higher or lower than the one in this problem? ANS: It would be reasonable to
expect an improvement on the success frequency of an actual program because of its
serial execution.
20. Given the following information for an assembly language program:
Job size = 3126 bytes
Page size = 1024 bytes
instruction at memory location 532: Load 1, 2098
a. How many pages are needed to store the entire job? ANS: Three pages: Page 0, Page
1 and Page 2 (3126/1042=3).
b. Compute the page number and displacement for each of the byte addresses where the
data is stored. (Remember that page numbering starts at zero). ANS: (Remember that
page numbering starts at zero).
Memory location 1052 = Page 1, displacement 10.
Memory location 2098 = Page 2, displacement 14.
Memory location 4087 = Page 3, displacement 961.
c. Determine whether the page number and displacements are legal for this job. ANS:
The first two pages (Page 1 and Page 2) and their displacement are legal for this job.
The third page (Page 3) is not legal.
d. Explain why the page number and/or displacements may not be legal for this job.
ANS: The job size is only 3126 bytes therefore memory location 4087 is not within
its boundaries. In this case the quotient is 3, meaning Page 3, which is not part of this
job's page set. The displacement, 961, is legal since the page size is 1042 bytes.
e. Indicate what action the operating system might take when a page number or
displacement is not legal. ANS: The operating system would issue an error message
to indicate that access to out of bounds memory had been attempted, stating the
program instruction, or memory location, at which the problem had occurred. The job
would be terminated.