博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OS Review Chapter 9: Memory Management
阅读量:3947 次
发布时间:2019-05-24

本文共 4051 字,大约阅读时间需要 13 分钟。

Chapter 9: Memory Management

文章目录

Background

Program must be brought into memory and placed within a process for it to be run

Base and Limit Registers

A pair of base and limit registers define the logical address space

Multi-step Processing of a User Program

在这里插入图片描述

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

Logical vs. Physical Address Space

  • Logical address–generated by the CPU; also referred to as virtual address.

  • Physical address–address seen by the memory unit.

Logical and physical addresses are the same in compile-time and load-time address-binding schemes

logical and physical addresses differ in execution time address-binding scheme

In this case, logical address is also referred to as virtual address. (Logical = Virtual in this course) MMU内存管理单元来决定虚拟地址到物理地址的转换 Memory-Management Unit

The user program deals with logical addresses; it never sees the real physical addresses.

Dynamic Loading

Better memory-space utilization; unused routine is never loaded

Useful when large amounts of code are needed to handle infrequently occurring cases

Dynamic Linking

比动态load更进一步 Both Linking and loading postponed until execution time.

节省内存,灵活性

When a routine is called, its stub is executed. The routine is loaded, the address of that routine replaces the stub, and executes the routine

Operating system needed to check if routine is in another process’ memory address

Dynamic linking is particularly useful for libraries

Swapping

Contiguous Allocation

如何分配给不同的进程使用 如何找到进程要访问的内存地址(寻址)

Monoprogramming systems

  • 系统
  • 用户

Multiprogramming systems:

  • Fixed partitions
  • variable partitions

Fixed partitions

Memory is divided into n partitions. Partitioning can be done at the startup time and altered later on. Each partition may have a job queue. Or, all partitions share the same job queue

在这里插入图片描述

Variable Partitions :

Hole–block of available memory–>How to satisfy a request of size n from a list of free holes

  • First-fit(首次适配)
  • Best-fit(最佳适配)
  • Worst-fit(最差适配)

Fragmentation(碎片)

Free memory holes between allocated ones are called external fragmentation外部碎片

memory that is allocated to a partition, but is not used, are called internal fragmentation内部碎片

外部碎片不可避免

Compaction for External Fragmentation

Compaction is possible only if relocation is dynamic, and is done at execution time

compaction scheme can be expensive

在这里插入图片描述

AC 连续分配容易通过base和limit寄存器实现内存保护

Paging

不连续分配的一种方法

Divide physical memory into fixed-sized blocks called frames(帧)

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 program.
  • Set up a page table to translate logical to physical addresses.
  • Internal fragmentation.

平均Internal fragmentation的大小是半个frame/page

Address Translation Scheme

Address generated by CPU is divided into:

  • Page number§
  • Page offset (d)

在这里插入图片描述

logical–> pages

physical–>frames

Implementation of Page Table

  • Page table is kept in main memory.
  • **Page-table base register (PTBR)**points to the page table

TLB 快表: Hit ratio = α

Effective Access Time (EAT)

​ EAT = (1 + ε) α+ (2 + ε)(1 –α) = 2 + ε- α

Memory Protection

Memory protection implemented by associating protection bit with each frame

Valid-invalid bit:

  • valid
  • invalid: the page is not in the process’ logical address space

we can use a page table length register (PTLR) that stores the length of a process’s page table.–>a process cannot access the memory beyond its region

Page Table Structure

Hierarchical Page Tables 分级页表:

Break up the logical address space into multiple page tables

在这里插入图片描述

Answer: 8 7 9

Hashed Page Tables

Inverted Page Table

转载地址:http://zmgwi.baihongyu.com/

你可能感兴趣的文章
拷贝代码时没有仔细检查,导致误修改了函数参数
查看>>
MySQL批量导入数据SQL语句(CSV数据文件格式)
查看>>
ADO连接Oracle
查看>>
遍历Windows系统中所有进程的名字(*.exe)
查看>>
使用互斥量保证程序最多只有一个实例运行
查看>>
进程定点自杀
查看>>
进程看门狗
查看>>
线程看门狗
查看>>
调试代码的宏定义
查看>>
__FILE__和__FUNCTION__的使用
查看>>
创建、重命名文件
查看>>
文件大小保护
查看>>
先文件大小保护,再写文件
查看>>
目录创建
查看>>
日志文件系统的写日志函数
查看>>
删除目录下的文件
查看>>
删除指定目录下所有文件及目录
查看>>
判断文件夹名是否是合法YYYYMM格式
查看>>
检查日志文件系统
查看>>
读配置文本
查看>>