COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management Chapter 7.
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
CS 311 – Lecture 21 Outline Memory management in UNIX
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
CS 104 Introduction to Computer Science and Graphics Problems
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 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Computer Organization and Architecture
Virtual Memory I Chapter 8.
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.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process. 
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.
Operating Systems Chapter 8
Chapter 4 Storage Management (Memory Management).
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.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –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 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Chapter 4 Memory Management Virtual Memory.
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.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Computer Systems Week 14: Memory Management Amanda Oddie.
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.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
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.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
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 Chapter 5 Advanced Operating System.
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 2: The Linux System Part 4
Memory Management.
Virtual Memory CSSE 332 Operating Systems
Chapter 2 Memory and process management
Chapter 9: Virtual Memory
Virtual Memory Chapter 8.
Main Memory Management
Module 9: Virtual Memory
Chapter 8: Main Memory.
Chapter 9: Virtual-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.
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
CS399 New Beginnings Jonathan Walpole.
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.
CSE451 Virtual Memory Paging Autumn 2002
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
Chapter 8 & 9 Main Memory and Virtual Memory
CSE 542: Operating Systems
Presentation transcript:

COMP091 – Operating Systems 1 Memory Management

Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address known to program Relocatable –Program image uses relative addresses and can run from any place in memory Relative address –Address is relative to some base address = base + offset –Calculated or use hardware relative addressing

Memory Management Terms Static addresses –Addresses either don't change, or appear not to change Dynamic –Program knows addresses change at runtime –Uses pointer or handles to cope with dynamic addresses –Stack frames are dynamic –Dynamically allocated memory

More Memory Management Terms Base | segment | page pointer –Contains the base address that relative addresses are relative to –Addresses can be expressed relative to these hardware registers

More Memory Management Terms Pointer –A data item –Address of some other object Handles –A pointer managed externally –Process is provided address of the handle This address is a pointer to the pointer –Might be ased in heaps where address of the resource might be changed externally

More Memory Management Terms Binding –Provides a value for the base address of a relative address –Loading binds relative addresses to base of a memory segment –Addresses may be rebound if program moves around

More Memory Management Terms Partition –Early multi-programming systems allocated a memory partition to each batch job –Relied on jobs to stay in their own space –One base address for entire partition Segment –Like partition but a job may have more than one for different purposes –OS keeps track of memory use to keep processes within their own segments

More Memory Management Terms Absolute address –Constant actual physical address Some low memory addresses are constant –Boot routines in low memory –Traps, exceptions and interrupts are handled by routines at absolute addresses, or pointed to by a pointer at an absolute address –In virtual memory systems, areas like low memory that are accessed using absolute addresses are located in their real address which equals their virtual address

More Memory Management Terms Low memory –Systems, both hardware and OS usually reserve some low memory addresses for specific fixed uses –Particularly important during boot process Contiguous allocation –Programs expect the memory in any given segment to occupy contiguous memory locations –OS would have to find free memory large enough for entire allocation –In virtual memory systems this doesn't matter –Which is good because garbage collection is hard

Virtual Memory Systems Physical memory divided into frames Virtual memory divided into pages –Many more pages then frames Loading (binding) means associating an (active) page with a frame Frames don't need to be contiguous Page table keeps track of pages Divide address by size of page (2**n for some n) Quotient is page number Remainder is offset into page

Virtual Memory Systems Shared pages A frame address can be inserted into the page tables of many different processes –Enabling the processes to share the data on the pages that point to the shared frame –Useful for intra-process communication Inverted page table –One entry per frame –Enables OS to find process that owns a frame –Useful if you have to move the frame

Segmentation Logical memory is composed of segments –Many contiguous pages in a segment Segment table has the base address of each segment and its size, referred to as its limit –Limit because that is the largest offset that its process can use without generating a segmentation fault Some segments are marked sharable –Common OS code

Segmentation and Virtual Memory Each segment has its own page table Addresses resolved in the usual way Calculate the page table offset to find page number –Offset = address / page size Add to the segment's page table base to find the entry with the frame # –Then add remainder to frame base Notice in the following diagram that there are a lot more pages in page tables than there are frames in physical memory –Some pages aren't mapped to memory frames

