Docsity

Computer Organization and Design: Memory, Slides of Operating Systems

Partial preview of the text

Download Computer Organization and Design: Memory and more Slides Operating Systems in PDF only on Docsity!

CIS 571

Computer Organization and Design

Unit 9: Memory

Slides developed by Benedict Brown, Milo Martin, Amir Roth & C.J. Taylor at the University of Pennsylvania with sources that included University of Wisconsin slides by Mark Hill, Guri Sohi, Jim Smith, and David Wood.

This Unit: Memory

  • DRAM
  • The operating system (OS)
    • A super-application
    • Hardware support for an OS
  • Virtual memory
    • Page tables and address translation
    • TLBs and memory hierarchy issues
  • Virtual Machines Mem CPU I/O System software App App App

DRAM

DRAM cells

  • 1 transistor and 1 capacitor per bit
    • contrast with SRAM: 6 transistors per bit
    • bit value is recorded as charge on the capacitor
    • charge dissipates over time, requires periodic refresh c/o Patterson & Hennessy, COD, Appendix C

A Computer System: Hardware

  • CPUs and memories
    • Connected by memory bus
  • I/O peripherals : storage, input, display, network, …
    • With separate or built-in DMA
    • Connected by system bus (which is connected to memory bus) Memory Disk kbd

DMA DMA

display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$

A Computer System: + App Software

  • Application process : the work we want to do
    • everything else is in support of this Memory Disk kbd

DMA DMA

display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ Application process

A Computer System: + OS

Memory Disk kbd

DMA DMA

display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ OS Process Process Process Process

A Computer System: + OS

  • Operating System (OS): virtualizes hardware for processes
    • Abstraction : provides services (e.g., threads, files, etc.)
      • Simplifies application programming model, raw hardware is nasty
    • Isolation : gives each process illusion of private CPU, memory, I/O
      • Simplifies application programming model
      • Increases hardware resource utilization Memory Disk kbd

DMA DMA

display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ OS Process Process Process Process

Multitasking: virtualizing a processor

  • When multiple applications are being run on the same

core, the OS shares the computer between them

  • Multitasking dates back to the early days of computers when systems were expensive and we needed to be able to support multiple users concurrently.
  • The OS needs to be able to switch between different

processes. In most cases it does this so quickly that

users/processes don’t realize the machine is being shared.

  • The act of switching between processes is referred to as a

context switch

  • what state is involved?

When do we perform a context switch?

  • Hardware timer ensures each process gets fair access to

the CPU

  • When do we switch?
    • when the timer goes off (e.g., every 2ms)
    • At system calls because they are usually slow
      • we want to do something else useful in the meantime, so switch to another process and run it instead

Virtualizing Main Memory

  • How do multiple procs (and the OS) share main memory?
    • Goal: each application thinks it has all of the memory
  • One process may want more memory than is in the system
    • Process insn/data footprint may be larger than main memory
    • Requires main memory to act like a cache
      • With disk as next level in memory hierarchy (slow)
      • Write-back, write-allocate, large blocks or “pages”
    • No notion of “program not fitting” in registers or caches (why?)
  • Solution:
    • Part #1: treat memory as a “cache”
      • Store the overflowed blocks in “swap” space on disk
    • Part #2: add a level of indirection (address translation)

Virtual Memory (VM)

  • Virtual Memory (VM) :
    • Level of indirection
    • Application generated addresses are virtual addresses (VAs)
      • Each process thinks it has its own 2 N bytes of address space
    • Memory accessed using physical addresses (PAs)
    • VAs translated to PAs at coarse (page) granularity
    • OS controls VA to PA mapping for itself and all other processes
    • Logically: translation performed before every insn fetch, load, store
    • Physically: hardware acceleration removes translation overhead …

OS

App … App VAs PAs (physical memory) OS controlled VA®PA mappings

VM is an Old Idea: Older than Caches

  • Original motivation: single-program compatibility
    • IBM System 370, in 1972
    • Same program could run on machines with different memory sizes
    • Prior, programmers explicitly accounted for memory size
  • But also: full-associativity + software replacement
    • Memory tmiss is high: extremely important to reduce %miss Parameter I$/D$ L2 Main Memory thit 2ns 10ns 30ns tmiss 10ns 30ns 10ms (10M ns) Capacity 8 – 64KB 128KB–2MB 64MB–64GB Block size 16 – 32B 32 – 256B 4+KB Assoc./Repl. 1 – 4, LRU 4 – 16, LRU Full, “working set”

Uses of Virtual Memory

  • More recently: isolation and multi-programming
    • Each app thinks it has 2 N B of memory, its stack starts 0xFFFFFFFF,…
    • Apps prevented from reading/writing each other’s memory
      • Can’t even address the other program’s memory!
  • Protection
    • Each page with a read/write/execute permission set by OS
    • Enforced by hardware
  • Inter-process communication.
    • Map same physical pages into multiple virtual address spaces
    • Or share files via the UNIX mmap() call …

OS

App … App