1 Memory Management Requirements of memory management system to provide the memory space to enable several processes to execute concurrently to provide.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Chapter 6: Memory Management
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.
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.
Chapter 7 Memory Management
Multiprocessing Memory Management
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 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 Management Chapter 5.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Computer Organization and Architecture
Operating System Concepts
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
Chapter 7 Memory Management
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
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.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
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.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
VIRTUAL MEMORY By Thi Nguyen. Motivation  In early time, the main memory was not large enough to store and execute complex program as higher level languages.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter 4 Memory Management Virtual Memory.
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. 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.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
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.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
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.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
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.
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Day 19 Memory Management.
Memory management.
From Monoprogramming to multiprogramming with swapping
Chapter 9 – Real Memory Organization and Management
Main Memory Management
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Multistep Processing of a User Program
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
COMP755 Advanced Operating Systems
Presentation transcript:

1 Memory Management Requirements of memory management system to provide the memory space to enable several processes to execute concurrently to provide a satisfactory level of performance for users to protect processes from each other to enable sharing of memory space between processes to make addressing transparent

2 Basics Source code into the object code via compilation or assembly. Software systems of any size are usually made up of several modules which are joined together into one complex system using a linker. At the time the source code is translated into an object module, it contains external references. The compiler will generate a symbol table which is used to resolve these references during linking. The resulting module is known as the load module. At this point all addresses generated are logical addresses as the compiler and linker have no idea where the code will be placed in memory. These must be converted into physical addresses before they can be loaded and run. If these external references are resolved before the execution of the program, the linking is referred to as static, whereas if they are made at execution time they are known as dynamic. Finally load module from secondary storage into main memory. The logical to physical address translation is known as binding. It can occur at programming time, compile time or link time in an embedded system or simple computer system. All three strategies are static binding techniques and the resultant code is not relocatable. When binding occurs at runtime it is known as dynamic binding all memory references are logical but must be translated into physical addresses before being presented to the memory. The logical to physical transformation is accomplished using an address map.

3 Relocatable Code If virtual address space is organised as below, then the basic requirement for modules is to be held contiguously in physical memory and to contain addresses relative to their first location. The physical address of this first location is called the base of the process. Physical memory is much smaller than Virtual memory. The user program is shown starting at an arbitrary address and sharing memory with other programs Virtual Memory Physical Memory The simplest form of dynamic relocation hardware is a single base register and a memory management unit (MMU) to perform the translation

4 UNUSED USER PROCESSES OPERATING SYSTEM Single Process Allocation Memory Management Fixed Partition Allocation PROCESS A PROCESS C PROCESS B OPERATING SYSTEM Process C = 300k Process B = 200k Process A = 150k Partition3 400k Partition 2 300k Partition 1 200k

5 Fixed Partitions Fixed size partitions to allow for large and small processes Wasted space leads to internal fragmentation Where internal infers space allocated for a process System must manage memory protection Disadvantages process can’t run because no partition of suitable size available internal fragmentation wastes space

6 Variable Partitions AVAILABLE SPACE PROCESS C PROCESS B PROCESS A OPERATING SYSTEM 1000k 750k 450k 250k 100k 0k PROCESS C PROCESS B PROCESS A OPERATING SYSTEM 1000k 750k 450k 250k 100k 0k New PROCESS D 225k 975k Initially processes are loaded until memory full or no spaces large enough

7 FREE PROCESS C FREE PROCESS A OPERATING SYSTEM 1000k 750k 450k 250k 100k 0k PROCESS C terminates leaving three holes to coalesce PROCESS A OPERATING SYSTEM 1000k 750k 450k 250k 100k 0k Variable Partitions (a)(b) In (a) not enough space for new process although total space o.k Wasted space is called external fragmentation where: external = space without allocation

8 Storage placement policies Memory allocation is the process of assigning blocks of memory on request – performed by the allocator receives memory from the operating system in a small number of large blocks that it must divide up to satisfy the requests for smaller blocks. It must also make any returned blocks available for reuse. –Best fit policy –First fit policy –Worst fit policy –Buddy System Best fit is intuitively appealing, since it would appear that minimum space is wasted and is simple. However most programs grow and shrink dynamically. There are two reasons for this: The stack – it’s size increases with the depth of function calls The use of dynamically acquired memory using the malloc command (in ‘C’), which permits it to acquire extra memory in a structure called the heap.

