zoukankan      html  css  js  c++  java
  • Memory hierarchy

    • main memory :DRAM dynamic Random Access Memory
    • cache : SRAM static Random Access Memory
    • Magnetic disk

    why hierarchy works?
    two reasons:

    • temporal locality:90%的时间实际上在执行10%的代码。
    • spatial locality:比如说arry/pc指令都是挨着执行的。

    memory hierarchy

    • registers->cache by compiler
    • cache->memory by hardware
    • memory -> disk by hardware and OS(virtual memory) and by programmer(files)

    cache -> Memory,在这个过程中要解决以下几个问题:
    1、block placement
    2、finding a block
    3、replacement on a miss
    4、write policy

    cache -> memory是怎么映射的呢?
    映射的基本单位是block.从memory搬进搬出的基本单位是block。
    方法一: direct-mapped cache

    假设cache的容量是8,block是1个byte.memory的容量是32.那么cache可以向memory映射,分为4个映射空间,也就是说橘红色的地方可以向memory的四个地方映射。那么cache里面除了要保存从memory里面拿出来的data以外,还要告诉我是橘红色的部分是从哪个memory的位置映射来的(也就是TAG信息)。
    还需要1bit的valid bit信息,告诉我cache里面是不是有data从memory过来。
    need 3bit address to find location in cache. no compare

    第二种:set-associative

    就相当于cache size进行分组,for example(还是以上个例子):
    fully-associative的情况,memory的一个位置只能map到对应的cache的一个位置,但是two-way set associate就可以将memory的一个位置只能map到对应的cache的两个位置
    need 2bit address and 2 compare to find location in cache.

    第三种:fully-associative

    for example(还是以上个例子):
    memory的一个位置能map到对应的cache的任意一个位置.

    no need address but need 8 compare to find location in cache.

    data replacement policy:

    • random
    • LRU(least recently used)

    read hit and miss:

    • on cache hit,normally
    • on cache miss:stall the CPU pipeline,and fetch block from next level of hierarchy

    write hit and miss:

    • write hit
      1、 write through updata the block in cache and also update memory. It will take a long time.能够永远维持cache的一致性。但是会在memory一段制造很多traffic。
      2、 write back hold data waiting to be written to memory,only stall on write if write buffer is already full. dirty bit = 1的时候表示的是要写到memory里面。dirty bit = 0的时候表示cache和memory是一样的copy。

    write miss

    • write back,从memory里面搬到cache里面。
    • write through,第一种:直接写到memory里面。第二种:allocate fetch the block。

    multilevel cache :
    L1- cache
    L2 -cache
    L3-cache

    a. 一个wrod access memory,一个wrod bus tranfer
    b. 四个word access memory, 四个word bus transfer
    c. 四个word access memory,一个word bus transfer(主要应用)

    access of DRAM:

    row + column

    sources of misses

    • compulsory misses(aka code start misses):first access to a block
    • capacity misses:cache的容量有限
    • conflict misses(aka collision misses):发生在non-fully associate cache
  • 相关阅读:
    你可能不知道的css-doodle
    js变量提升与函数提升的详细过程
    绑定Github上的个人博客到Godaddy域名
    基于Github&Hexo的个人博客搭建过程
    github提交代码contributions不显示小绿块
    从零开始学 Web 系列教程
    从零开始学 Web 之 Vue.js(六)Vue的组件
    从零开始学 Web 之 Vue.js(五)Vue的动画
    从零开始学 Web 之 Vue.js(四)Vue的Ajax请求和跨域
    CSS(二)- 选择器
  • 原文地址:https://www.cnblogs.com/xuqing125/p/15662278.html
Copyright © 2011-2022 走看看