操作系统复习六

本文探讨了程序如何从磁盘加载到内存并转化为进程,强调了内存管理和地址绑定的重要性。通过基数和极限寄存器实现内存保护,确保用户模式下的内存访问在指定范围内。介绍了分页机制,允许进程的物理地址空间不连续,并详细阐述了地址转换的过程,包括页号、页偏移量的计算以及页表和TLB的作用。同时,提到了不同内存分配策略如首次适应、最佳适应和最差适应。最后,讨论了有效访问时间和TLB在提高内存访问效率上的贡献。
摘要由CSDN通过智能技术生成

Background:
Program must be brought (from disk) into memory and
placed within a process for it to be run
◼ Main memory and registers are only storage CPU can
access directly
◼ Memory unit only sees a stream of addresses + read
requests, or address + data and write requests
◼ Register access in one CPU clock (or less)
◼ Main memory can take many cycles, causing a stall
◼ Cache sits between main memory and CPU registers
◼ Protection of memory required to ensure correct operation

From Program To Process
在这里插入图片描述
Base and Limit Registers:
◼ A pair of base and limit registers
define the logical address space 一对基数和极限寄存器 定义逻辑地址空间
◼ CPU must check every memory
access generated in user mode to
be sure it is between base and limit
for that user CPU必须检查每一个在用户模式下产生的内存访问的 访问,以确保它在基数和极限之间。 确定它是在基数和极限之间。
◼ Base register contains value of
smallest physical address 基准寄存器包含最小物理地址的值
◼ Limit register contains range of
logical addresses – each logical
address must be less than the limit
register 限制寄存器包含逻辑地址的范围 逻辑地址范围 - 每个逻辑 地址必须小于极限 寄存器

在这里插入图片描述

Address Binding
◼ Programs on disk, ready to be brought into memory to execute form
an input queue磁盘上的程序,准备带入内存执行,形成一个输入队列
⚫Without support, must be loaded into address 0000
如果没有支持,必须载入地址0000
◼ Inconvenient to have first user process physical address always at 0000
不方便让第一个用户进程的物理地址总是在0000。
◼ Further, addresses represented in different ways at different stages of a program’s life
此外,在程序的不同阶段,地址以不同的方式表示。
⚫ Source code addresses usually symbolic
源代码地址通常是符号性的
⚫ Compiled code addresses bind to relocatable addresses  i.e. “14 bytes from beginning of this module”
编译后的代码地址与可重定位的地址绑定,即 “从本模块开始的14字节”。

⚫ Linker or loader will bind relocatable addresses to absolute addresses  i.e. 74014
链接器或加载器将把可重定位的地址绑定到绝对地址上,例如:74014
⚫ Each binding maps one address space to another
每个绑定都将一个地址空间映射到另一个地址空间

Binding of Instructions and Data to Memory
◼ Address binding of instructions and data to memory addresses can happen at three different stages
指令和数据与存储器的地址绑定 地址的绑定可以发生在三个不同的阶段
 Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes
编译时。如果内存位置是事先知道的。可以生成绝对代码;如果起始位置改变,必须重新编译 如果起始位置改变,必须重新编译代码
 Load time: Must generate relocatable code if memory location is not known at compile time
加载时间。必须生成可重定位的代码,如果 必须生成可重定位的代码,如果在编译时不知道内存位置
 Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers)
执行时间。如果进程在执行过程中可以从一个地方移动到另一个地方,则绑定时间将推迟到运行时间。进程在其执行过程中可以从一个 进程可以从一个内存段移动到另一个内存段。需要硬件支持 地址映射(例如,基数和极限寄存器)的硬件支持。

在这里插入图片描述
Dynamic Storage-Allocation Problem

◼ First-fit: Allocate the first hole that is big enough
◼ Best-fit: Allocate the smallest hole that is big enough;
must search entire list, unless ordered by size
 Produces the smallest leftover hole
