Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: 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.
Allocating Memory.
Chapter 7 Memory Management
CS 311 – Lecture 21 Outline Memory management in UNIX
OS Fall’02 Memory Management Operating Systems Fall 2002.
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.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
Memory Management Chapter 5.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
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.
Chapter 7 Memory Management
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Memory Management Chapter 7.
Subject: Operating System.
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.
1 Memory Management Requirements of memory management system to provide the memory space to enable several processes to execute concurrently to provide.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
CE Operating Systems Lecture 14 Memory management.
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.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
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 Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
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.
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.
Memory Management Chapter 7.
Memory Management Chapter 7.
Memory Management.
Memory management.
Chapter 8: Main Memory.
Chapter 8: Main Memory.
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
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.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Page Main Memory.
Presentation transcript:

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 2 Copyright ©2005 Memory binding Each entity has a set of attributes, e.g. a variable has type, size, dimensionality. Binding is the action of specifying values of attributes of an entity. Two types of binding are used in practice: –Early binding: Restrictive, but leads to efficient execution –Late binding: Flexible, but may lead to less efficient execution

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 3 Copyright ©2005 Memory binding Memory allocation is a binding of the `memory address’ attribute of a data entity Static and dynamic binding are examples of early and late binding, respectively

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 4 Copyright ©2005 Features of static and dynamic memory allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 5 Copyright ©2005 Memory allocation preliminaries Stack – LIFO allocation – A `contiguous’ data structure – Used for data allocated `automatically’ on entering a block Heap – Non-contiguous data structure – Pointer-based access to allocated data – Used for `program controlled data’ (PCD data) that is explicitly allocated and de-allocated in a program, e.g. malloc/calloc

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 6 Copyright ©2005 A heap before and after freeing an allocation area

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 7 Copyright ©2005 Memory allocation model for a process

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 8 Copyright ©2005 Linking, loading and execution of programs

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 9 Copyright ©2005 Memory binding in programs The origin of a program is the address of its first instruction or data byte A compiler is given an origin specification It binds instructions and data of a program in accordance with its origin specification

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 10 Copyright ©2005 Assembly program P and its generated code

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 11 Copyright ©2005 Linking and relocation of programs Linking –A program may wish to use library functions and other programs –These library functions and other programs should become a part of the program –Linking is the function that performs this action Relocation –Many program may have the same origin specification, so the address binding of some of them has to be changed –A program may have to be executed from a memory area that is different from the area for which it is compiled

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 12 Copyright ©2005 Linking and relocation of programs Linking and relocation could be performed –Statically –Dynamically What are the advantages of dynamic linking or relocation? How is dynamic linking or relocation performed?

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 13 Copyright ©2005 Program relocation using the relocation register: (a) program, (b) its view during execution

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 14 Copyright ©2005 Memory protection using bound registers

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 15 Copyright ©2005 Memory protection using memory protection leys

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 16 Copyright ©2005 Kernel actions for memory protection

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 17 Copyright ©2005 Free area management in a heap: (a) singly linked free list, (b) doubly linked free list

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 18 Copyright ©2005 Heap management: (a) free list, (b)-(d) allocation using first, best and next fit

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 19 Copyright ©2005 Memory fragmentation Fragmentation is the development of un-usably small areas in memory It has several consequences –Memory is wasted –The OS may run out of space to be allocated Two forms of memory fragmentation –Internal fragmentation –External fragmentation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 20 Copyright ©2005 Forms of memory fragmentation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 21 Copyright ©2005 How to counter external fragmentation? Do not allow free memory areas to become too small –Best fit leads to successively smaller memory areas! Combine adjoining free areas into a single larger memory area Perform compaction

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 22 Copyright ©2005 Boundary tags

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 23 Copyright ©2005 Merging using boundary tags (a) Free list, (b) -(d) freeing of areas X, Y or Z

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 24 Copyright ©2005 Memory compaction

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 25 Copyright ©2005 Buddy system When memory is to be allocated –Allocate the entire free area to satisfy a request, or –Split a free area into two free areas of equal size * These areas are called buddies * One of the buddies is considered for satisfying a memory request (either completely, or through successive splitting) When memory is to be freed –It is merged with its buddy, if the buddy is also free Status of blocks is saved in a status map

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 26 Copyright ©2005 A buddy system

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 27 Copyright ©2005 Buddy system operation when a block is released

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 28 Copyright ©2005 Powers of two allocators Allocation is in terms of blocks whose sizes are different powers of 2 Blocks are not split or merged Free lists are maintained for different block sizes The header element contains information about block status and size. It is stored in the block itself Header element occupies memory, hence memory efficiency is low for requests that are powers of two in size

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 29 Copyright ©2005 Header element in the powers-of-two allocator

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 30 Copyright ©2005 Approaches to memory allocation Contiguous memory allocation –Allocates a single contiguous memory area to a request –Suffers from fragmentation –Requires provision to counter fragmentation Noncontiguous memory allocation –Allocates a set of disjoint memory areas to a request –Overcomes certain forms of fragmentation (internal ? External?) –Requires address translation during execution of programs

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 31 Copyright ©2005 Contiguous memory allocation Fixed partitioned memory allocation –Partitions are fixed once and for all –A process is allocated a memory partition that is larger in size than its maximum requirement Variable partitioned memory allocation –A process is allocated only as much memory as it needs –Memory is reused through first-fit, best-fit, etc.

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 32 Copyright ©2005 Internal fragmentation in fixed partitioned allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 33 Copyright ©2005 Memory compaction in variable partitioned allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 34 Copyright ©2005 Noncontiguous memory allocation Several disjoint memory areas may be allocated in response to a request. However, hardware aids in the execution of programs. –User or a process is not aware of noncontiguity –Hence two views of a process exist * Logical view: View by the user or process itself. * Physical view: Actual situation regarding allocation –The organization of components in the logical view is called logical organization, and addresses used in it are called logical addresses –Addresses used in the physical view are called physical addresses Avoids external fragmentation as no memory area is too small to be allocated

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 35 Copyright ©2005 Noncontiguous memory allocation How is noncontiguous memory allocation performed? –A process is considered to consist of a set of components –Each component is allocated a contiguous area of memory that can accommodate it –Each logical address in an instruction is considered to consist of a pair (component #, byte #) During operation of the process, a hardware unit called the memory management unit (MMU) converts a (component #, byte #) pair into an absolute memory address

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 36 Copyright ©2005 Noncontiguous memory allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 37 Copyright ©2005 Logical and physical views of a process in a noncontiguous memory allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 38 Copyright ©2005 Schematic of address translation in non-contiguous memory allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 39 Copyright ©2005 Approaches to Noncontiguous memory allocation Paging –A process consists of components of a fixed size, called pages –The page size is a power of 2 and is fixed in the architecture –Memory is divided into parts called page frames, whose size matches the size of a page –The kernel allocates memory to all pages of a process –The kernel builds a page table that stores information about addresses of page frames allocated to processes –The MMU uses information in the page table to perform address translation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 40 Copyright ©2005 Paging A logical address is split into a pair (page #, word #) This splitting is performed using bit-splitting since the page size is a power of 2

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 41 Copyright ©2005 Processes in paging

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 42 Copyright ©2005 Approaches to noncontiguous memory allocation Segmentation –Each component in a process is a logical unit called a segment, e.g., a function, a module or an object –Components have different sizes –The kernel allocates memory to all components and builds a segment table –Each logical address in a segment is a pair of the form (segment #, byte #) –The MMU uses the segment table to perform address translation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 43 Copyright ©2005 A process Q in segmentation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 44 Copyright ©2005 Comparison of continuous and noncontinuous memory allocation

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 45 Copyright ©2005 Kernel memory allocation The kernel creates and destroys data structures used to store information about user processes and resources at a very high rate, e.g. PCBs, ECBs. Hence efficiency of kernel memory allocation directly influences its overhead Kernel uses special techniques to perform memory allocation for its data structures These techniques exploit the fact that the sizes of many of these data structures are known in advance, e.g. PCBs, ECBs.

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 46 Copyright ©2005 Slab allocator A slab is a fixed sized area of memory A slab contains data structures of the same kind A slab is preformatted to contain standard sized slots for these data structures A free list indicates which slots are free If all slabs containing data structures of a specific kind are full, new slabs are allocated by the kernel Allocation and de-allocation of memory is very fast

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 47 Copyright ©2005 Format of a slab

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 48 Copyright ©2005 Program forms employed in operating systems

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 49 Copyright ©2005 (a) a program, and (b) its equivalent overlay structured program in execution

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 50 Copyright ©2005 Sharing of a program (a) static sharing, (b) dynamic sharing

Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 51 Copyright ©2005 Reentrant program (a) structure of program C, (b)-(c) invocation by A and B.