CS 104 Introduction to Computer Science and Graphics Problems

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Memory Management Chapter 7.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management.
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.
Chapter 8 Main Memory Bernard Chen Spring Objectives To provide a detailed description of various ways of organizing memory hardware To discuss.
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.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Memory management  swapping  contiguous allocation  paging  segmentation  segmentation.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
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.
Example of a Resource Allocation Graph CS1252-OPERATING SYSTEM UNIT III1.
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.
Operating Systems Chapter 8
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Exam2 Review Bernard Chen Spring Deadlock Example semaphores A and B, initialized to 1 P0 P1 wait (A); wait(B) wait (B); wait(A)
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.
Subject: Operating System.
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.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
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 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory Management.
Chapter 8: Main Memory.
Chapter 8: Main Memory.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
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.
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:

CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (3) Memory Management 10/07 ~ 10/10/2008 Yang Song (Prepared by Yang Song and Dr. Hung)

The Fundamental Functions Process Management Memory Management File Management Input / Output Networking Utility Services

Memory Management Memory management and CPU scheduling are perhaps the two most central tasks of an OS memory consists of a large array of words, each with its own address both program and data are stored in memory CPU fetch-execute cycle fetch next instruction from memory (based on program counter) decode the instruction possibly fetch operands from memory execute the instruction store the result in memory Memory is given an address and it returns a value it does not distinguish between instructions and data it does not care how the address was arrived at

Address Binding Users do not (cannot?) think about real addresses user processes go through several steps before execution (e.g., compilation, loading, linking, …) addresses may be represented in different ways during these steps (symbol, relocatable addr, …) Instructions/data may be bound to real addresses: at compile time: compiler substitutes actual addresses in executable used in MS-DOS at load time: compiler generates relocatable code, final binding is delayed until load time once loaded in memory and process starts, bindings are locked in – not generally used at execution time: if process can be moved during its execution, then binding must be delayed until run time requires special hardware support – used in most general-purpose OS's

Logical vs. Physical Address The concept of a logical address space that is mapped to a physical address space is central to memory management CPU works in a logical (virtual) address space users, processes, instruction operands, program counter refer to logical addresses memory is a physical address space real memory accesses require real addresses Memory Management Unit (MMU) maps logical addresses to physical addresses implemented in hardware for example, might have a relocation register that provides the base address for a process' block of physical memory

Contiguous Memory Allocation Main memory must accommodate both the OS and user processes usually divided into two partitions: OS & interrupt vector in low memory, user processes in high memory contiguous memory allocation places each process in a single, contiguous section of memory OPTION 1: single partition (all processes share same memory space) relocation-register scheme used to protect user processes from each other, and from changing OS code and data relocation register contains smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register

Contiguous Memory Allocation OPTION 2: multiple partitions (each process has its own partition) process memory time P1 600K 10 P2 1000K 5 P3 300K 20 P4 700K 8 P5 500K 15 OS 400K OS P2 400K 2560K 1000K 2000K 2300K P1 P3 OS 400K 2560K 1000K 2000K 2300K P1 P3 OS P4 400K 2560K 1000K 2000K 2300K P1 P3 1700K

Dynamic Storage Allocation Problem as processes free up holes in memory and new processes request memory, how do you allocate partitions? first-fit: allocate the first hole that is big enough best-fit: allocate the smallest hole that is big enough must search the entire list of holes unless ordered by size produces the smallest leftover hole worst-fit: allocate the largest hole available also must search the entire list of holes produces the largest leftover hole process memory time P1 600K 10 P2 1000K 5 P3 300K 20 P4 200K 8 P5 100K 15 OS 400K 2560K 1000K 2000K 2300K P1 P3 first-fit is fast best-fit tends to work better for storage utilization

Fragmentation With dynamic storage allocation, fragmentation can be a problem there may be many small holes, none big enough to fit a process compaction is needed to coalesce holes (similar to defragging a hard drive) note: compaction is possible only if bindings are done at execution time process memory time P1 600K 10 P2 1000K 5 P3 300K 20 P4 1200K 8 OS 400K 2560K 1000K 2000K 2300K P1 P3 1300K

Paging Paging is one solution to the external fragmentation problem Non-contiguous storage allocation – a process is allocated physical memory wherever it is available divide the physical memory into fixed-size blocks called frames (size is a power of 2, generally between 512 and 8K bytes) divide logical memory into blocks of the same size called pages to run a process of size n pages, need to find n free frames and load Paging requires hardware support every logical address generated by the CPU is divided into: page number (p): used as an index into a page table containing the base address of each page in physical memory page offset (d): combined with base address to determine the physical memory address

Paging Examples abstract example: tiny (but concrete) example: page size = 4 bytes physical memory = 32 bytes abstract example: 4 pages in logical address space page table maps to physical frames

Page Fault If the process references a logical page that is not in physical memory: memory management unit checks page table page fault exception is raised due to invalid bit OS must locate logical page in secondary memory schedules a disk operation to swap into memory at disk interrupt, swaps page into a free frame sets valid bit in page table restarts instruction

Page Replacement Algorithms Page replacement completes separation between logical & physical memory large virtual memory can be provided on a smaller physical memory choices as to which pages are swapped in and out of memory have significant impact on effective access time we want page replacement algorithms that minimize the page fault rate

First-In-First-Out (FIFO) Algorithm Select as victim the page that has been in memory the longest i.e., treat frame set as a queue, replace pages in FIFO order simple, but not very effective in practice doesn't favor pages that are used often (e.g., contains frequently used variable) example: suppose 3 pages can be in memory at a time per process process references pages: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 requires 15 page faults

Optimal Algorithm Select as victim the page that will not be used for the longest time Same reference string requires only 9 page faults (compared with 15 for FIFO)

Least Recently Used (LRU) Algorithm OPT is not practical since it requires future knowledge However, we can approximate OPT under certain assumptions if we use the recent past as an approximation of the near future, then will select as victim the page that has been used least recently LRU works well in practice