Working Set At any point in time, a logical page may or may not be mapped to a physical frame The set of pages that are currently mapped to a physical frame and are pageable is called the working set Note: Windows allows applications to make large allocations that are permanently resident in physical memory and non-pageable so not part of working set –Address Windowing Extensions (AWE) or large page allocations

Backing Store Location of pages not currently in the working set Either a page file or a memory mapped file Processes can access data in a file by mapping some virtual addresses to the file on disk This is how executables are loaded Can be used to access other files And to share data among processes

File Mapping

Memory Management Functions

Demand Paging Program attempts memory access Processor (with hardware virtual memory support) attempts to find frame Page table doesn't contain a frame address if the page is not in memory Processor generates page fault User process is put in wait state

Demand Paging (cont.) OS checks to see if address is valid If not, process is terminated with memory violation If valid, page is retrieved from backing store, stored in a frame, page table updated with frame # Process is restarted This time, processor will find frame in page table and address can be accessed

Soft Page Fault A page fault generated for a page that doesn't have to be retrieved from backing store –Currently or recently in some other process's working set Maybe the OS –A new page never yet accessed (demand zero fault) –A pre-fetched page System just has to add frame to process's page table

Memory Map Describes relationship between pages of logical memory and physical memory frames –Or other locations of a logical memory pages Another memory map data structure describes all of the physical frames –User count –Age (for swap eligibility) –Frame number

Memory Mapping When loading an executable image into memory, only first page of image is loaded into virtual memory This allows construction of the page table for the entire image Image is not copied from disk file to virtual memory Instead memory map data structures are altered so the area of disk containing the image becomes a part of the virtual memory As image executes, page faults bring image into real memory

Swapping When physical memory is full, some pages have to be removed, or swapped, into swap file Usually the least most recently used page is swapped out Different OS's could use different algorithms Efficiency of algorithm is very important to performance Pages have “dirty bit” set if they have been changed since loading If dirty bit is not set page is discarded instead of being swapped (no need to save it)

Addressing Modes Hardware supports physical and virtual addressing modes OS itself resides in area of physical address space where physical addressing is employed –Processor doesn't have to resolve virtual addresses for the OS itself Processes that manipulate large amounts of memory can acquire large physically resident allocations –But still accessed through memory map

Access Control Segment tables contain access control information: –Read only for executables –Read allowed only for kernel mode processes –Read allowed for user mode processes –Write allowed only for kernel mode processes –Write allowed for user mode processes –Page dirty –Page has been accessed –etc

Page Allocation Programs asking for memory allocations are requesting virtual memory –Since the memory isn't real, they are actually asking for control over some virtual memory addresses A free area vector lists the blocks of free page numbers, smallest block first –There are other ways Allocation algorithm tries to allocate a request in minimum number of blocks Might break a too large block into smaller blocks to get right size

Deallocation When a block of memory is deallocated, attempt is made to combine the block with adjacent blocks to create a larger free block This is to counter the fragmentation that can occur as allocation breaks blocks up into smaller ones

Virtual Memory The memory space for a process may, and normally would, consist of more than one segment Each segment has a page table describing the virtual memory of that segment The virtual memory associated with the process consists of the collection of memory spaces described by all of the process's segments

Where is Virtual Memory? In a newly allocated data segment the memory doesn't exist until a page fault –After that it is in a physical frame or swap file If the segment points to a shared OS segment, then the virtual memory may be permanently stored in low memory If the segment “contains” an executable, or is mapped to some other file, the virtual memory will be mapped to the area of disk containing the executable –Will be loaded to memory via page faults only when needed

References MSDN: – us/library/windows/desktop/aa366525%28v=vs.8 5%29.aspxhttp://msdn.microsoft.com/en- us/library/windows/desktop/aa366525%28v=vs.8 5%29.aspx tldp –

Next Week Test in first 50 minutes –Lectures and labs No new lab this week or next –Students can have additional week for lab 5 if they need it. –May redo a past lab with permission