Chapter 7 Memory Management

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management Chapter 7.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
7. Physical Memory 7.1 Preparing a Program for Execution
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
OS Fall’02 Memory Management Operating Systems Fall 2002.
Chapter 7 Memory Management
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management Chapter 5.
Chapter 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Operating System 7 MEMORY MANAGEMENT. MEMORY MANAGEMENT REQUIREMENTS.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
Chapter 7 Memory Management
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
1 Memory Management Chapter 8. 2 Memory Management n It is the task carried out by the OS and hardware to accommodate multiple processes in main memory.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
CompSci 143A1 Part II: Memory Management Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory Spring, 2013.
COMP 3500 Introduction to Operating Systems Memory Management: Part 2 Dr. Xiao Qin Auburn University Slides.
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Requirements, Partitioning, paging, and segmentation
Day 19 Memory Management.
Chapter 8: Main Memory.
Real Memory Management
Chapter 8 Main Memory.
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Economics, Administration & Information system
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Chapter 7.
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Operating Systems: Internals and Design Principles, 6/E
Page Main Memory.
Presentation transcript:

Chapter 7 Memory Management Operating System Chapter 7 Memory Management

Chapter 7 Memory Management Goals of memory management subdividing memory to accommodate multiple processes(为支持多道程序将内存进行划分) Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time(内存管理应确保有适当数目的就 绪进程使用处理器时间)

Chapter 7 Memory Management The External View of the Memory Manager

Chapter 7 Memory Management 7.1 Memory Management Requirements 7.2 Memory Partitioning 7.3 Paging 7.4 Segmentation 7.5 Summary

7.1 Memory Management Requirements 7.1.1 Five requirements 7.1.2 Preparing Program for Execution

7.1.1 Five requirements(1/6) 1. Relocation We need to relocate the process to a different area of memory. Programmer does not know where the program will be placed in memory when it is executed. While the program is executing, it may be swapped(交换) to disk and returned to main memory at a different location (relocated). Memory references(访问) found in the code must be translated to actual physical memory address(物理内存地址).

7.1.1 Five requirements(2/6) 1. Relocation Relocation could raise some technical concerns related to addressing

7.1.1 Five requirements(3/6) 2. Protection Processes should not be able to reference memory locations in another process without permission Normally, processes cannot access any portion of the OS, neither program nor data. Impossible to check absolute addresses at compile time, must be checked at rum time. Memory protection requirement must be satisfied by the processor (hardware) rather than the operating system Operating system cannot anticipate all of the memory references a program will make

7.1.1 Five requirements(4/6) 3. Sharing Allow several processes to access the same portion of memory Share same copy of the program Share data structure to cooperate on some task The memory management system must allow controlled access to shared areas of memory without compromising essential protection.

7.1.1 Five requirements(5/6) 4. Logical Organization(逻辑组织) Programs are written in modules Modules can be written and compiled independently Different degrees of protection given to modules (read-only, execute-only) Share modules among processes

7.1.1 Five requirements(6/6) 5. Physical Organization(物理组织) Memory is organized into at least two levels, referred to as main memory and secondary memory Memory available for a program plus its data may be insufficient(内存对程序和其数据来说可能不足) Overlaying(覆盖) allows various modules to be assigned the same region of memory Programmer does not know how much space will be available and where his/her program will be loaded in memory

7.1 Memory Management Requirements 7.1.1 Five requirements 7.1.2 Preparing Program for Execution

7.1.2 Preparing Program for Execution(1/9) Program Transformations Translation (Compilation) Linking Loading

7.1.2 Preparing Program for Execution(2/9) A Sample Code Segment ... static int gVar; int proc_a(int arg) { gVar = 7; put_record(gVar); }

7.1.2 Preparing Program for Execution(3/9) The Relocatable Object module

7.1.2 Preparing Program for Execution(4/9) The Absolute Program

7.1.2 Preparing Program for Execution(5/9) The Program Loaded at Location 4000

7.1.2 Preparing Program for Execution(6/9) Address Binding Assign Physical Addresses = Relocation Static binding Programming time Compilation time Linking time Loading time Dynamic binding Execution time

7.1.2 Preparing Program for Execution(7/9) Static Address Binding Static Binding = At Programming, Compilation, Linking, and/or Loading Time

7.1.2 Preparing Program for Execution(8/9) Dynamic Address Binding Dynamic Binding = At Execution Time

7.1.2 Preparing Program for Execution(9/9) Address Binding How to implement dynamic binding Perform for each address at run time: pa = address_map(la) Simplest form of address_map: pa = la + RR(Relocation Register)

