CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Memory Management.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Background A program must be brought into memory and placed within a process for it to be executed. Input queue – collection of processes on the disk that.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory Management Chapter 5.
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
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/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
CSCI 315 Operating Systems Design
Chapter 8: Main Memory.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management -1 Background Swapping Memory Management Schemes
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
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. 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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
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.
Chapter 10 Memory Management Introduction Process must be loaded into memory before being executed. Input queue – collection of processes on the.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
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.
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.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Memory Management 1. Outline Background Logical versus Physical Address Space Swapping Contiguous Allocation Paging Segmentation 2.
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 2: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging Operating System Concepts.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Module 9: Memory Management
Chapter 9: Memory Management
Chapter 8: 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.
Storage Management Chapter 9: Memory Management
Module 9: Memory Management
Chapter 8: Main Memory.
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.
Multistep Processing of a User Program
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
Memory Management-I 1.
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.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 542: Operating Systems
Presentation transcript:

CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido

CS6502 Operating Systems - Dr. J. Garrido Memory Management-- Background A program must be loaded into memory and placed within a process for it to be executed. Input queue – collection of processes on the disk that are waiting to be loaded into memory for execution. User programs go through several steps before being executed.

CS6502 Operating Systems - Dr. J. Garrido Program Development Source editing Compilation Linking Loading Executing

CS6502 Operating Systems - Dr. J. Garrido Binding Address binding: the association of instructions and data to memory addresses. This can occur at three different stages. Compile time: If the memory locations are known a priori, absolute code can be generated; must recompile code if starting location changes. Load time: Must generate relocatable code if memory location is not known at compile time. Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another.

CS6502 Operating Systems - Dr. J. Garrido Dynamic Loading A module is not loaded until it is called Better memory-space utilization; unused module is never loaded. Useful when large amounts of code are needed to handle infrequently occurring cases. No special support from the operating system is required implemented through program design.

CS6502 Operating Systems - Dr. J. Garrido Dynamic Linking Linking postponed until execution time. Small piece of code, stub, used to locate the appropriate memory-resident library routine. Stub replaces itself with the address of the module, and executes the module. Operating system needed to check if module is in processes’ memory address.

CS6502 Operating Systems - Dr. J. Garrido Logical vs. Physical Address Space Logical address – a reference to a location in the program. It is generated by the compiler or assembler Physical address – an actual location in main memory A logical address space is bound to a separate physical address space when the program is loaded.

CS6502 Operating Systems - Dr. J. Garrido Memory Management Classification Memory Management with static loading: Entire program is loaded into memory. Once program is loaded, it stays in memory ‘till execution is complete. Monoprogramming - One program in memory at a time. Multiprogramming - Partition memory: Load more than one program. –Fixed Partitions –Variable Partitions

CS6502 Operating Systems - Dr. J. Garrido Memory Management Classification Memory Management with dynamic loading: Swapping –Whole program is in memory during execution. –Whole program is moved to disk when suspended. Overlaying –Only part of program is in memory during execution. –May be moved to disk when suspended. Paging Segmentation Virtual memory -- Only currently executing portion of program is in memory

CS6502 Operating Systems - Dr. J. Garrido Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images.

CS6502 Operating Systems - Dr. J. Garrido Schematic View of Swapping

CS6502 Operating Systems - Dr. J. Garrido Static Relocation Different jobs run at different addresses. Addresses are changed at load time. (Relocation) Static relocation modifies instructions that address locations in memory. Static relocation does not solve protection.

CS6502 Operating Systems - Dr. J. Garrido Dynamic Relocation Addresses changed at execution time. Facilitates Protection using: –Addressing via Base (&Limit) Register. Additional benefit, program may be moved during execution.

CS6502 Operating Systems - Dr. J. Garrido Protection Necessary because malicious or incompetent programs may access the program or data space of another program and contaminate it.

CS6502 Operating Systems - Dr. J. Garrido Protection (2) Solution: Divide memory into Blocks of memory, associate a key with each block. Trap or transfer control to the OS when any program attempts to access memory whose key does not agree with its own.

CS6502 Operating Systems - Dr. J. Garrido Protection (3) Alternative: Load a Base Register w/ address at which process loaded. Load a Limit Register w/ size of partition. Compare each address generated with the contents of the base and base + limit register.

CS6502 Operating Systems - Dr. J. Garrido Contiguous Memory Allocation Main memory is divided into partitions: Single User Partition: –Resident operating system, usually held in low memory with interrupt vector. –User processes then held in high memory. Multiple User Partitions

CS6502 Operating Systems - Dr. J. Garrido Single-partition allocation Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register.

CS6502 Operating Systems - Dr. J. Garrido Multiple Partitions Fixed partitions (static) – the number and sizes of the partitions do not change Variable partitions (dynamic) – partitions are created dynamically according to: –available memory –the memory requirements of processes

CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions Memory is divided into fixed-sized partitions. These are not normally of the same size. The number and the size of the partitions are fixed. One partition is allocated to each active process in the multiprogramming set. There is one special partition, the system partition, in which the memory-resident portion of the operating system is always stored.