◼ Worst-fit: Allocate the largest hole; must also search
entire list
 Produces the largest leftover hole
◼ First-fit and best-fit are better than worst-fit in terms of
speed and storage utilization


Question:
在这里插入图片描述
在这里插入图片描述


Practice:

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
1.No 2.Best Fit algorithm


Paging:
Physical address space of a process can be noncontiguous; process
is allocated physical memory whenever the latter is available
◼ Divide physical memory into fixed-sized blocks called
frames (size is power of 2, between 512 bytes and 8,192
bytes)
◼ Divide logical memory into blocks of same size called pages
◼ Keep track of all free frames
◼ To run a program of size N pages, need to find N free frames and
load the program into them
◼ Set up a page table to translate logical to physical addresses
◼ Backing store likewise split into pages

Address Translation Scheme:
◼ Address generated by CPU is divided into 2 pieces:
 Page number页号 § – used as an index into a page table which
contains base address of each page in physical memory
 Page offset 页面偏移量(d) – combined with base address to define the
physical memory address that is sent to the memory unit
在这里插入图片描述
 For given logical address space 2m (m bits) and page size 2n


1 KB=2^10=1024
1 MB=2^20
1 GB=2^30
1 TB=2^40


◼ If the address of a given logical address space is A, the
page size is L, then page number P and page offset d
can be calculated as:
 P=INT⌊ A/L ⌋
 d=A MOD L
 For example, if the page size is 1KB, A=2170, then Address Translation Scheme
29
P=2, d=122

◼ Address translation(p, d)
 If p is in associative register, return corresponding frame number如果p是在关联寄存器中,则返回相应的帧号号码
 Otherwise get frame number from page table in memory 否则从内存中的页表获取帧号
在这里插入图片描述
Implementation of Page Table
◼ Page table is kept in main memory
页表被保存在主内存中
◼ Page-table base register (PTBR) points to the page table
页表基寄存器(PTBR)指向页表
◼ Page-table length register (PTLR) indicates size of the page table
页表长度寄存器(PTLR)表示页表的大小。
◼ In this scheme every data/instruction access requires two memory accesses: one for the page table and one for the data/instruction
在这个方案中,每个数据/指令访问都需要两次内存访问 ◼ 在这个方案中,每个数据/指令访问需要两个内存访问:一个是页表,一个是数据/指令。
◼ The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)
两个内存访问的问题可以通过使用一个特殊的快速查找硬件缓存来解决。这两个内存访问问题可以通过使用特殊的快速查找硬件缓冲器来解决,这种硬件缓冲器称为关联内存或 翻译查找缓冲器(TLB)。
◼ Some TLBs store address-space identifiers (ASIDs) in each TLB entry – uniquely identifies each process to provide address-space protection for that process
有些TLB在每个TLB中存储地址空间标识符(ASIDs) 条目 - 唯一识别每个进程以提供地址空间的 为该进程提供地址空间保护


Effective Access Time
◼ Associative Lookup = t time unit
◼ Hit ratio = 
 Hit ratio – percentage of times that a page number is found in the
associative registers; ratio related to number of associative registers
◼ Consider  = 80, 100ns for memory access
◼ Effective Access Time (EAT)
◼ Consider  = 80%, 100ns for memory access
 EAT = 0.80 x 100 + 0.20 x 200 = 120ns
◼ Consider more realistic hit ratio ->  = 99%, 100ns for memory access
EAT = 0.99 x 100 + 0.01 x 200 = 101ns

◼ Multi-level TLBs (data & instruction)
 L1
 L2


Structure of the Page Table
◼ Memory structures for paging can get huge using
straightforward methods
◼ Hierarchical Paging
◼ Hashed Page Tables
◼ Inverted Page Tables


在这里插入图片描述
(1).Page number and Page offset
(2).C
(3).P=0 d=500

在这里插入图片描述
3*1024+512=3584
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值