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

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

Chapter 8: Main Memory

Chapter 8: Main Memory

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

Chapter 8: Memory Management Strategies

Memory Management. Memory Management

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

Module 8: Memory Management

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

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

Goals of Memory Management

Chapter 9: Memory Management. Background

Module 8: Memory Management

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

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

Chapter 8: Memory Management

Logical versus Physical Address Space

The Memory Management Unit. Operating Systems. Autumn CS4023

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

Chapter 8: Memory Management

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

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

Background. Contiguous Memory Allocation

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

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

Chapter 8: Memory- Management Strategies

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

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

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

Chapter 8: Main Memory

CS307: Operating Systems

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

CS307 Operating Systems Main Memory

Chapter 8: Main Memory

Main Memory (Part I)

Chapter 8: Memory-Management Strategies

CS420: Operating Systems

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

Principles of Operating Systems

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

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

Lecture 8 Memory Management Strategies (chapter 8)

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

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

Chapters 9 & 10: Memory Management and Virtual Memory

CS370 Operating Systems

SHANDONG UNIVERSITY 1

Chapter 8 Memory Management

Virtual Memory - I. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XV. University at Buffalo.

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

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Memory Management. Memory

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

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

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

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

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XI Deadlocks - II. University at Buffalo. Deadlocks. October 6 th, 2011

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

Introduction to Operating Systems

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

Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut

3. Memory Management

CS 3733 Operating Systems:

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

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Frequently asked questions from the previous class survey

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

Memory Management and Protection

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

Process. Memory Management

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

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

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

CSE 421/521 - Operating Systems Fall Lecture - XIX. File Systems. University at Buffalo

CS3600 SYSTEMS AND NETWORKS

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

Memory Management 9th Week

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

Main Memory (II) Operating Systems. Autumn CS4023

Chapter 8 Main Memory

Process. One or more threads of execution Resources required for execution

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

Memory Management. Dr. Yingwu Zhu

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

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

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

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

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

Course: Operating Systems Instructor: M Umair. M Umair

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

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Basic Memory Management

CS420: Operating Systems. Paging and Page Tables

12: Memory Management

Transcription:

CSE 421/521 - Operating Systems Fall 2012 Lecture - XII Main Memory Management Tevfik Koşar University at Buffalo October 18 th, 2012 1 Roadmap Main Memory Management Fixed and Dynamic Memory Allocation External and Internal Fragmentation Address Binding HW Address Protection Paging Segmentation 2

Memory Management Requirements! The O/S must fit multiple processes in memory " memory needs to be subdivided to accommodate multiple processes " memory needs to be allocated to ensure a reasonable supply of ready processes so that the CPU is never idle " memory management is an optimization task under constraints Fitting processes into memory is like fitting boxes into a fixed amount of space 3 Memory Allocation Fixed-partition allocation Divide memory into fixed-size partitions Each partition contains exactly one process The degree of multi programming is bound by the number of partitions When a process terminates, the partition becomes available for other processes OS process 5 process 9 process 10 process 2 #no longer in use 28

Memory Allocation (Cont.) Variable-partition Scheme (Dynamic) When a process arrives, search for a hole large enough for this process Hole block of available memory; holes of various size are scattered throughout memory Allocate only as much memory as needed Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 OS process 5 process 9 OS process 5 process 9 process 10 process 2 process 2 process 2 29 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 is faster. Best-fit is better in terms of storage utilization. Worst-fit may lead less fragmentation. 30

Example 7 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 is faster. Best-fit is better in terms of storage utilization. Worst-fit may lead less fragmentation. 30

Fragmentation External Fragmentation total memory space exists to satisfy a request, but it is not contiguous (in average ~50% lost) Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used 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 32 Address Binding Addresses in a source program are generally symbolic eg. int count; A compiler binds these symbolic addresses to relocatable addresses eg. 100 bytes from the beginning of this module The linkage editor or loader will in turn bind the relocatable addresses to absolute addresses eg. 74014 Each binding is mapping from one address space to another 10

Each process has a separate memory space Two registers provide address protection between processes: Base register: smallest legal address space Limit register: size of the legal range Logical Address Space 11 Memory-Management Unit (MMU) Hardware device that maps logical to physical address In MMU scheme, the value in the relocation register (base register) is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses 12

HW Address Protection CPU hardware compares every address generated in user mode with the registers Any attempt to access other processes memory will be trapped and cause a fatal error 13 Paging - noncontiguous Physical address space of a process can be noncontiguous Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 16 megabytes) 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 n free frames and load program Set up a page table to translate logical to physical addresses Internal fragmentation 37

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 38 Address Translation Architecture 39

Paging Example 40 Paging Example 41

Free Frames Before allocation After allocation 42 Shared Pages Shared code One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems). Shared code must appear in same location in the logical address space of all processes Private code and data Each process keeps a separate copy of the code and data The pages for the private code and data can appear anywhere in the logical address space 22

Shared Pages Example 23 User s View of a Program 24

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 25 Logical View of Segmentation 1 1 4 2 3 4 2 3 user space physical memory space 26

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 the length (limit) of the segment segment addressing is d (offset) < STLR Segmentation Architecture (Cont.) Protection. With each entry in segment table associate: validation bit = 0 illegal segment read/write/execute privileges Protection bits associated with segments; code sharing occurs at segment level Since segments vary in length, memory allocation is a dynamic storage-allocation problem A segmentation example is shown in the following diagram

Address Translation Architecture Example of Segmentation

Consider the following segment table:!! Segment! Base!! Length!! 0!! 219!! 600!! 1!! 2300!! 14!! 2!! 90!! 100!! 3!! 1327!! 580!! 4!! 1952!! 96 Exercise What are the physical addresses for the following logical addresses? a. 1, 100 b. 2, 0 c. 3, 580 Solution Consider the following segment table:!! Segment! Base!! Length!! 0!! 219!! 600!! 1!! 2300!! 14!! 2!! 90!! 100!! 3!! 1327!! 580!! 4!! 1952!! 96 What are the physical addresses for the following logical addresses? a. 1, 100 illegal reference (2300+100 is not within segment limits) b. 2, 0 physical address = 90 + 0 = 90 c. 3, 580 illegal reference (1327 + 580 is not within segment limits)

Sharing of Segments Sharing of Segments 31

Summary Main Memory Management Memory Allocation Fragmentation Address Binding HW Address Protection Paging Segmentation Hmm.. Next Lecture: Virtual Memory 33 Acknowledgements Operating Systems Concepts book and supplementary material by A. Silberschatz, P. Galvin and G. Gagne Operating Systems: Internals and Design Principles book and supplementary material by W. Stallings Modern Operating Systems book and supplementary material by A. Tanenbaum R. Doursat and M. Yuksel from UNR 34