By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
OS Fall’02 Memory Management Operating Systems Fall 2002.
Lecture 11: Memory Management
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management 2010.
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
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 ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
Computer Organization and Architecture
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
CSE451 Operating Systems Winter 2012 Memory Management Mark Zbikowski Gary Kimura.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Operating Systems Chapter 8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Operating System Main Memory.
Operating Systems ECE344 Ding Yuan Memory Management Lecture 7: Memory Management.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
VIRTUAL MEMORY By Thi Nguyen. Motivation  In early time, the main memory was not large enough to store and execute complex program as higher level languages.
CE Operating Systems Lecture 14 Memory management.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CSE 451: Operating Systems Fall 2010 Module 10 Memory Management Adapted from slides by Chia-Chi Teng.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
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.
CSE 451: Operating Systems Winter 2015 Module 11 Memory Management Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska, Levy,
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.
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.
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.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Chapter 8: Main Memory.
CSE 120 Principles of Operating
CSE 451: Operating Systems Winter 2007 Module 10 Memory Management
CS703 - Advanced Operating Systems
CSE451 Operating Systems Winter 2011
CSE 451: Operating Systems Winter 2010 Module 10 Memory Management
CSE 451: Operating Systems Winter 2014 Module 11 Memory Management
Main Memory Management
Chapter 8: Main Memory.
Operating System Concepts
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Winter 2004 Module 10.5 Segmentation
CSE 451: Operating Systems Autumn 2004 Memory Management
CSE 451: Operating Systems Winter 2007 Module 10 Memory Management
Chapter 8: Memory Management strategies
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2009 Module 10 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management CSE451 Andrew Whitaker.
CSE 451: Operating Systems Winter 2004 Module 10 Memory Management
Paging and Segmentation
CS703 - Advanced Operating Systems
CSE451 Operating Systems Winter 2009
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CSE 451: Operating Systems Autumn 2010 Module 10 Memory Management
Page Main Memory.
Presentation transcript:

