Module 3.0: Memory Management

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

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.
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
Chapter 7 Memory Management
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
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.
Memory Management Chapter 5.
A. Frank - P. Weisberg Operating Systems Real Memory Management.
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.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
1 Memory Management Chapter 7. 2 Roadmap n Memory management u Objectives u Requirements n Simple memory management u Memory partitioning F Fixed partitioning.
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.
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 Chapter 7.
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.
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 Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
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.
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.
1 Memory Management Chapter 8. 2 Memory Management n It is the task carried out by the OS and hardware to accommodate multiple processes in main memory.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Memory Management Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
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.
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 Memory Management
Memory Management Chapter 7.
Chapter 8: Main Memory.
Real 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 Chapter 8 11/24/2018.
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.
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Chapter 7.
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.
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Presentation transcript:

Module 3.0: Memory Management Background Logical vs. Physical Address Memory Management Requirements Swapping Fixed Partitioning Dynamic Partitioning Overlays Placement Algorithm K. Salah

Binding of Instructions and Data to Memory Address binding of instructions and data to memory addresses can happen at three different stages. Compile time: If memory location is known a priori, absolute code can be generated; must recompile code if starting location changes. Build-time static .lib linking Load time: Must generate relocatable code if memory location is not known at compile time. Static linking in which program has to specify which executable modules are explicitly specified to be loaded by the program. The loading happens at load time of program and module. Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). Dynamic loading (by user program) Dynamic linking, e.g DLL (by OS) K. Salah

Dynamic Loading Routine is not loaded until it is called Better memory-space utilization; unused routine 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. K. Salah

Overlays Keep in memory only those instructions and data that are needed at any given time. Needed when process is larger than amount of memory allocated to it. Implemented by user, no special support needed from operating system, programming design of overlay structure is complex K. Salah

Dynamic Linking Before loading DLLs, addresses of functions in DLL are pointing to dummy addresses in an import table When process is loaded, the OS loader loads every module listed in the imported table, and resolves the addresses of each of the functions listed in each modules. The addresses are found in the exported table of the module. A demo of C:\program files\smartcapture.exe and c:\windows\system32\user32.dll Show import modules Show import module details Show export module details K. Salah

DLL process and how modules can be interconnected using import and export tables K. Salah

Memory Management Is the task carried out by the OS and hardware to accommodate multiple processes in main memory In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes. Memory needs to be allocated efficiently in order to pack as many processes into memory as possible If only a few processes can be kept in main memory, then much of the time all processes will be waiting for I/O and the CPU will be idle K. Salah

CPU Utilization vs. Processes Number CPU utilization = 1 – pn where n: number of processes p: fraction of time process is waiting for I/O How much memory should we have in order to gain higher CPU utilization? Study the graph. 1-p^2 – The chance of both waiting, and then take the complement. K. Salah

Memory Management Requirements Relocation programmer cannot know where the program will be placed in memory when it is executed a process may be (often) relocated in main memory due to swapping swapping enables the OS to have a larger pool of ready-to-execute processes memory references in code (for both instructions and data) must be translated to actual physical memory address K. Salah

Memory Management Requirements Protection processes should not be able to reference memory locations in another process without permission impossible to check addresses at compile time in programs since the program could be relocated address references must be checked at run time by hardware K. Salah

Memory Management Requirements Sharing must allow several processes to access a common portion of main memory without compromising protection cooperating processes may need to share access to the same data structure better to allow each process to access the same copy of the program rather than have their own separate copy K. Salah

Memory Management Requirements Logical Organization users write programs in modules with different characteristics instruction modules are execute-only data modules are either read-only or read/write some modules are private others are public To effectively deal with user programs, the OS and hardware should support a basic form of module to provide the required protection and sharing K. Salah

Memory Management Requirements Physical Organization secondary memory is the long term store for programs and data while main memory holds program and data currently in use moving information between these two levels of memory is a major concern of memory management (OS) it is highly inefficient to leave this responsibility to the application programmer K. Salah

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 and Microsoft Windows. K. Salah

Schematic View of Swapping K. Salah

Simple Memory Management In this part of the chapter we study the simpler case where there is no virtual memory An executing process must be loaded entirely in main memory (if overlays are not used) Although the following simple memory management techniques are not used in modern OS, they lay the ground for a proper discussion of virtual memory (later) fixed partitioning dynamic partitioning (also called variable-size partitions). K. Salah

Fixed Partitioning Partition main memory into a set of non overlapping regions called partitions Partitions can be of equal or unequal sizes K. Salah

