Chapter 4 Memory Management.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory management In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. Memory management is achieved.
Chapter 6: Memory Management
Fixed/Variable Partitioning
Memory Management. Managing Memory … The Simplest Case The O/S User Program 0 0xFFF … * Early PCs and Mainframes * Embedded Systems One user program at.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)
Chapter 3.1 : Memory Management
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Chapter 3 Memory Management
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
1 Chapter 3.1 : Memory Management Storage hierarchy Storage hierarchy Important memory terms Important memory terms Earlier memory allocation schemes Earlier.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
Tutorial 6 Memory Management
Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
1. Memory Manager 2 Memory Management In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
CY2003 Computer Systems Lecture 09 Memory Management.
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
Chapter 10 Memory Management Introduction Process must be loaded into memory before being executed. Input queue – collection of processes on the.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Memory Management 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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT. MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile.
Memory Management Chapter 5 Advanced Operating System.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
Memory Management One of the most important OS jobs.
Memory Management Chapter 7.
Memory Management.
Chapter 2 Memory and process management
Memory management.
From Monoprogramming to multiprogramming with swapping
Memory Allocation The main memory must accommodate both:
CSC 322 Operating Systems Concepts Lecture - 12: by
Main Memory Management
The Operating System Memory Manager
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
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 (1).
Chapter 7 Memory Management
Page Main Memory.
Presentation transcript:

Chapter 4 Memory Management

Agenda Memory Management Why? What? How? 内存是计算机的一种非常重要的资源,如何对内存进行管理,是操作系统的重要功能之一。

General Memory Problem We have a limited (expensive) physical resource: main memory We want to use it as efficiently as possible We have an abundant, but slower, resource: disk 每个程序员都梦想拥有这样的内存:它容量无限大,速度无限快,并且是永久性存储器,价格低廉。遗憾的是,目前的技术还无法实现。

Lots of Variants Many processes, total size less than memory Technically possible to pack them together Will programs know about each other’s existence? One process, size exceeds memory Can you only keep part of the program in memory? Lots of processes, total size exceeds memory What programs are in memory, and how to decide?

Memory Manager It’s task: Manage memory hierarchy Track used and free memory Allocate memory to processes Reclaim (De-allocate) memory Swapping between main memory and disk Reclaim: 回收 存储管理器的主要任务:有效的管理内存,即记录哪些内存是正在使用的,哪些内存是空闲的,在进程需要时为其分配内存,在进程使用后释放内存。

A typical memory hierarchy. The numbers are very rough approximations.

Memory Cache Questions when dealing with cache: When to put a new item into the cache. Which cache line to put the new item in. Which item to remove from the cache when a slot is needed. Where to put a newly evicted item in the larger memory. 研究高速缓存要面临和解决的一些问题。主要就是提高命中率(hit,miss),现在能到90%左右。 Evict:驱逐 由于最底层的高速缓存的管理由硬件来完成,本章主要介绍如何管理优化内存。

Types of Memory Primary Memory (a.k.a. RAM) Holds data and programs used by a process that is executing Only type of memory that a CPU deals with Secondary Memory (i.e. hard disk) Non-volatile memory used to store data when a process is not executing

The Memory Manager (MM) Purpose: to manage the use of primary and secondary memory. Responsible for: Allocating primary memory to processes Moving processes between primary and secondary memory Optimizing memory usage

Process Memory There are two types of memory that can be used within a process: Stack: used for local/automatic variables and for passing parameters to function calls Heap: used for dynamic memory allocation

Allocates more memory than needed at first Process Memory Layout Allocates more memory than needed at first Heap grows towards stack for dynamic memory allocation Stack grows towards heap when automatic variables are created Environment Variables, etc. Stack Segment Heap Storage Data Segment (global and static variables) Text Segment

Single-Partition Strategies Three simple ways of organizing memory with an operating system and one user process.

Fixed-Partition Strategies Memory divided into fixed-size regions Size of each region usually not equal MM will allocate a region to a process that best fits it Unused memory within an allocated partition called internal fragmentation

Fixed-Partition Example Internal Fragmentation Internal Fragmentation Partition 5 Partition 5 Process 1 Partition 4 Partition 4 Internal Fragmentation Partition 3 Partition 3 Process 3 Internal Fragmentation Partition 2 Partition 2 Process 2 Partition 1 Partition 1 Operating System Operating System

Multiprogramming with Fixed Partitions Fixed memory partitions separate input queues for each partition single input queue

Variable-Partition Strategies MM allocates regions equal to the memory requirements of a process at any given time As processes die, holes develop in the memory MM inserts new processes into holes

Variable-Partition Example Process 3 Process 3 Process 2 Process 3 Process 4 Process 4 Process 1 Process 5 Process 5 Operating System Operating System Operating System Initially P2 completes P4 starts P1 completes P5 starts After compacting

More… Results in External Fragmentation After a while, only small processes will be able to run due to too much external fragmentation MM must compact the memory to make more space available for larger processes 外碎片的特点: 紧缩内存这个技术是很消耗时间的。

Relocation Illustration of the relocation problem. (a) (b) logical address (c) physical address

Base and Limit Registers Base and limit registers can be used to give each process a separate address space.

Memory Management with Bitmaps (a) A part of memory with five processes and three holes. The tick marks show the memory allocation units. The shaded regions (0 in the bitmap) are free. (b) The corresponding bitmap. (c) The same information as a list.

Memory Management with Linked Lists Four neighbor combinations for the terminating process, X.

Storage Placement Strategies First Fit Scan; use the first available hole whose size is sufficient to meet the need. Problem: Creates average size holes; more fragementation closer to scan start. Next Fit Minor variation of first fit: keep track of where last search ended, restart from there. Problem: slightly worse performance than first fit. Best Fit Use the hole whose size is equal to the need, or if none is equal, the smallest hole that is large enough. Problem: Creates small holes that can't be used. Worst Fit Use the largest available hole. Problem: Gets rid of large holes, making it difficult to run large processes. Quick Fit maintains separate lists for some of the more common sizes requested. When a request comes for placement, it finds the closest fit. This is a very fast scheme, but a merge is expensive. If merge is not done, memory will quickly fragment into a large number of holes.

Modeling Multiprogramming 采用多道程序设计可以提高CPU的利用率。 Degree of multiprogramming CPU utilization as a function of number of processes in memory