CS307 Operating Systems Main Memory

Similar documents
CS307: Operating Systems

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Chapter 8: Memory-Management Strategies

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

CS3600 SYSTEMS AND NETWORKS

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Chapter 8: Main Memory

Memory Management. Memory Management

Chapter 8: Main Memory

Chapter 8: Main Memory

Chapter 9: Memory Management. Background

Chapter 8: Memory Management Strategies

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation

Chapter 8: Main Memory

Goals of Memory Management

Module 8: Memory Management

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

Chapter 8: Memory Management

Module 8: Memory Management

Chapter 8 Main Memory

Memory Management. Memory

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science

Logical versus Physical Address Space

Main Memory (Part II)

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

Lecture 8 Memory Management Strategies (chapter 8)

Chapter 8 Memory Management

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Memory Management. Contents: Memory Management. How to generate code? Background

CS370 Operating Systems

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

CSE 4/521 Introduction to Operating Systems. Lecture 14 Main Memory III (Paging, Structure of Page Table) Summer 2018

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

Principles of Operating Systems

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

SHANDONG UNIVERSITY 1

Background. Contiguous Memory Allocation

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

CS370 Operating Systems

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

CS 3733 Operating Systems:

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University

The Memory Management Unit. Operating Systems. Autumn CS4023

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Memory Management. Dr. Yingwu Zhu

P r a t t hr h ee e : e M e M m e o m r o y y M a M n a a n g a e g m e e m n e t 8.1/72

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

CS420: Operating Systems

Main Memory (Part I)

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

Main Memory (II) Operating Systems. Autumn CS4023

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

Memory Management. Dr. Yingwu Zhu

Chapter 9 Memory Management

Introduction to Operating Systems

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

Basic Memory Management

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Chapter 8: Memory Management