Chapter 7 Memory Management 7.1 Memory Management Requirements 7.2 Memory Partitioning 7.3 Paging 7.4 Segmentation 7.5 Summary

7.2 Memory Partitioning Fundamental Memory Management Problem How do we manage applications whose size may be larger than the size of memory available? Partition in blocks and load as necessary

7.2 Memory Partitioning Memory sharing schemes Single-program systems 2 partitions (OS/user) Multi-programmed Divide memory into partitions of different sizes Several schemes

7.2 Memory Partitioning 7.2.1 Fixed Partitioning 7.2.2 Dynamic Partitioning 7.2.3 Buddy System 7.2.4 Relocation

7.2.1 Fixed Partitioning(1/7) Alternatives for Fixed Partitioning Equal-size partitions(大小相等的分区) Unequal-size partitions(大小不等的分区)

7.2.1 Fixed Partitioning(2/7) Equal-size partitions: features Any process whose size is less than or equal to the partition size can be loaded into an available partition If all partitions are full, the operating system can swap a process out of a partition

7.2.1 Fixed Partitioning(3/7) Limitations of fixed partitions A program may be too big to fit in a partition. The programmer must design the program with overlays (覆盖技术) Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. internal fragmentation(内部碎片).

7.2.1 Fixed Partitioning(4/7) Unequal-size partitions(大小不等的分区) Both of these problems of equal-size partitions can be lessened, though not solved, by using unequal-size partitions.

7.2.1 Fixed Partitioning(5/7) How to assign processes to partitions Placement Algorithm Equal-size partitions trivial Unequal-size partitions Queue for each partition: Some partitions may be unused Single Queue: More complex, but more flexible Choose the one that fits the best

7.2.1 Fixed Partitioning(6/7)

7.2.1 Fixed Partitioning(7/7) Disadvantages of Fixed Partitions The number of active processes in the system is limited by the number of partitions Small jobs will not utilize partition efficiently

7.2 Memory Partitioning 7.2.1 Fixed Partitioning 7.2.2 Dynamic Partitioning 7.2.3 Buddy System 7.2.4 Relocation

7.2.2 Dynamic Partitioning(1/10) Memory not partitioned a priori Each request is allocated portion of free space Memory = Sequence of variable-size blocks Some are occupied, some are free (holes) External fragmentation occurs Adjacent holes (right, left, or both) must be coalesced to prevent increasing fragmentation

7.2.2 Dynamic Partitioning(2/10)

7.2.2 Dynamic Partitioning(3/10) Placement algorithms 1. First-fit algorithm(首次适配) Scans memory from the beginning and chooses the first available block that is large enough Simplest and usually fastest and best May have many process loaded in the front end of memory that must be searched over when trying to find a free block

7.2.2 Dynamic Partitioning(4/10) Placement algorithms 2. Best-fit algorithm(最佳适配) Chooses the block that is closest in size to the request Worst performer overall Since smallest block is found for process, the smallest amount of fragmentation is left Memory compaction must be done more often

7.2.2 Dynamic Partitioning(5/10) Placement algorithms 3. Worst-fit algorithm(最坏适配) Worst Fit allocates a process to the partition which is largest sufficient among the freely available partitions available in the main memory.

7.2.2 Dynamic Partitioning(6/10) Placement algorithms 4. Next-fit(邻近适配) Scans memory from the location of the last placement and chooses the next available block that is large enough More often allocate a block of memory at the end of memory where the largest block is found The largest block of memory is broken up into smaller blocks Compaction is required to obtain a large block at the end of memory

7.2.2 Dynamic Partitioning(7/10)

7.2.2 Dynamic Partitioning(8/10) Linked List Implementation All available space tied together through a linked list(空闲链表) Type/Size tags at the start of each Block Checking neighbors of released block b

7.2.2 Dynamic Partitioning(9/10) Bitmap Implementation Memory divided into fix-size blocks Each block represented by a 0/1 bit in a binary string: the“bitmap a) memory with 5 processes and 3 free blocks b) the bitmap (1: occupy 0: free) c) represent by free linked list

7.2.2 Dynamic Partitioning(10/10) Bitmap Implementation Operations use bit masks Release: B[i] = B[i] & '11011111' Allocate: B[i] = B[i] | '11000000' Search: Repeatedly, Check left-most bit and Shift mask right: TEST = B[i] & '10000000'

7.2 Memory Partitioning 7.2.1 Fixed Partitioning 7.2.2 Dynamic Partitioning 7.2.3 Buddy(伙伴) System 7.2.4 Relocation