by Teacher Asma Aleisa Year 1433 H

  Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory resources among computing.  processes to maximize performance with minimal overhead.  Mechanisms  Physical and virtual addressing (1)  Techniques: Partitioning, paging, segmentation (1)  Page table management, TLBs, VM tricks (2)  Policies  Page replacement algorithmes (3) 2

  Virtual (logical) and physical memory address.  Survey techniques for implementing virtual memory : Fixed and variable partitioning. Paging. Segmentation. 3

  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.

  Hardware device that maps virtual to physical address  The user program deals with logical addresses; it never sees the real physical addresses

  OS provides Virtual Memory (VM) as the abstraction for managing memory Indirection allows moving programs around in memory. Allows processes to address more or less memory than physically installed in the machine :  Virtual memory enables a program to execute with less than its complete data in physical memory  Many programs do not need all of their code and data at once (or ever) - no need to allocate memory for it  OS adjusts amount of memory allocated based upon behavior Requires hardware support for efficient implementation Let’s go back to the beginning…

  Rewind to the days of batch programming  Programs use physical addresses directly.  OS loads job, runs it, unloads it.  Multiprogramming changes all of this Want multiple processes in memory at once : o Overlap I/O and CPU of multiple jobs Can do it a number of ways: o Fixed and variable partitioning, paging, segmentation.  Requirements » Need protection - restrict which addresses jobs can use » Fast translation - lookups need to be fast » Fast change - updating memory hardware on context switch

  To make it easier to manage the memory of processes running in the system, we’re going to make them use virtual addresses (logical addresses)  Virtual addresses are independent of the actual physical location of the data referenced  OS determines location of data in physical memory  Instructions executed by the CPU issue virtual addresses  Virtual addresses are translated by hardware into physical addresses (with help from OS)  The set of virtual addresses that can be used by a process comprises its virtual address space  Many ways to do this translation…  Start with old, simple ways, progress to current techniques

  Physical memory is broken up into fixed partitions  Hardware requirements: base register  Physical address = virtual address + base register  Base register loaded by OS when it switches to a process  Size of each partition is the same and fixed  How do we provide protection?  Advantages Easy to implement, fast context switch  Problems  Internal fragmentation: memory in a partition not used by a process is not available to other processes  Partition size: one size does not fit all (very large processes?)

 Internal fragmentation Any program, no matter how small, occupies an entire partition.

 P1 P2 P3 P5 P4 Physical Memory Base Register P4’s Base Offset Virtual Address +

  Natural extension -- physical memory is broken up into variable sized partitions  Hardware requirements: base register and limit register  Physical address = virtual address + base register  Why do we need the limit register? Protection  If (physical address > base + limit) then exception fault  Advantages:  No internal fragmentation: allocate just enough for process  Problems:  External fragmentation: job loading and unloading produces empty holes scattered throughout memory

 P1 P2 P3 Physical Memory P3’s Base P3’s Limit Offset Limit Register Virtual Address Protection Fault < Yes? No? + Base Register

 15 External fragmentation Job loading and unloading produce holes in the memory.

 P1 P2 P3 P n Physical Memory  Paging solves the external fragmentation problem by using fixed sized units in both physical and virtual memory called CHUNKS. Virtual Memory

 17  Partition memory into small equal fixed-size chunks and divide each process into the same size chunks.  The chunks of a process are called pages and chunks of memory are called frames.  Operating system maintains a page table for each process.  Contains the frame location for each page in the process.  Memory address consist of a page number and offset within the page

  Translating addresses :  Virtual address has two parts: page number and offset.  page number is an index into a page table.  Page table determines page frame number (PFN)  Physical address is PFN::offset  Page tables:  Map page number to page frame number.

 (virtual) p: page number d: offset. f: frame number

 Page numberOffset Physical Address Page frame Virtual Address Page Table Physical Memory

 21

 22

 23

  Page table entries control mapping  The Modify bit says whether or not the page has been written  It is set to (1) when a write to the page occurs  The Reference bit says whether the page has been accessed  It is set to (1) when a read or write to the page occurs  The Valid bit says whether or not the PTE can be used  It is checked each time the virtual address is used  The Protection bits say what operations are allowed on page  Read (R), write (W), execute (X)  The page frame number (PFN) determines physical page MRV Protection Page Frame Number

  Easy to allocate memory:  Memory comes from a free list of fixed size chunks  Allocating a page is just removing it from the list External fragmentation not a problem  Easy to swap out chunks of a program:  All chunks are the same size.  Use valid bit to detect references to swapped pages  Pages are a convenient multiple of the disk block size

  Can still have internal fragmentation  Process may not use memory in multiples of a page  Memory reference overhead  lookup (page table, then memory)  More memory spaces required to hold page table.

 19  Segmentation is a technique that partitions memory into logically related data units  A segment is a logical unit such as:  main program,  procedure,  function,  object,  array,  local variable,  file,  Stack physical memory space Logical address

 19  Virtual addresses become  Units of memory from user’s perspective  Natural extension of variable-sized partitions  Variable-sized partitions = 1 segment/process  Segmentation = many segments/process  Hardware support  Multiple base/limit pairs, one per segment (segment table)  Segments named by #, used to index into table

 < + Segment Table Physical Memory Physical Fault No? Yes? Segment #Offset Virtual Address limit base

  Extensions  Can have one segment table per process  Segment #s are then process-relative (why do this?)  Can easily share memory  Put same translation into base/limit pair  Can share with different protections (same base/limit, diff protection)  Problems  Cross-segment addresses  Segments need to have same #s for pointers to them to be shared among processes  Large segment tables  Keep in main memory, use hardware cache for speed

  Can combine segmentation and paging  The x86 supports segments and paging  Use segments to manage logically related units  Module, procedure, stack, file, data, etc.  Segments vary in size, but usually large (multiple pages)  Use pages to partition segments into fixed size chunks  Makes segments easier to manage within physical memory  Segments become “pageable” - rather than moving segments into and out of memory, just move page portions of segment  Need to allocate page table entries only for those pieces of the segments that have themselves been allocated  Tends to be complex…

  Virtual memory  Processes use virtual addresses  OS + hardware translates virtual address into physical addresses  Various techniques  Fixed partitions - easy to use, but internal fragmentation  Variable partitions - more efficient, but external fragmentation  Paging - use small, fixed size chunks, efficient for OS Segmentation - manage in chunks from user’s perspective  Combine paging and segmentation to get benefits of both