Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging



Similar documents
The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

OPERATING SYSTEM - MEMORY MANAGEMENT

OPERATING SYSTEMS MEMORY MANAGEMENT

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

W4118: segmentation and paging. Instructor: Junfeng Yang

Operating Systems, 6 th ed. Test Bank Chapter 7

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

Chapter 7 Memory Management

Chapter 7 Memory Management

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

Lecture 17: Virtual Memory II. Goals of virtual memory

Virtual vs Physical Addresses

COS 318: Operating Systems. Virtual Memory and Address Translation

Chapter 12. Paging an Virtual Memory Systems

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

How To Write A Page Table

Chapter 11: File System Implementation. Chapter 11: File System Implementation. Objectives. File-System Structure

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Outline: Operating Systems

Operating System Tutorial

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

HY345 Operating Systems

Board Notes on Virtual Memory

CS5460: Operating Systems

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Segmentation Segmentation: Generalized Base/Bounds

Chapter 11: File System Implementation. Operating System Concepts with Java 8 th Edition

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

Operating Systems. Virtual Memory

OPERATING SYSTEM - VIRTUAL MEMORY

Chapter 1 Computer System Overview

CHAPTER 17: File Management

Chapter 11: File System Implementation. Operating System Concepts 8 th Edition

CS5460: Operating Systems. Lecture: Virtualization 2. Anton Burtsev March, 2013

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

W4118 Operating Systems. Instructor: Junfeng Yang

Computer Architecture

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Virtual Machines. COMP 3361: Operating Systems I Winter

Paging: Introduction A Simple Example And Overview

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Hardware Assisted Virtualization

COS 318: Operating Systems. Virtual Machine Monitors

High-Performance Processing of Large Data Sets via Memory Mapping A Case Study in R and C++

Disk Space Management Methods

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

WHITE PAPER. AMD-V Nested Paging. AMD-V Nested Paging. Issue Date: July, 2008 Revision: 1.0. Advanced Micro Devices, Inc.

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Peter J. Denning, Naval Postgraduate School, Monterey, California

VIRTUAL MEMORY IN CONTEMPORARY MICROPROCESSORS

Keil C51 Cross Compiler

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

CHAPTER 6 TASK MANAGEMENT

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Computer-System Architecture

File System Management

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

A3 Computer Architecture

Recommended hardware system configurations for ANSYS users

Chapter 5 Cloud Resource Virtualization

Chapter 6, The Operating System Machine Level

The Classical Architecture. Storage 1 / 36

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

Chapter 12 File Management

COS 318: Operating Systems

File Systems Management and Examples

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Rethinking SIMD Vectorization for In-Memory Databases

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Addendum Intel Architecture Software Developer s Manual

Chapter 13: Query Processing. Basic Steps in Query Processing

Segmentation and Fragmentation

This tutorial will take you through step by step approach while learning Operating System concepts.

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Topics in Computer System Performance and Reliability: Storage Systems!

361 Computer Architecture Lecture 14: Cache Memory

Chapter 1 13 Essay Question Review

Part III Storage Management. Chapter 11: File System Implementation

File Management Chapters 10, 11, 12

1 File Management. 1.1 Naming. COMP 242 Class Notes Section 6: File Management

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

Original-page small file oriented EXT3 file storage system

Chapter 11 I/O Management and Disk Scheduling

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Data Storage - I: Memory Hierarchies & Disks

Memories Are Made of This

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

Transcription:

Memory Management Outline Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging 1

Background Memory is a large array of bytes memory and registers are only storage CPU can access directly both instructions and data are fetched from memory memory unit just sees a stream on memory addresses Accessing memory is slow (why?) register access in one CPU clock (or less) cache sits between main memory and CPU registers Protection of memory required to ensure correct operation isolate processes from one another and from the OS 2

Process Protection in Hardware Protect OS from user processes and processes from each other give each process separate space determine legal range of addresses for each process A pair of base and limit registers define the process address space. CPU compares each address generated by the process with the base and limit registers. 3

Address Binding Address binding of instructions and data to memory addresses can happen at three different stages compile time: If memory location known a priori, absolute code can be generated load time: Must generate relocatable code if memory location is not known at compile time must recompile code if starting location changes code can be placed anywhere in memory 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) 4

