Operating Systems 1; Year 2003/04



Solutions of Exercises #13: Memory Management


Problems of OSC

Problem 9.2

Explain the difference between internal and external fragmentation.

Answer Internal Fragmentation is the area in a region or a page that is not used by the job occupying that region or page. This space is unavailable for use by the system until that job is finished and the page or region is released.

Problem 9.3

Describe the following allocation algorithms:

  1. First fit
  2. Best fit
  3. Worst fit

Answer

  1. First-fit: search the list of available memory and allocate the first block that is big enough.
  2. Best-fit: search the entire list of available memory and allocate the smallest block that is big enough.
  3. Worst-fit: search the entire list of available memory and allocate the largest block. (The justification for this scheme is that the leftover block produced would be larger and potentially more useful than that produced by the best-fit approach.)

Problem 9.5

Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K, and 426K (in order)? Which algorithm makes the most efficient use of memory?

Answer

  1. First-fit:
    1. 212K is put in 500K partition
    2. 417K is put in 600K partition
    3. 112K is put in 288K partition (new partition 288K = 500K - 212K)
    4. 426K must wait
  2. Best-fit:
    1. 212K is put in 300K partition
    2. 417K is put in 500K partition
    3. 112K is put in 200K partition
    4. 426K is put in 600K partition
  3. Worst-fit:
    1. 212K is put in 600K partition
    2. 417K is put in 500K partition
    3. 112K is put in 388K partition
    4. 426K must wait
In this example, Best-fit turns out to be the best.

Problem 9.7

Why are page sizes always powers of 2?

Answer Recall that paging is implemented by breaking up an address into a page and offset number. It is most efficient to break the address into X page bits and Y offset bits, rather than perform arithmetic on the address to calculate the page number and offset. Because each bit position represents a power of 2, splitting an address between bits results in a page size that is a power of 2.

Problem 9.8

Consider a logical address space of eight pages of 1024 words each, mapped onto a physical memory of 32 frames.

  1. How many bits are there in the logical address?
  2. How many bits are there in the physical address?

Answer

  1. Logical address : 13 bits
  2. Physical address : 15 bits

Problem 9.9
On a system with paging, a process cannot access memory that it does not own; why? How could the operating system allow access to other memory? Why should it or should it not?

Answer
An address on a paging system is a logical page number and an offset. The physical page is found by searching a table based on the logical page number to produce a physical page number. Because the operating system controls the contents of this table, it can limit a process to accessing only those physical pages allocated to the process. There is no way for a process to refer to a page it does not own because the page will not be in the page table. To allow such access, an operating system simply needs to allow entries for non-process memory to be added to the process s page table. This is useful when two or more processes need to exchange data they just read and write to the same physical addresses (which may be at varying logical addresses). This makes for very efficient interprocess communication.

Problem 9.10
Consider a paging system with the page table stored in memory.

  1. If a memory reference takes 200 nanoseconds, how long does a paged memory reference take?
  2. If we add associative registers, and 75 percent of all page-table references are found in the associative registers, what is the effective memory reference time? (Assume that finding a page-table entry in the associative registers takes zero time, if the entry is there.)
Answer
  1. 400 nanoseconds; 200 nanoseconds to access the page table and 200 nanoseconds to access the word in memory.
  2. Effective access time = 0.75 * (200 nanoseconds) + 0.25 * (400 nanoseconds) = 250 nanoseconds.

Problem 9.11
What is the effect of allowing two entries in a page table to point to the same page frame in memory? Explain how this effect could be used to decrease the amount of time needed to copy a large amount of memory from one place to another. What effect would updating some byte on the one page have on the other page

Answer: By allowing two entries in a page table to point to the same page frame in memory, users can share code and data. If the code is reentrant, much memory space can be saved through the shared use of large programs such as text editors, compilers,and database systems. "Copying" large amounts of memory could be effected by having dif- ferent page tables point to the same memory location.
However, sharing of nonreentrant code or data means that any user having access to the code can modify it and these modifications would be reflected in the other user's "copy."

Problem 9.12
Why segmentation and paging sometimes combined into one scheme?

Answer:
Segmentation and paging are often combined in order to improve upon each other. Segmented paging is helpful when the page table becomes very large. A large contiguous section of the page table that is unused can be collapsed into a single segment table entry with a page table address of zero. Pages segmentation handles the case of having very long segments that require a lot of time for allocation. By paging the segments, we reduce wasted memory due to external fragmentation as well as simplify the allocation.

Problem 9.13
Describe a mechanism by which one segment could belong to the address space of two different processes.

Answer:
Since segment tables are a collection of base-limit registers, segments can be shared when entries in the segment table of two different jobs point to the same physical location. The two segment tables must have identical base pointers and the shared segment number must be the same in the two processes.

Problem 9.14
Explain why it is easier to share a reentrant module using segmentation than it is to do so when pure paging is used.

Answer:
Since segmentation is based on a logical division of memory rather that a physical one, segments of any size can be shared with only one entry in the segment tables of each user. With paging there must be a common entry in the page tables for each page that is shared.

Problem 9.16
Consider the following segment table:
Segment
Base 
Length
0
219
600
1
2300
14
2
90
100
3
1327
580
4
1952
96

What are the physical addresses for the following logical addresses?

a.  0,430
b.  1,10
c.  2,500
d.  3,400
e.  4,112

Answer:
a.  219 + 430 = 649
b.  2300 + 10 = 2310
d.  illegal reference, trap to operating system
d.  1327 + 400 = 1727
e.  illegal reference, trap to operating system

Problem 9.17
Consider the Intel address translation scheme shown in Figure 9.20 in OSC (page 292).

  1. Describe all the steps that are taken by the Intel 80386 in translating a logical address into a physical address.
  2. What are the advantages to the operating system of hardware that provide such complicated memory translation hardware?
  3. Are there any disadvantages to this address translation system?

Answer:
a.   The selector is an index into the segment descriptor table. The segment descriptor result plus the original offset is used to produce a linear address with a dir, page, and offset. The dir is an index into a page directory. The entry from the page directory selects the page table, and de page field is an index into the page table. The entry from the page table, plus the offset, is the physical address.

b.   Such a page translation mechanism offers the flexibility to allow most operating system to implement their memory scheme in hardware, instead of having to implement some parts in hardware and some in software. Because it can be done in hardware it is more efficient (and the kernel is simpler).

c.   Address translation can take longer due to the multiple table lookups it can invoke. Caches help, but there will still be cache misses.

-->


Franz Meyer

Last modified: Sun Mar 28 20:46:26 MEST 2004