7.2.3 Buddy System(1/3) Compromise between fixed and variable partitions Fixed number of possible hole sizes; typically, 2i Each hole can be divided (equally) into 2 buddies. Track holes by size on separate lists When n bytes requested, find smallest i so that n≤2i If hole of this size available, allocate it; otherwise, consider larger holes. Recursively split each hole into two buddies until smallest adequate hole is created Allocate it and place other holes on appropriate lists On release, recursively coalesce buddies Buddy searching for coalescing can be inefficient

7.2.3 Buddy System(2/3)

7.2.3 Buddy System(3/3)

7.2 Memory Partitioning 7.2.1 Fixed Partitioning 7.2.2 Dynamic Partitioning 7.2.3 Buddy System 7.2.4 Relocation

7.2.4 Relocation(1/5) Why?? When program loaded into(载入) memory the actual (absolute) memory locations are determined A process may occupy different partitions which means different absolute memory locations during execution (from swapping,交换) Compaction(压缩) will also cause a program to occupy a different partition which means different absolute memory locations

7.2.4 Relocation(2/5) Addresses Logical Address(逻辑地址) Reference to a memory location independent of the current assignment of data to memory(与当前数据在内存 中的分配无关的访问地址) Translation must be made to the physical address Relative Address(相对地址): Address expressed as a location relative to some known point Physical Address(物理地址) The absolute address(绝对地址) or actual location in main memory

7.2.4 Relocation(3/5) 相对地址 基址寄存器 加法器 绝对地址 界限寄存器 比较器 给操作系统的中断 进程映像

7.2.4 Relocation(4/5) Registers Used during Execution Base register(基址寄存器) Starting address for the process Bounds register(界限寄存器) Ending location of the process These values are set when the process is loaded(加载) or when the process is swapped in(换入)

7.2.4 Relocation(5/5) Registers Used during Execution The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system

Chapter 7 Memory Management 7.1 Memory Management Requirements 7.2 Memory Partitioning 7.3 Paging 7.4 Segmentation 7.5 Summary

7.3 Paging 7.3.1 Dealing with Insufficient Memory 7.3.2 Paging scheme in OS

7.3.1 Dealing with Insufficient Memory(1/3) Memory compaction How much and what to move? Swapping Temporarily move process to disk Requires dynamic relocation Overlays Allow programs large than physical memory Programs loaded as needed according to calling structure.

7.3.1 Dealing with Insufficient Memory(2/3) Memory compaction

7.3.1 Dealing with Insufficient Memory(3/3) Overlays Allow programs large than physical memory Programs loaded as needed according to calling structure

7.3 Paging 7.3.1 Dealing with Insufficient Memory 7.3.2 Paging scheme in OS

7.3.2 Paging scheme in OS(1/5) Partition memory into small equal fixed-size chunks(块) which are called frames(帧) Divide each process into small equal fixed-size chunks which are called pages(页). The size of pages are equal to the size of frames Operating system maintains a page table(页表) for each process Contains the frame location(帧位置) for each page in the process Memory address consist of a page number(页号) and offset(偏移量) within the page

7.3.2 Paging scheme in OS(2/5) Address generated by CPU is divided into: Page number (p)– 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

7.3.2 Paging scheme in OS(3/5) Paging Example

7.3.2 Paging scheme in OS(4/5) Assignment of Process Pages to Free Frames

7.3.2 Paging scheme in OS(5/5) Page Tables for Example

Chapter 7 Memory Management 7.1 Memory Management Requirements 7.2 Memory Partitioning 7.3 Paging 7.4 Segmentation 7.5 Summary

7.4 Segmentation(1/5) Segmentation is a technique that partitions memory into logically related data units Module, procedure, stack, data, file, etc. Virtual addresses become <segment #, offset> Units of memory from user's perspective Segmentation = many segments/process Hardware support Multiple base/limit pairs, one per segment (segment table) Segments named by #, used to index into table

7.4 Segmentation(2/5)

7.4 Segmentation(3/5)

7.4 Segmentation(4/5)

7.4 Segmentation(5/5) Segmentation and Paging Can combine segmentation and paging The x86 supports segments and paging Use segments to manage logically related units Module, procedure, stack, file, data, etc. Segments vary in size, but usually large (multiple pages) Use pages to partition segments into fixed size chunk Makes segments easier to manage within physical memory

Chapter 7 Memory Management 7.1 Memory Management Requirements 7.2 Memory Partitioning 7.3 Paging 7.4 Segmentation 7.5 Summary