Multistep Processing of User Program 5

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 hardware memory unit Logical and physical addresses are the same in compile- time and load-time address-binding schemes. Logical and physical addresses differ in execution-time address-binding scheme. 6

Memory-Management Unit (MMU) Hardware device that maps virtual to physical address. Simple MMU scheme start each process's logical address from 0 base memory address for each process stored in relocation register max. process address stored in limit register relocation register added to every logical address logical: 0 max correspond to physical: R+0 R+limit 7

Dynamic Loading Static loading entire program in memory before program starts program size limited by size of memory 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 8

Dynamic Linking Static linking library modules considered as any other object files linker/loader combines libraries into every binary image in which they may be referenced multiple copies of library code may reside in memory at a time Dynamic linking linking postponed until execution time small piece of code, stub, used to locate the appropriate memoryresident library routine stub replaces itself with the address of the routine OS checks if routine is in processes memory address only one copy of libraries resident in memory at a time such a library is called a shared library 9

Swapping What is swapping? moving a process currently resident in memory to a backing store and swapping another process into the freed space swap individual pages of the same process in-out of memory When is swapping needed? if there is no free memory for the new process dispatched by the scheduler if some process needs more physical memory than is available Backing store is generally maintained on disk swapping is costly if swapped out memory needs to be brought back in immediately all the time, then it will lead to memory thrashing See 'top' and 'swapon -s' under Linux. 10

Schematic View of Swapping 11

Contiguous Memory Allocation Efficient allocation of main memory is important memory is limited in size contains the OS and multiple concurrently active user processes Main memory usually divided into two partitions: resident operating system, usually held in low memory with interrupt vector user processes then held in high memory Contiguous memory allocation each process in a single contiguous region of memory allows multiple processes to reside in memory at the same time processes must be protected from each other! 12

Hardware Support for Protection Relocation and limit registers used to protection of user processes from each other, and operating system from the user processes Hardware checks base register contains value of smallest physical address each logical address must be less than the limit register MMU maps logical address dynamically 13

Contiguous Memory Allocation (2) Multiple-partition method hole block of available memory holes of various size are scattered throughout memory when a process arrives, it is allocated memory from a hole large enough to accommodate it operating system maintains information about: a) allocated partitions b) free partitions (hole) OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 2 process 10 process 2 process 2 process 2 14

Dynamic Storage-Allocation Problem Given a list of variable-sized holes, how to allocate memory for a new arriving process of some size, n Memory allocation schemes 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 Performance first-fit and best-fit better than worst-fit in terms of performance and storage requirement first-fit generally the fastest 15

Fragmentation External Fragmentation total memory space exists to satisfy a request, but it is not contiguous 50-percent rule given N allocated blocks, 0.5N blocks will be lost to fragmentation Solutions to external fragmentation compaction move allocated blocks to place all holes together compaction is possible only if relocation is dynamic permit non-contiguous allocation of logical address space Internal Fragmentation occurs with fixed sized blocks used to reduce cost of managing extremely small holes size of last block may be slightly larger than requested memory what is the greatest memory loss due to internal fragmentation?16

Paging Solution to external fragmentation and compaction logical address space of a process can be noncontiguous commonly used in most OS frequently depend on hardware support Scheme divide physical memory into fixed-sized blocks called frames size is generally power of 2, between 512 bytes and 8,192 bytes divide logical memory into blocks of same size called pages OS keeps track of all free frames a program of size n pages, needs n free frames before loading needs a page table to translate logical to physical addresses Problem of internal fragmentation still exists 17

Address Translation Scheme Hardware defines the page size (and frame size). Page size, d, determines the number of bits required to specify the page offset, n. How? d = 2n The remaining bits in the logical address specify the page number, p. For logical address space, 2m, and page size 2n, page number page offset p d m-n n 18

Paging Hardware 19

Paging Model of Logical and Physical Memory 20

Paging Example 32-byte memory and 4-byte pages Logical Address Physical Address 0 (5*4)+0 = 20 1 (5*4)+1 = 21 5 (6*4)+1 = 25 10?? 15?? 21

Free Frames Before allocation After allocation 22

Page Table Issues Small or large page size? small page size reduces internal fragmentation loss, how? large page size reduces size of page table, how? larger transfers produces more efficient disk transfers Each memory load/store goes through page table page table access must be fast store page tables in hardware registers only possible for small tables, up to 256 entries! Each process has its own page table page table switching on each context switch must be fast Most computers allow large page tables page table is kept in main memory single register points to page table address in memory 23