9 Storage placement policies Worst fit doesn’t look too promising. However, worst fit could possibly leave a hole large enough to accommodate another process, while best fit, in trying to minimise the unused space could create a hole too small to be useful. First fit, appears to be too indiscriminate but there is very little overhead in implementing it. In the first fit algorithm, the allocator keeps a list of free blocks (known as the free list) and, on receiving a request for memory, scans along the list for the first block that is large enough to satisfy the request. The first fit algorithm performs reasonably well, as it ensures that allocations are quick.

10 NEW PROCESS 150K 100k 300k 200k 400k First fit, Hole residue = 150k Best fit, Hole residue = 50k Worst fit, Hole residue = 250k AVAILABLE HOLE SIZES (in memory order) ALLOCATION SELECTION Memory Management Best fit – hole into which process fits most tightly First fit – first available hole Worst fit – leaves maximum amount of free space

11 Buddy System In a buddy system, the allocator will only allocate blocks of certain sizes which are usually either powers of two, or form a Fibonacci sequence. Blocks can be divided into two smaller blocks. When the allocator receives a request for memory, it rounds the requested size up to a permitted size. If the free list for that size is empty, the allocator splits a block from a larger size. When blocks are recycled, there may be some attempt to merge adjacent blocks into ones of a larger permitted size (coalescence). A binary buddy heap before allocation A binary buddy heap after allocating a 8 kB block A binary buddy heap after allocating a 10 kB block; note the 6 kB wasted because of rounding up

12 Memory Management FREE PROCESS C PROCESS A OPERATING SYSTEM Need to suspend all process while compaction takes place Major overhead – particularly in time critical systems When to perform compaction when process terminates when process cannot load due to fragmentation at fixed intervals when user decides to Compaction of free space

13 Managing Memory If the memory requirements of the system exceed the available main memory there are at least three ways of solving the problem: –Overlays –Swapping –Paging Overlays are sections of an application's code or data that are stored on secondary memory when not in use. Swapping - if memory is needed, a ready process is selected to be swapped out. Swapping a process out of main memory involves copying the data segments of that process to a disk. When a process is selected to be run, if that process is swapped out, the system must first find or make space in main memory, then swap that process in, before running it.

14 ED CB A Overlays – function call hierarchy k2 k1 ACEACE ACDACD ABAB Overlays – address assignments Since B and D do not call each other, they need not reside in memory at the same time. The same is true of functions D and E; furthermore their presence is needed only when C is resident.

15 Simple Paging PAGE PAGE PAGE Process A Process B Process C A1 A2 A3 A4 A5 A6 B1 B2 B3 B4 B5 C1 C2 C3 C4 - Memory space Paging System Allocation

16 Simple Paging A1 A2 A3 A4 A5 A6 - C1 C2 C3 C4 - A1 A2 A3 A4 A5 A6 D1 D2 D3 E1 E2 C1 C2 C3 C4 E3 E4 - New process D New process E A1 A2 A3 A4 A5 A6 F1 F2 F3 H1 H2 G1 G2 H3 H4 - F4 (a)(b) (c) Updated Paging System

17 Simple Paging Memory address Converted memory address p pd Page Address Translation

18 Page Tables Address Translation

19 Memory Leakage A memory leak is a particular kind of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. The program in this case is part of some very simple software designed to control a lift This part of the program is run whenever anyone inside the lift presses the button for a floor. When a button is pressed: Get some memory, which will be used to remember the floor number Put the floor number into the memory Are we already on the target floor? { If so, we have nothing to do: finished } Otherwise { Wait until the lift is idle Go to the required floor Release the memory we used to remember the floor number }

20 #include void f(void) { void* s; s = malloc(50); /* get memory */ return; /* memory leak */ main() { while (1) f(); /* This function call will fail to malloc sooner or later */ } Memory was available and pointed to by s, but not saved. After this function returns, the pointer is destroyed and the allocated memory becomes unreachable. To "fix" this code, either the f() function itself needs to add "free(s)" somewhere.

21 Coffee Break

22 Correspond to logical divisions in a process i.e. code segments/ modules FREE A4 A3 B2 A2 A1 B3 B1 OPERATING SYSTEM SEGMENT 4 SEGMENT 3 SEGMENT 2 SEGMENT 1 SEGMENT 3 SEGMENT 2 SEGMENT 1 Process Structures Memory allocation Process A Process B Segmentation

23 Memory Management Logical addressPhysical address + LENGTHBASE ADDRESS s displacement d

24

25