Docsity

Memory Management: Paging and Virtual Memory - Prof. Michael W. Hicks, Study notes of Operating Systems

Partial preview of the text

Download Memory Management: Paging and Virtual Memory - Prof. Michael W. Hicks and more Study notes Operating Systems in PDF only on Docsity!

CMSC 412

Memory Management: Paging and Virtual Memory

Announcements

  • Reading:
    • Today: Chapter 8.2-8.
    • Next time: Chapter 8.5-8.7, 9

Announcements

  • AWC 400 Level Lecture Series (400 LLS)
  • AVW 3258 Oct 18, 19, 20 5- 6:30 pm
  • FREE PIZZA!
  • Professors who will be teaching 400 level classes this spring will be speaking for 10-15 minutes about the class they will be teaching and how they will run the class. This is a great way to find out information about the course from the Professor who will be teaching it.

Logical vs. Physical Addresses

  • The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. - Logical address – generated by the CPU; also referred to as virtual address. - Physical address – address seen by the memory unit.

Schematic View of Swapping

Contiguous Allocation

  • Main memory usually into two partitions: - Resident operating system, usually held in low memory with interrupt vector. - User processes then held in high memory.
  • Single-partition allocation
    • Subdivide user-space into fixed-size chunks of memory. Each process gets a full chunk. - What if the process doesn’t need that much? - What if it needs more?

Contiguous Allocation

  • Multiple-partition allocation
    • Hole – block of available memory; holes of various size are scattered throughout memory.
    • When a process arrives, it is allocated memory from a hole large enough to accommodate it.
    • Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

Dynamic Storage-Allocation

Problem

  • How to satisfy a request of size n from a list of free holes?
  • Goal: efficient utilization of storage.
    • If we have n processes that require m bytes of memory where m < n , we can fit all processes in memory at once.
  • Goal: fast allocation times.
    • The time to find a hole of necessary size

Reducing Fragmentation

  • Compaction
    • Shuffle memory contents to place all free memory together in one large block.
  • Compaction is possible only if using relocatable logical addresses.
  • I/O problem
    • Pin job in memory while it is doing I/O.
    • Or, do I/O only into (non-relocatable) OS buffers.

Non-Contiguous Allocation

  • Can eliminate external fragmentation and improve storage utilization by allowing process memory to be non- contiguous. - Break the process memory into different chunks and allocate chunks in different parts of physical memory.

Segmentation

  • Programs tend to be divided into different parts - Code - Data - Heap - Stack
  • They can reside in separate segments that may be non-contiguous in physical memory.

Logical View of Segmentation

1 3 2 4 1 4 2 3 user space physical memory space

Example of Segmentation

Paging

  • Divide physical memory into fixed sized chunks called frames (pages), logical memory into same-sized pages - typical frames are 512 bytes to 64 Kbytes - When a process is to be executed, load the pages that are needed into memory.
  • Have a map from pages to frames
    • Called the page table.

Address Translation Scheme

  • Address generated by CPU is divided into:
    • Page number (p) – used as an index into the page table, which contains base address of each page in physical memory.
    • Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit.
  • Consider 32-bit addresses on Pentium:
    • 4096-byte pages (12 bits for the offset)
    • 20 bits for the page number

Address Translation

Paging Fragmentation

  • If we have 4K pages, and a process requires 15K of memory, how many pages will we need?
  • Suffer from internal fragmentation : last page likely not completely used - On average 50% of a page lost per process to internal fragmentation
  • How does this impact our choice of page size?

Implementation of Page Table

  • Page table is kept in main memory.
  • Page-table base register ( PTBR) points to the page table.

Memory Protection

  • Memory protection by associating protection bit with each frame.
  • Valid-invalid bit attached to each entry in the page table: - “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal page. - “invalid” indicates that the page is not in the process’ logical address space.

Valid/Invalid Bit Example

Two-Level Paging Example

  • A logical address (on 32-bit machine with 4K page size) is divided into: - a page number consisting of 20 bits. - a page offset consisting of 12 bits.
  • Since the page table is paged, the page number is further divided into: - a 10-bit page number. - a 10-bit page offset.

Two-Level Paging Example

  • Thus, a logical address is as follows: where p 1 is an index into the outer page table, and p 2 is the displacement within the page of the outer page table. page number (^) page offset pi p 2 d 10 10 12

Address-Translation Scheme

  • Address-translation scheme for a two-level 32-bit paging architecture

Problem: Still too big?

  • What about 64 bit address spaces?
  • Two-level page table:
    • Page num: 52 bits, or 2^52 entries in page directory!
  • More levels of hierarchy?
    • Further subdivide the page number.
      • 32-bit SPARC: three-level scheme.
      • 32-bit 68030: four-level scheme
  • Try something different …

Inverted Page Table

  • One entry for each real page of memory.
  • Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page.
  • Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs.
  • Use hash table to limit the search to one — or at most a few — page-table entries.

Inverted Page Table

Architecture

Problem: Address Lookup

  • Every data/instruction access requires many memory accesses. At the least, one for the page table and one for the data/instruction.
  • The two memory access problem can be solved by the use of a special fast- lookup hardware cache called associative memory or translation look-aside buffers (TLBs) - typically 16- 64 entries

Paging Hardware With TLB