Page Table Implementation Page-table base register (PTBR) points to page table only this register affected on each context switch Every load/store requires two memory accesses one for the page table and one for the data/instruction Translation look-aside buffer (TLB) cache to hold popular page table entries access to TLB should be very fast, use associative cache However, each process has its own page table on a context switch, OS changes PTBR pointer and, may need to purge the TLB use address-space identifiers (ASIDs) in each TLB entry uniquely identifies each process to provide address-space protection for that process 24

Paging Hardware With TLB 25

Memory Protection Memory protection implemented by associating protection bit with each frame Valid-invalid bit attached to each entry in the page table: valid indicates that the associated page is in the process logical address space, and is thus a legal page invalid indicates that the page is not in the process logical address space 26

Memory Protection (2) Scheme 14 bit address space Program uses addresses 0 10468 Page size of 2kb Accessing addresses on pages 6 and 7 is invalid segmentation fault Problems addresses 10469 12287 are still valid page table still contains all rows use page table length register 27

Shared Pages Shared code Paging allows the possibility of easily sharing code one copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems) each process has private data significant reduction in memory usage possible Example 3 code pages shared each process has private data 28

Structure of the Page Table Hierarchical Paging Hashed Page Tables Inverted Page Tables 29

Hierarchical Page Tables Sometimes necessary to divide page table into pieces to support a large logical address space (232 to 264) example: for page size of 4kb, page table has 220 entries contiguous allocation of big page tables not feasible Two-level page table (paged page-table) further divide the page number field p1 index into outer page table p2 displacement within outer page table page number pi p2 10 10 page offset d 12 30

Two-Level Page-Table Scheme 31

Address-Translation Scheme for Two-Level Paging 32

More Levels in Hierarchical Mapping Two level scheme not appropriate for 64-bit machine divide the outer page table further Even three-level scheme is daunting outer page table still 234 bytes in size We can go on increasing the number of paging levels but, each level requires a memory access two-level page table requires three memory accesses for each load/store n-level requires n+1 memory accesses! need another page table implementation... 33

Hashed Page Tables Common in address spaces > 32 bits virtual page number is the hash Each hash table entry contains a linked list of elements Each element contains virtual page number value of mapped page frame next pointer Algorithm hash virtual page number into hash table compare with each element in linked list until match is found use corresponding page frame to form physical address 34

Hashed Page Tables (2) 35

Inverted Page Table Attempt to overcome drawbacks of traditional page tables machines with large virtual address spaces have huge tables consume lot of memory Inverted page table approach table contains one entry for each real page of memory entry consists of the virtual address of the also contains information on process that owns that page see figure on next page Decreases memory needed to store each page table, but linear search of table needed to find physical mapping substantial increase in search time for every memory access Use hash table to limit the search to one, or few page-table entries 36

Inverted Page Table (2) 37

Segmentation Memory-management scheme that supports user view of memory a program is a collection of segments 1 4 1 2 3 4 2 3 user space physical memory space 38

Segmentation Architecture Logical address consists of a two tuple: <segment-number, offset> Segment table maps two-dimensional logical 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; segment number s is legal if s < STLR 39

Segmentation Architecture (2) 40

Example of Segmentation 41

Example: The Intel Pentium Supports both segmentation and segmentation with paging CPU generates logical address given to segmentation unit which produces linear addresses linear address given to paging unit which generates physical address in main memory paging units form equivalent of MMU 42

Intel Pentium Segmentation 32-bit architecture Max. number of segments 16K 8k segments in local descriptor table (LDT) 8k segments in global descriptor table (GDT) Max. size of segment 4GB Each segment descriptor is 8 bytes contains segment base and limit Each logical address is 48 bits 16 bit segment selector, 32 bit offset 16 bit segment selector contains 13 bit segment number, 1 bit table identifier, 2 bits of protection Maps 48 bit logical address to 32 bit linear address 43

Intel Pentium Segmentation (2) 44

Pentium Paging Architecture Page size 4kb or 4mb For 4kb pages two level paging scheme base of page directory pointed to by CR3 register 10 high-order bits offset into the page directory page directory gives base of inner page table inner page table indexed by middle 10 bits of linear address page table returns base of page low-order 12 bits of linear address used to offset page 45

Pentium Paging Architecture (2) 46