Chapter 7 Physical Memory Preparing a program for execution Memory partitioning schemes Allocation strategies for variable partitions Managing insufficient.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Chapter 6: Memory Management
Memory Management Chapter 7.
Fixed/Variable Partitioning
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.
CS 311 – Lecture 21 Outline Memory management in UNIX
OS Fall’02 Memory Management Operating Systems Fall 2002.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Module 3.0: Memory Management
CS 104 Introduction to Computer Science and Graphics Problems
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Lecture 13 L.Mohammad R.Alkafagee1.  The concept of a logical address space that is bound to a separate physical address space is central to proper memory.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
1 Memory Management (a). 2 Background  Program must be brought into memory and placed within a process for it to be run.  Input queue – collection of.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Operating Systems Principles Memory Management Lecture 7: Physical Memory 主講人:虞台文.
Memory Management. Introduction To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes.
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.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
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.
Operating Systems Lecture 31.
Operating Systems Principles Memory Management Lecture 7: Physical Memory 主講人:虞台文.
Memory Management Chapter 5 Advanced Operating System.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Operating Systems Lecture 31 Syed Mansoor Sarwar.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
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.
Memory Management Chapter 7.
Main Memory Management
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.
Chapter 7 Memory Management
Presentation transcript:

Chapter 7 Physical Memory Preparing a program for execution Memory partitioning schemes Allocation strategies for variable partitions Managing insufficient memory

7.1 preparing a program for execution Program transformations  compilation/assembly  linking  loading Source module1 Object module1 Source module2 Object module2 Source module3 Object module3... Load module (in secondary memory) Load module (in main memory) translationlinkingloadingexecution

Logical-to-physical address binding notations:  binding( relocation)  static binding  dynamic binding  (dynamically) relocatable Fun1(){ … fun2(); … } Fun2(){ … } … call m2,fun2 … //fun2 … Call Ladd1 … Ladd1: //fun2 … Call Fadd1 … Fadd1: //fun2 …

Static binding  programming-time binding  compile-time binding  link-time binding  load-time binding int i; …… i= …; …… f(); …… Store 20 …… Branch f i 20 0 Function f …… Store 120 …… Branch 0 i Function f …… Store 1120 …… Branch 1000 i

Dynamic binding the binding occurs at runtime, i.e., immediately preceding each memory reference. This delays the binding of the program to the machine until the latest possible moment. Physical_address=address_map(logical_address) Processor Main memory Address_map Logical address Physical address Data transfers(R/W)

Processor Main memory Relocation register Logical address Physical address Data transfers(R/W) + Physical_address=logical_address+ RR int i; …… i= …; …… f(); …… Store 20 …… Branch f i 20 0 Function f …… Store 120 …… Branch 0 i Function f …… Store 120 …… Branch 0 i Address map

7.2 Memory partitioning schemes Fixed partitions properties:  the sizes of partitions are determined statically  the sizes of partitions cannot be changed at runtime  partitions have different sizes to accommodate the different programs Schemes to schedule for the partitions:  using a separate queue for each partition  using a common queue

processes OS queues processes OS queues

Variable partitions properties:  the sizes of partitions are determined at runtime  the sizes of partitions equal the exact amount of space requested  memory consist of variable size blocks, alternating between occupied blocks and free blocks A BCD E

memory management:  requests to allocate  free memory areas A BC A’ BC A B BC’ A BC C A BC C B’

Linked list implementation free size A occupied size B occupied size C free size E occupied size D

Bitmap implementation … 1-KB block is represented by one bit( A, B, C, D, E: 3KB, 2KB, 5KB, 1KB, 5KB) Releasing block: Allocating block: Searching block: B [i]=b [i] & ‘ ’ B [i]=b [i] | ‘ ’ B [0]=b [0] & ‘ ’ B [0]=b [0] & ‘ ’ ……

The buddy system  assumption: fixed number of possible hole sizes, and each of which is a power of 2  buddies: any hole of size 2 i can be divided into two holes of size 2 i-1, these two holes are called buddies  implementation: H

 allocation( a request for n unit) find the smallest hole size such that n <=2i; if list I is not empty remove a hole form the list&allocate; else find a larger hole list( not empty) than list I; remove and divide into two holes(l&r) of half of size; place r on the next-lower list; if hole l is the smallest one for the request allocate; else divide repeatedly;

 release( for the block of size 2 i ) If the buddy of the block is occupied the new hole is added to the list i; Else remove the buddy from the list I; coalesce the two holes into a hole of size 2 i+1 ; repeat until the largest possible hole is created;

7.3 Allocation strategies for variable partitions First-Fit: finding the first hole large enough to accommodate the given request. Next_Fit( rotating-first-fit) starting each search at the point where the previous search stopped. Best_Fit selecting the hole with the closest fit. Worst_fit using the largest currently available hole for any given request.

Measures of memory utilization Equilibrium state: Prob(release)==Prob(request) Prob(n++)==Prob(n--) A BC A B A BC A BC C ab c d

m=a+b+c+d(7.1) n=(7.2) N=d+b(7.3) Prob(n++)=Prob(release)*a/m(7.4) Prob(n--)=Prob(release)*d/m+Prob(request)*(1-p)(7.5) A=d+(1-p)m(7.6)

m=d+(1-p)m+b+c+d =(1-p)m+2b+2d =(1-p)m+2n Conclusion1: n=0.5pm The fraction of memory occupied by holes: f =?

Assumption: average hole size: h average occupied block size: b k= M=nh+mb =0.5kmb+mb =mb(0.5k+1) Conclusion2:

7.4 Managing insufficient memory Memory compaction ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ p1p1 p2p2 p3p3 p1p1 p2p2 p3p3 p3p3 p1p1 p2p2 p2p2 p1p1 p3p3

Swapping creating new space by selecting one of the resident processes and temporarily evicting it to secondary storage. properties:  can always evict as many resident processes as is necessary;  affects only one or a small number of processes;  requires accesses to secondary memory.

Overlays different portions of the program replace( overlay) each other in memory as execution proceeds. A BC DE 0 A B C A D A C E

FAQs 3.1 m.A()x=11,y=9; m.A()x=12,y=10; m.B()x=11,y=10; m.B()x=10,y=10; m.A()x=10,y=8;

3.3 monitor stack{ char array[MAX]; UINT bottom=MAX-1,top=MAX-1; condition c; void push(char x){ if(bottom-top<MAX) array[top--]=x; if(bottom-top==1) c.signal; } void pop(char &x){ if(bottom==top) c.wait; x=array[++top]; }

4.8 Pb(s){ do{ R=0; SWAP(R,S); while(!R); } Vb(s){ s=1; }

4.13 f(x){ P(mutex); if(x){ condcnt_c1++; if(urgentcnt) V(urgent); else V(mutex); P(condsem_c1); condcnt_c1--; } x++; //////////////// if(condcnt_c2){ urgentcnt++; V(condsem_c2); P(urgent); urgentcnt--; } //////////////// x=0; if(urgentcnt) V(urgent); else V(mutex);

Hardwar e timers Wall-clockcountdown Timer queue TQ p1p1 20p2p2 125p3p3 50p4p Hardwar e timers Timer queue TQ p1p1 70p2p2 55p3p3 50p4p Hardwar e timers Timer queue TQ p1p1 55p2p2 15p3p3 35p4p4 15