COSC Operating Systems Design, Fall 2001, Byunggu Yu. Chapter 9 Memory Management (Lecture Note #8) 1. Background

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 8: Main Memory. Operating System Concepts 8th Edition

Page Table Structure. Hierarchical Paging. Hashed Page Tables. Inverted Page Tables

CS420: Operating Systems. Paging and Page Tables

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

CS399 New Beginnings. Jonathan Walpole

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Memory Management (1) Memory Management

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

UNIT-III VIRTUAL MEMORY

Memory: Page Table Structure. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Fall 2015 COMP Operating Systems. Lab 06

Operating Systems Unit 6. Memory Management

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Memory Management (2)

Memory Management. Goals of Memory Management. Mechanism. Policies

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Virtual to physical address translation

Transcription:

CS307 Main Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018

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 storage CPU can access directly Register access in one CPU clock cycle Main memory can take many cycles Memory unit only sees a stream of addresses + read requests, or address + data and write requests Protection of memory required to ensure correct operation 2

Base and Limit Registers A pair of base and limit registers define the physical address space 3

Hardware Address Protection 4

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 memory unit Logical address space is the set of all logical addresses generated by a program Physical address space is the set of all physical addresses generated by a program 7

Memory-Management Unit (MMU) Hardware device that at run time maps logical to physical address Many methods possible, covered in the rest of this chapter To start, consider a simple scheme where the value in the relocation register is added to every address generated by a user process at the time it is sent to memory Base register now called relocation register The user program deals with logical addresses; it never sees the real physical addresses Execution-time binding occurs when reference is made to location in memory Logical address bound to physical addresses 8

Dynamic Relocation using a Relocation Register 9

Memory Management Contiguous memory allocation Non-contiguous memory allocation Paging 15

Contiguous Allocation Each process is contained in a single contiguous section of memory 0 Main memory usually contains two partitions: Resident operating system, usually held in low memory with interrupt vector User processes then held in high memory Relocation registers used to protect user processes from each other, and from changing operating-system code and data Base register contains value of smallest physical address Limit register contains range of logical addresses each logical address must be less than the limit register MAX 16

Hardware Support for Relocation and Limit Registers 17

Contiguous Allocation (Cont.) Multiple-partition allocation Degree of multiprogramming limited by number of partitions 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 Process exiting frees its partition, adjacent free partitions combined 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 10 process 2 process 2 process 2 process 2 18

Dynamic Storage-Allocation Problem How to satisfy a request of size n from a list of free holes? 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 First-fit and best-fit better than worst-fit in terms of speed and storage utilization 19

Fragmentation External Fragmentation total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used First fit analysis reveals that given N blocks allocated, another 0.5 N blocks lost to fragmentation 1/3 may be unusable -> 50-percent rule 20

Fragmentation (Cont.) Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time Another solution to permit the logical address space of the processes to be noncontiguous paging segmentation 21

Paging Physical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available Divide physical memory into fixed-sized blocks called frames Size is power of 2, between 512 bytes and 16 Mbytes Divide logical memory into blocks of same size called pages Keep track of all free frames To run a program of size N pages, need to find up to N free frames and load program Set up a page table to translate logical to physical addresses Still have Internal fragmentation 22

Paging Model of Logical and Physical Memory Page Frame 23

Address Translation Scheme Address generated by CPU is divided into: Page number (p) used as an index into a page table, which contains base address of each page in physical memory Page offset (d) combined with base address to define the physical memory address that is sent to the memory unit page number p m - n page offset d n For given logical address space 2 m and page size 2 n 24

Paging Hardware 25

Paging Example 0 1 Page Frame 0 1 2 3 2 3 4 5 What character does the following logical addresses map to? (A) 10 = 10 10 (B) 5 = 01 01 (C) 14 = 11 10 6 7 n=2 and m=4 32-byte memory and 4-byte pages 26

Paging (Cont.) Calculating internal fragmentation Page size = 2,048 bytes Process size = 72,766 bytes 35 pages + 1,086 bytes Internal fragmentation of 2,048-1,086 = 962 bytes Internal fragmentation Worst case fragmentation = frame size 1 byte On average fragmentation = 1 / 2 frame size Calculate the page numbers and offsets for the following address, when page size is 1KB: 2375 = 1024 * 2 + 327 19366 = 1024 * 18 + 934 27

Free Frames Before allocation After allocation 28

Implementation of Page Table Page table is kept in main memory Page-table base register (PTBR) points to the page table Page-table length register (PTLR) indicates size of the page table In this scheme every data/instruction access requires two memory accesses One for the page table and one for the data / instruction The two memory access problem can be solved by the use of a special fastlookup hardware cache called associative memory or translation lookaside buffers (TLBs) TLBs typically small (64 to 1,024 entries) On a TLB miss, value is loaded into the TLB for faster access next time Replacement policies must be considered Some entries can be wired down for permanent fast access 29

Paging Hardware With TLB 31

Effective Access Time Associative Lookup = time unit Hit ratio = Hit ratio percentage of times that a page number is found in the associative registers; ratio related to number of associative registers Consider = 80% Effective Access Time (EAT) EAT = (1 + ) + (2 + )(1 ) = 2 + When = 80%, = 20ns for TLB search, 100ns for 1 memory access time unit EAT = 120 x 0.80 + 220 x 0.20 = 140ns 32

Structure of the Page Table Memory structures for paging can get huge using straight-forward methods Consider a 32-bit logical address space as on modern computers Page size of 4 KB (2 12 ) Page table would have 1 million entries (2 32 / 2 12 ) If each entry is 4 bytes -> 4 MB of physical address space / memory for page table alone That amount of memory used to cost a lot Don t want to allocate that contiguously in main memory Hierarchical Paging Hashed Page Tables Inverted Page Tables 37

Hierarchical Page Tables Break up the logical address space into multiple page tables A simple technique is a two-level page table We then page the page table 38

Two-Level Page-Table Scheme inner page table 39

Two-Level Paging Example A logical address (on 32-bit machine with 4K page size) is divided into: a page number consisting of 20 bits a page offset consisting of 12 bits Since the page table is paged, the page number is further divided into: a 10-bit page number a 10-bit page offset Thus, a logical address is as follows: page number page offset p 1 p 2 d 10 10 12 where p 1 is an index into the outer page table, and p 2 is the offset within the page of the inner page table Known as forward-mapped page table 40

Address-Translation Scheme 41

Three-level Paging Scheme 43

Hashed Page Tables Common in address spaces > 32 bits The virtual page number is hashed into a page table This page table contains a chain of elements hashed to the same location Each element contains (1) the virtual page number (2) the address of the mapped page frame (3) a pointer to the next element Virtual page numbers are compared in this chain searching for a match If a match is found, the corresponding physical frame is extracted 44

Hashed Page Table 45

Inverted Page Table Rather than each process having a page table and keeping track of all possible logical pages, track all physical pages One entry for each real frame of memory Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs Use hash table to limit the search to one or at most a few page-table entries TLB can accelerate access 46

Inverted Page Table Architecture 47

Segmentation Memory-management scheme that supports user view of memory A program is a collection of segments A segment is a logical unit such as: main program procedure function method object local variables, global variables common block stack symbol table arrays 48

User s View of a Program 49

Example of Segmentation 50

Segmentation Architecture Logical address consists of a two tuple: <segment-number, offset>, Segment table maps two-dimensional physical 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 51

Segmentation Hardware 53

Pop-Quiz Consider a 32-bits logical address space Two-level page table 4K page size 10-bit page number 10-bit page offset each entry is 4 bytes page number page offset p 1 p 2 d 10 10 12 Question: How much space is needed to store the page table? 60

Homework Reading Chapter 8 61