Salta al contenuto
Note per Studenti Virtual Memory and Paging Report

Virtual Memory and Paging

In questa pagina 3

Besides being fast (Memory Hierarchy and Cache MemoryMemories form a hierarchy (small fast SRAM, larger slower DRAM, huge slow disks) which works because programs reuse data close in time and in space (locality). A cache hit or miss gives an average access time t_hit plus miss rate times miss penalty; placement can be direct mapped (index = low address bits, tag = high bits), fully associative (tag = whole address, compared in parallel by an associative memory) or k-way set associative (a block can sit in k locations of one set).Memory Hierarchy and Cache Memory →), the available memory must be large. Virtual memory shows every program the full size of main memory and disk: programs can use the same addresses without interfering. A dedicated hardware unit, the memory management unit (MMU), performs the mapping between virtual and physical memory, ensuring process separation. Management is simplified by splitting memory into pages.

Page table

Definition (page table). The mapping between virtual pages and physical pages is held in the page table. Each row contains, besides the physical page number (frame):

  • valid: if 00, the page does not correspond to real code or data in memory;
  • dirty: if 11, at least one write occurred (the page must be copied to disk before being replaced);
  • used: supports page replacement.

Translation example. 4 KB pages: the 16-bit virtual address splits into the page number (4 high bits) and the offset (12 bits); translation replaces the page number with the frame and leaves the offset unchanged. Table: page 0 →\to frame 2 (valid); page 1 not valid; page 2 →\to frame 7 (valid, dirty); page 3 →\to frame 5 (valid).

virtual address page offset outcome physical address
0x0010 0 0x010 valid, frame 2 0x2010
0x3A7C 3 0xA7C valid, frame 5 0x5A7C
0x2400 2 0x400 valid, frame 7 0x7400
0x1FFF 1 0xFFF page fault (from disk)

Two-level tables, TLB and page fault

With a two-level structure (directory and page table) fetching a datum takes three memory accesses: the directory entry, the page table entry and finally the operand or instruction: too slow. The Translation Lookaside Buffer (TLB) is a cache for the virtual-to-physical mapping: it holds the translations of the most recently used pages and, if the page is there, translation is immediate.

Definition (page fault). A page fault occurs when the requested page is not in memory (valid bit 0): it must be fetched from disk, which takes enormously longer than a DRAM access, so the operating system handles the fault and replaces a page (saving it first if dirty).

Example. With the table above, an access to page 11 (valid =0=0) causes a page fault: the page must be loaded from disk.

Common mistakes

  • Forgetting that the offset does not change in the virtual-to-physical translation.
  • Treating a cache miss and a page fault as equivalent: the first is served by main memory, the second by disk.

Versione ripasso

Teoria collegata