CS6502 Operating Systems - Dr. J. Garrido Multiple Fixed Partitions Method of organizing memory: Divide memory into n partitions. Rule: Process may not be larger than the partition. If all Partitions of same size: Lots of space lost internally in the Partition. (Internal Fragmentation) Operating System Partition 4 Partition 2 Partition 3 Partition 1 200K 400K 600K 800K Process 4 Process 3 Process 2 Process 1

CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions

CS6502 Operating Systems - Dr. J. Garrido Fragmentation in Fixed Partition Fragmentation problem Internal fragmentation - A partition is only partially used. The entire partition is allocated to a program

CS6502 Operating Systems - Dr. J. Garrido Memory Allocation Problem An important problem in OS is finding a fit between the partition sizes and the actual memory requirements of processes The goal is to minimize fragmentation

CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions: Multiple Input Queues Partition 4 Partition 2 Partition 1 Multiple Input Queues 100K 200K 400K 700K Partition 3 Operating System If Partitions are of different sizes: Less space is left unused to Internal Fragmentation. When a job arrives, it can be put into the input queue for the smallest partition which is large enough to hold it. Disadvantage of sorting incoming jobs into separate queues occurs when the queue for small partitions is full, but the queue for large partition is empty and consequently jobs await space when space is available.

CS6502 Operating Systems - Dr. J. Garrido Single Input Queue Partition 4 Partition 2 Partition 1 100K 200K 400K 700K Partition 3 Operating System Single Input Queue OS/MFT Used by OS/360 Alternative is to have a single queue for all jobs. When a partition becomes available, assign the job closest to front of queue that will fit. Incoming jobs are queued until suitable partition is available. Then, the process is loaded into the partition and run until terminated.

CS6502 Operating Systems - Dr. J. Garrido Variable Partition Allocation The partitions are created dynamically The OS maintains a table of partitions allocated that indicates which parts (location and size) of memory are available and which have been allocated.

CS6502 Operating Systems - Dr. J. Garrido Holes in Memory Hole – a contiguous block of available memory When a process requests memory, it is allocated memory from a hole large enough to accommodate it. Operating system maintains data about: –allocated partitions –Available memory blocks (holes)

CS6502 Operating Systems - Dr. J. Garrido Allocation with Variable Partitions At any given time, there is a list of available blocks of memory of various sizes (holes) and a queue of processes requesting memory. Memory is allocated contiguously to processes until there is no available block of memory large enough

CS6502 Operating Systems - Dr. J. Garrido Dynamic Memory Allocation The memory manager can: Wait until a large enough block of memory is available, or Skip down the queue to find a process with smaller requirements for memory.

CS6502 Operating Systems - Dr. J. Garrido Holes and Memory Allocation When a process is to be loaded, the OS searches for a hole large enough for this process and allocates the necessary space. When a process terminates, the OS frees its block of memory. In general, there is at any time, a set of holes, of various sizes, scattered throughout memory. Adjacent holes are merged to form a larger hole.

CS6502 Operating Systems - Dr. J. Garrido Memory Allocation First-fit: Allocate the first hole that is big enough. Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. How to satisfy a process request of size n from a list of free holes. First-fit and best-fit better than worst-fit in terms of speed and storage utilization.

CS6502 Operating Systems - Dr. J. Garrido Advantages of Variable Partition Memory utilization is generally better for variable-partition schemes. There is little or no internal fragmentation. There can be external fragmentation.

CS6502 Operating Systems - Dr. J. Garrido Memory States OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

CS6502 Operating Systems - Dr. J. Garrido Compaction: Solution to Fragmentation External fragmentation is a serious problem. The goal is to shuffle the memory contents to place all free memory together in one large block. This is only possible if relocation is dynamic (binding is done at execution time), using base and limit registers. Can be quite expensive (overhead).

CS6502 Operating Systems - Dr. J. Garrido Fragmentation - Recap External fragmentation – total memory space exists to satisfy a request, but it is not contiguous. Internal fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.

CS6502 Operating Systems - Dr. J. Garrido Non-contiguous Memory Allocation Paging Segmentation

CS6502 Operating Systems - Dr. J. Garrido Pages A page is a unit of logical memory of a program A frame is a unit of physical memory All pages are of the same size All frames are of the same size A frame is of the same size as a page

CS6502 Operating Systems - Dr. J. Garrido Paging Physical memory is divided into fixed-sized blocks called frames (size is power of 2 ). Logical memory is divided into blocks of same size called pages. A page of a program is stored on a frame, independently of other pages A logical address on the page is converted to a physical address on the corresponding frame

CS6502 Operating Systems - Dr. J. Garrido

Paging(2) The OS keeps track of all free (available) frames, and allocated frames in the page table. To run a program of size n pages, the OS needs n free frames to load program. The OS sets up a page table and converts logical to physical addresses. There is a small amount of internal fragmentation.

CS6502 Operating Systems - Dr. J. Garrido Memory Allocation with Paging The frames allocated to the pages of a process need not be contiguous; in general, the system can allocate any empty frame to a page of a particular process. There is no external fragmentation There is potentially a small amount of internal fragmentation that would occur on the last page of a process.

CS6502 Operating Systems - Dr. J. Garrido Logical Address Any address referenced in a process is defined by the page that the address belongs to and the relative address within that page. A logical address of a process consists of a page number and an offset.