previous
 next 
CS 3733 Operating Systems Notes: Paging
(change semester)

The method of choice on most systems is paging: programs do not have to be loaded contiguously.

  1. Physical memory is divided into fixed-size blocks called frames.
  2. The logical memory of the programs is broken into fixed-size blocks called pages.
  3. The system keeps a list of frames that are not currently being used, called the free frame list.
  4. Initially, all frames are free.
  5. The page size = frame size is always a power of 2.
    Page sizes are typically 1-16K bytes.
  6. A logical address generated by the CPU is divided into a page number (p) and a page offset (d).
               total bits:  p + d
            -------------------------------------
           | page number: p bits  |offset: d bits|
            -------------------------------------
    
  7. If the offset has d bits, the page size is 2d.
  8. If the page number has p bits, the number of pages is 2p.
  9. The maximum size of a process is 2p+d bytes.
  10. The physical address used by the memory system is divided into a frame number and an offset.
               total bits:  f + d
        -----------------------------------------
       |    frame number: f bits  |offset: d bits|
        -----------------------------------------
    
  11. If the frame number has f bits, the number of frames is 2f.
  12. The total amount of physical memory supported by the system is 2f+d bytes.
  13. Address translation is done by mapping a page number into a frame number.
  14. Each process has a page table which is a list a frames used by that process.
  15. The page number is used as an index into the page table, giving the page table entry which contains the frame number of the actual page in memory.
  16. You can think of the page table as an array, pt, where pt[page_number] = frame number.

    Paging Example 1

    Paging Example 1: If the page size is 1K, a physical address has 32 bits, and a logical address has 28 bits:
    1. What is the maximum size (in bytes) of a process?
    2. How many bits are in the offset field of an address?
    3. How many entries does a page table for one process have?
    4. How many bytes does a page table entry require?
    5. How many maximum size processes can fit in the maximum amount of memory?
  17. The page offset gives the position within the page. If the page size is 2d, the offset will be d bits long.
  18. When a process enters the system, the required number of frames is allocated to the process from the free frame list.
    These are entered into page table of the process.
  19. There is no external fragmentation (pieces of physical memory too small to use).
  20. There is a small amount of internal fragmentation because frames are allocated as units.

Look at the paging hardware figure from the book.

Look at Paging Exercise 1
Paging Exercise 1


The implementation of paging is as follows:


Example:
Suppose: Calculate the effective memory access time with and without the TLB.


Note: there are two ways of implementing the TLB.
TLB lookup can be done in series with page table lookup or in parallel to it.

Example:
Redo the previous example if the TLB hit ratio is 95%.

Typical TLB hit ratios of 99% or higher are not uncommon, even when the TLB is relatively small.

Look at Paging Exercise 2
Paging Exercise 2


One of the advantages of paging is that each process has its own page table and so logical addresses for each process can begin at 0.
This allows relocation to be done by changing the page table.
It also provides automatic protection of one program from another, but allows for sharing of memory between processes.

Questions:
  1. How would you expect the number of pages and the number of frames to be related?
  2. If the logical address is 30 bits and the page size is 4K, approximate the number of bytes in the page table for a given process.
  3. If a logical address is 30 bits, a physical address is 32 bits, and the page size is 4K, estimate the fraction of memory that would be taken up by page tables.
  4. Aside from copying bits, what arithmetic operations does the MMU do during an address translation?
  5. Compare the time it takes to do a page translation using partitions and using paging.
  6. How would an operating system implement shared memory if partitions were used?
  7. How would an operating system implement shared memory if a paging system were used?

Paging Questions

Next Notes

Back to CS 3733 Notes Table of Contents