# 存储系统原理
# 存储系统分类
存储系统包括:
- cache 存储系统
- 包括 cache 和主存
- 目的是提高存储器速度
- 虚拟存储系统
- 包括主存和硬盘 (辅存)
- 目的是扩大存储器容量
# 存储系统层次结构
- 通用寄存器
- 高速缓存
- 主存储器
- 辅存储器
- 脱机大容量存储器
# 存储系统的速度
若 是命中率,则访问周期为 . , 则 .
存储系统的访问效率定义为
# 虚拟存储器
虚拟存储器的管理方式有三种:
- 段式管理
- 页式管理
- 段页式管理
# 页面替换算法
# LRU 算法
LRU (least recently used) 算法伪代码如下:
# LRU code | |
# defining the table size | |
table_size = 3 | |
reference_string = [0, 1, 2, 3, 0, 1, 4, 0, 1, 2, 3, 4] | |
# the list which stores the current pages in memory | |
# and where page replacement is executed. | |
pages = [] | |
# page faults | |
faults = 0 | |
# iterating through the ref string | |
for page in reference_string: | |
# check if page already exists in the list, | |
# if yes, we just remove the page and append it | |
# to the end of the list (last index). | |
if page in pages: | |
# removing | |
pages.remove(page) | |
# appending | |
pages.append(page) | |
# if page is not there | |
else: | |
# we first check length of page list. | |
# if still spots left in the list, we first fill it | |
if(len(pages) < table_size): | |
pages.append(page) | |
else: | |
# if the page list is filled. We remove the | |
# first page. | |
pages.remove(pages[0]) | |
# and then we append page to the end of list. | |
pages.append(page) | |
# Increment 1 in Page faults | |
faults +=1 | |
print("total page faults = ", faults) |