CS139-lecture-20211116

Memory cont. #

Fragmentation #

image_2021-11-16-13-36-13 image_2021-11-16-13-37-56 image_2021-11-16-13-39-50

The small 2B chunk will never be able to be used, and the sum of all of these small gaps in memory is wasted, called internal fragmentation.

Compaction #

image_2021-11-16-13-40-29

  • compaction is expensive to invoke

Swapping #

image_2021-11-16-13-42-37 image_2021-11-16-13-42-47

Segmentation #

One of the methods of implementing non-contiguous memory is segmentation.

image_2021-11-16-13-42-59 image_2021-11-16-13-43-44 image_2021-11-16-13-44-09 image_2021-11-16-13-47-01 image_2021-11-16-13-49-09

  • an address may be something like <3, 14>, which represents segment 3 with a 14 byte offset
  • another table keeps track of the segment’s addresses and lengths

image_2021-11-16-13-52-20 image_2021-11-16-13-52-37

Paging #

image_2021-11-16-13-54-22 image_2021-11-16-13-54-27

  • similar to segmentation, except that everything is divided into equal size blocks

image_2021-11-16-13-56-12 image_2021-11-16-13-56-17

Addressing #

image_2021-11-16-13-56-22 image_2021-11-16-14-00-13 image_2021-11-16-14-00-19 image_2021-11-16-14-00-25 image_2021-11-16-14-02-48 image_2021-11-16-14-06-20 image_2021-11-16-14-08-32

VPN = “virtual page number”, PFN = “physical frame number”

Paging hardware #

image_2021-11-16-14-09-03 image_2021-11-16-14-09-08 image_2021-11-16-14-09-13 image_2021-11-16-14-09-18 image_2021-11-16-14-09-58

  • paging suffers internal fragmentation
  • paging solves external fragmentation

image_2021-11-16-14-16-23 image_2021-11-16-14-16-29 image_2021-11-16-14-16-35

  • D is the dirty bit, which indicates “write needs to be updated on disk”
  • A is access bit, indicates if the page has been recently accessed
  • R/W is protection bit, indicates read or write permission
  • P is the valid/invalid bit, the “present” bit

Paging problems #

image_2021-11-16-14-21-06

  • where do we store the page table itself? in memory

image_2021-11-16-14-21-18 image_2021-11-16-14-24-29

The TLB is the “translation lookaside buffer”. MMU is part of the CPU suite.

image_2021-11-16-14-26-21

TLB Hit

  • 1 TLB lookup
  • 1 mem access (load/store)

TLB Miss

  • 1 TLB lookup (miss)
  • 1 mem access(page table lookup)
  • 1 TLB update
  • 1 mem access (load/store)

We want a high TLB hit rate.

image_2021-11-16-14-30-36 image_2021-11-16-14-36-48

Effective access time #

image_2021-11-16-14-36-58

Structure of a page table #

image_2021-11-16-14-39-39 image_2021-11-16-14-43-38