Fixed Partitioning any process whose size is less than or equal to a partition size can be loaded into the partition if all partitions are occupied, the operating system can swap a process out of a partition a program may be too large to fit in a partition. The programmer must then design the program with overlays when the module needed is not present the user program must load that module into the program’s partition, overlaying whatever program or data are there K. Salah

Fixed Partitioning Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. Unequal-size partitions lessens these problems but they still remain... Equal-size partitions was used in early IBM’s OS/MFT (Multiprogramming with a Fixed number of Tasks) K. Salah

Placement Algorithm with Partitions Equal-size partitions If there is an available partition, a process can be loaded into that partition because all partitions are of equal size, it does not matter which partition is used If all partitions are occupied by blocked processes, choose one process to swap out to make room for the new process When swapping out a process, its state changes to to a Blocked-Suspend state, and gets replaced by a new process or a process from the Ready-Suspend queue K. Salah

Placement Algorithm with Partitions Unequal-size partitions: use of multiple queues assign each process to the smallest partition within which it will fit A queue for each partition size tries to minimize internal fragmentation Problem: some queues will be empty if no processes within a size range is present K. Salah

Placement Algorithm with Partitions Unequal-size partitions: use of a single queue When its time to load a process into main memory the smallest available partition that will hold the process is selected increases the level of multiprogramming at the expense of internal fragmentation K. Salah

Dynamic Partitioning Partitions are of variable length and number Each process is allocated exactly as much memory as it requires Eventually holes are formed in main memory. This is called external fragmentation Must use compaction to shift processes so they are contiguous and all free memory is in one block Used in IBM’s OS/MVT (Multiprogramming with a Variable number of Tasks) K. Salah

Dynamic Partitioning: an example A hole of 64K is left after loading 3 processes: not enough room for another process Eventually each process is blocked. The OS swaps out process 2 to bring in process 4 K. Salah

Dynamic Partitioning: an example another hole of 96K is created Eventually each process is blocked. The OS swaps out process 1 to bring in again process 2 and another hole of 96K is created... Compaction would produce a single hole of 256K K. Salah

Placement Algorithm Used to decide which free block to allocate to a process Goal: to reduce usage of compaction (time consuming) Possible algorithms: Best-fit: choose smallest hole. Hole sizes are sorted. First-fit: choose first hole from beginning Next-fit: choose first hole from last placement Worst-fit: choose the biggest hole. Makes bigger holes more useful. Quick-fit: choose a hole from a common-size hole list K. Salah

Placement Algorithm: comments Next-fit often leads to allocation of the largest block at the end of memory First-fit favors allocation near the beginning: tends to create less fragmentation than Next-fit Best-fit searches for smallest block: the fragment left behind is as small as possible main memory quickly forms holes too small to hold any process: compaction generally needs to be done more often Worst-fit and quick-fit have still fragmentation (useless holes) problems. K. Salah

How OS keeps track of memory usage: Bit Maps Linked Lists Buddy System K. Salah

Memory Management with Bit Maps Memory is divided up into small units which are represented by a bit map The smaller the allocation unit, the larger the bit map Search becomes slow when bit map is large K. Salah

Memory Management with Linked Lists A list entry is either a P or H. Works faster for replacement algorithms. When sorted, updating the list is straightforward. Possible to have two separate lists for Ps and Hs to make the search faster. K. Salah

Relocation Because of swapping and compaction, a process may occupy different main memory locations during its lifetime Hence physical memory references by a process cannot be fixed This problem is solved by distinguishing between logical address and physical address K. Salah

Address Types A physical address (absolute address) is a physical location in main memory A logical address is a reference to a memory location independent of the physical structure/organization of memory Compilers produce code in which all memory references are logical addresses A relative address is an example of logical address in which the address is expressed as a location relative to some known point in the program (ex: the beginning) K. Salah

Address Translation Relative address is the most frequent type of logical address used in pgm modules (ie: executable files) Such modules are loaded in main memory with all memory references in relative form Physical addresses are calculated “on the fly” as the instructions are executed For adequate performance, the translation from relative to physical address must by done by hardware K. Salah

Simple example of hardware translation of addresses When a process is assigned to the running state, a base register (in CPU) gets loaded with the starting physical address of the process A bound register gets loaded with the process’s ending physical address When a relative addresses is encountered, it is added with the content of the base register to obtain the physical address which is compared with the content of the bound register This provides hardware protection: each process can only access memory within its process image K. Salah

Example Hardware for Address Translation K. Salah