Chapter 5 : Memory Management

Slides:



Advertisements
Similar presentations
Chapter 8: Main Memory.
Advertisements

Memory.
Part IV: Memory Management
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
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
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory Management Chapter 5.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
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.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
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.
Operating Systems Chapter 8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 4 Storage Management (Memory Management).
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
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.
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.
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.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Chapter 7 Memory Management
Memory Management Chapter 7.
Module 9: Memory Management
Chapter 9: Memory Management
UNIT–IV: Memory Management
Chapter 8: Memory Management
Chapter 8: Main Memory.
Chapter 8: Memory Management
Main Memory Management
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.
Storage Management Chapter 9: Memory Management
Operating System Concepts
Module 9: Memory Management
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.
CSS 430: Operating Systems - Main Memory
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.
Lecture 3: Main Memory.
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.
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

Chapter 5 : Memory Management By : Jigar M. Pandya

The need for memory management Memory is cheap today, and getting cheaper But applications are demanding more and more memory, there is never enough! Basically we will do memory management for primary memory By : Jigar M. Pandya

Memory Management Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time By : Jigar M. Pandya

Memory Management Requirements Relocation Protection Sharing Logical organisation Physical organisation By : Jigar M. Pandya

Requirements: Relocation The programmer does not know where the program will be placed in memory when it is executed, it may be swapped to disk and return to main memory at a different location (relocated) Memory references must be translated to the actual physical memory address By : Jigar M. Pandya

Requirements: Protection Processes should not be able to reference memory locations in another process without permission Impossible to check absolute addresses at compile time Must be checked at run time By : Jigar M. Pandya

Requirements: Sharing Allow several processes to access the same portion of memory Better to allow each process access to the same copy of the program rather than have their own separate copy By : Jigar M. Pandya

Requirements: Logical Organization Memory is organized linearly (usually) Programs are written in modules Modules can be written and compiled independently Different degrees of protection given to modules (read-only, execute-only) Share modules among processes Segmentation helps here By : Jigar M. Pandya

Requirements: Physical Organization Cannot leave the programmer with the responsibility to manage memory Memory available for a program plus its data may be insufficient Overlaying allows various modules to be assigned the same region of memory but is time consuming to program Programmer does not know how much space will be available By : Jigar M. Pandya

The need for Relocation Because of need for process swapping and memory compaction, a process may occupy different main memory locations during its lifetime. Consequently, physical memory references (addresses) by a process cannot always be fixed. This problem is solved by distinguishing between logical address and physical address. By : Jigar M. Pandya

Logical vs. Physical Address Space The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. Logical address – generated by the CPU; also referred to as virtual address. Physical address – address seen by the memory unit. By : Jigar M. Pandya

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. Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed. Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped. Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows. By : Jigar M. Pandya

Schematic View of Swapping By : Jigar M. Pandya

Contiguous Allocation Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector. User processes then held in high memory. 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. By : Jigar M. Pandya

Dynamic Storage-Allocation Problem How to satisfy a request of size n from a list of free holes. 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. First-fit and best-fit better than worst-fit in terms of speed and storage utilization. By : Jigar M. Pandya

Fragmentation 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. Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block. Compaction is possible only if relocation is dynamic, and is done at execution time. By : Jigar M. Pandya

Paging It is memory management scheme . Every Process is Divided in to number of pages. Divide physical memory into fixed-sized blocks called frames Divide logical memory into blocks of same size called pages. By : Jigar M. Pandya

Paging In Continuous Memory management We have to assign a whole block of the process size in the memory. Some time it may be not available in a single block. In Paging process is divided in to pages so there may be free pages available in the memory of same size. A process can put its page at any frame in The memory . When CPU runs a process it will generate logical addresses. But there should be some mapping between Logical Address and the frame in the Mem. By : Jigar M. Pandya

Paging Every Logical address will be divided In to two parts. 1) p = page number 2) d = offset In Example if Page size is 10 then For process of size 5 P= 0 d = 5 For process of size 12 P= 1 d = 2 Offset 2 in page 1 will be same as offset 2 in frame 3 because p1 is loaded in to frame no 3 By : Jigar M. Pandya

Paging By : Jigar M. Pandya

Paging CPU will generate a Logical address in p & d form. There Will Be A page map table to map the logical address to the frame number Logical address page number will be index of PMT. Using that we can get frame number. combine that frame number with offset will give you physical address in memory By : Jigar M. Pandya

Free Frames Before allocation After allocation By : Jigar M. Pandya

Implementation of Page Table Page table is kept in main memory. Page-table base register (PTBR) points to the page table. Page-table length register (PRLR) indicates size of the page table. In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction. The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs) By : Jigar M. Pandya

Associative Memory Associative memory – parallel search Page # Frame # By : Jigar M. Pandya

Paging Hardware With TLB (translation look-aside buffers) By : Jigar M. Pandya

Advantage of Paging If I want to user 100 KB then I don’t need a single block of 100KB I can use 10 free frame of 10KB that may not in continuous memory location. So some how we can avoid the problem of fragmentation. By : Jigar M. Pandya

Paging When we do paging we are dividing the code in to number of pages. So it may happen if there is a for loop Then some portion may be in first page, remaining may be in second page. That will also run the code . But if we want to separate code in modular format then we can use new concept that is called … SEGMENTATION By : Jigar M. Pandya

SEGMENTATION What is Module ?? If a large program is there then we are dividing that in to small small function that functions are called the modules. A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, common block, By : Jigar M. Pandya

User’s View of a Program By : Jigar M. Pandya

User’s View of a Program In segmentation there won’t be same size frames in memory it will be of different size segment and will be created when ever it is needed. So no fixed partition. By : Jigar M. Pandya

Logical View of Segmentation 1 4 2 3 1 2 3 4 user space physical memory space By : Jigar M. Pandya

Segmentation Architecture Logical address consists of a two tuple: <segment-number, offset> Segment table – maps two-dimensional physical addresses; each table entry has: base – contains the starting physical address where the segments reside in memory. limit – specifies the length of the segment. Segment-table base register (STBR) points to the segment table’s location in memory. Segment-table length register (STLR) indicates number of segments used by a program; By : Jigar M. Pandya

Segmentation Architecture Offset can not go beyond the size of the limit register By : Jigar M. Pandya

Segmentation Memory Management By : Jigar M. Pandya

Example of Segmentation By : Jigar M. Pandya

Segmentation Vs paging By : Jigar M. Pandya

Segmentation with Paging First The request will be divided in to segment Then each segment will be divided in to pages. So we need to manage segment table and also the page table for each segment. By : Jigar M. Pandya

Segmentation with Paging By : Jigar M. Pandya

Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical address space can therefore be much larger than physical address space. Allows address spaces to be shared by several processes. Allows for more efficient process creation. Virtual memory can be implemented via: Demand paging Demand segmentation By : Jigar M. Pandya

Thrashing Thrashing  a process is busy swapping pages in and out. If a process does not have “enough” pages, the page-fault rate is very high. This leads to: low CPU utilization. operating system thinks that it needs to increase the degree of multiprogramming. another process added to the system. By : Jigar M. Pandya