系统级程序设计笔记(6)

Memory Operation and Performance


前言

本篇博客整理了系统级程序设计课程中的lecture7.

相关材料见:SLP-Notes

待更新

  • Locality: Code Examples
  • Caches
    • Terms
    • Why Use Middle Bits as Index?

Memory Systems

Memory Technology

  • Categories
    • Static Random Access Memory(SRAM)
    • Dynamic Random Access Memory(DRAM)
    • Magnetic disks
    • Magnetic tapes
    • Optical disks
  • Computers use memory technologies of varying size and speed to achieve both acceptable speed and size at an affordable cost.

  • Access Time: SRAM < DRAM < Mag Disks

    Cost: SRAM > DRAM > Mag Disks

  • [简答题]

    This scheme of taking advantage of several memory technologies to get both speed and size is called a memory hierarchy.

  • 如下图

    1

    1

Locality of Reference

The immediate future will be similar to the immediate past and that memory addresses that have been accessed recently are likely to be accessed again.

  • Spatial and Temporal Locality
    • References to a single address occurclose together in time (this is calledtemporal locality).
    • References to addresses that are nearto each other occur together in time(this is called spatial locality).
  • It is a property of programs, not of computers.

    Program’s locality is a property of the program’s behavior, and not of the computer.

  • Code Examples

Memory Hierarchies

  • Typical computer designs have at least four levels in the hierarchy.
    • Registers are closest to the CPU, are smallestin size, and are also the fastest memory in thesystem

    • Furthest from the CPU is the disk, where largeinactive parts of programs sleep for long periods of time

    • In between: caches & main memory

      • The policy decisions for these levels are made as the program executes.

      • The computer has special cache hardware that moves data from memory to cachesand vice versa。

    1

  • [简答题] Design of Hierarchy: Strategies

    1

  • Memory Hierarchy

    1


Caches

Special Terms

  • Cache lines

  • Cache Hits
  • Cache Misses
    • Cold Misses (Compulsory Misses)
    • Conflict Misses
    • Capacity Misses
  • C = B X E X S

Direct-Mapped Cache

  • Set Selection

    Line Matching

    Word Extraction

  • Example

    教材P429-432

  • Why Use Middle Bits as Index?

    教材P432

Associative Cache

  • Set Associative Cache
  • Fully Associative Cache

教材P435 练习6.12-6.15

Cache-aware Programming

  • Example

    教材P441-444

  • Matrix Multiply

    教材P448-449


Virtual Memory

基本概念

1

  • 为什么要引入虚拟内存?

    教材P559

  • 虚拟内存的作用

    教材P559

物理和虚拟地址

VA -> MMU -> PA

  • 物理地址与虚拟地址
  • 虚拟寻址
  • 地址翻译
  • 内存管理单元

虚拟内存作为缓存的工具

  • 虚拟页与物理页
  • 页帧
  • 三种虚拟页面
    • 未分配的
    • 缓存的
    • 未缓存的
  • 页表
    • 存放在物理内存中
    • 将虚拟页映射到物理页
  • 页命中与缺页
    • 页命中
    • 缺页:交换 / 页面调度
  • 局部性

虚拟内存作为内存管理的工具

虚拟内存作为内存保护的工具