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

Similar documents
Memory Management. Dr. Yingwu Zhu

Chapter 8 Main Memory

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

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

CS307: Operating Systems

Chapter 8 Memory Management

Principles of Operating Systems

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8 Main Memory

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

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

Chapter 8: Memory-Management Strategies

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

CS307 Operating Systems Main Memory

Basic Memory Management

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB)

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

12: Memory Management

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

Chapter 9 Memory Management

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

CS399 New Beginnings. Jonathan Walpole

Chapter 8: Main Memory

Chapter 8: Main Memory

Goals of Memory Management

Compile: compiler. Load: loader. compiler linker loader memory. source object load code module module 2

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

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

Chapter 8: Memory- Management Strategies

Memory management: outline

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

Memory Management. Dr. Yingwu Zhu

Memory Management. Goals of Memory Management. Mechanism. Policies

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

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

CS370 Operating Systems

Memory and multiprogramming

Operating Systems Design Exam 2 Review: Fall 2010

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

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

Memory Management. Memory Management

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

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

Memory management: outline

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

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

Chapter 8: Main Memory

CS3600 SYSTEMS AND NETWORKS

CS 3733 Operating Systems:

Chapter 8: Main Memory

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

Operating Systems, Fall

Operating Systems, Fall

Chapter 9: Memory Management. Background

Module 8: Memory Management

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

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

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

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

Chapter 8: Memory Management Strategies

Module 8: Memory Management

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

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS 416: Opera-ng Systems Design March 23, 2012

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University.

Main Memory (Part II)

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

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

Operating Systems Design Exam 2 Review: Spring 2011

Chapter 8: Memory Management

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

CS450/550 Operating Systems

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

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

Chapter 4 Memory Management

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

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

Logical versus Physical Address Space

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

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

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

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

16 Sharing Main Memory Segmentation and Paging

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Chapter 3 - Memory Management

Last Class: Deadlocks. Where we are in the course

15 Sharing Main Memory Segmentation and Paging

ECE 571 Advanced Microprocessor-Based Design Lecture 12

CPE300: Digital System Architecture and Design

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Operating Systems Design Exam 2 Review: Spring 2012

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

CS 5523 Operating Systems: Memory Management (SGG-8)

Operating Systems. User OS. Kernel & Device Drivers. Interface Programs. Memory Management

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

Address spaces and memory management

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

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

1. Creates the illusion of an address space much larger than the physical memory

Transcription:

Operating Systems 09. Memory Management Part 1 Paul Krzyzanowski Rutgers University Spring 2015 March 9, 2015 2014-2015 Paul Krzyzanowski 1

CPU Access to Memory The CPU reads instructions and reads/write data from/to memory CPU read/write memory Functional interface: value = read(address) write(address, value)

Programs have references to memory Programs make use of memory addresses Instruction execution: addresses for branching Data access: addresses for reading/writing data Static linking compiler linker loader High-level code Object module Executable binary In-memory image Symbolic addresses Offsets or cross-references to external symbols Other object modules/librarie s

Monoprogramming Run one program at a time Share memory between the program and the OS OS Absolute memory addresses are no problem Program This was the model in old MS- DOS (and other) systems

Multiprogramming Keep more than one process in memory More processes in memory improves CPU utilization OS Absolute memory addresses are a problem!! Program 2 Program 1 Program 0

Justifying Multiprogramming: CPU Utilization Keep more than one process in memory More processes in memory improves CPU utilization OS Program 2 Program 1 Program 0 If a process spends 20% of its time computing, then would switching among 5 processes give us 100% CPU utilization? Not quite. For n processes, if p = % time a process is blocked on I/O then: probability all are blocked = p n CPU is not idle for (1-p n ) of the time 5 processes: 67% utilization

How do programs specify memory access? Absolute code If you know where the program gets loaded (any relocation is done at link time) Position independent code All addresses are relative (e.g., gcc fpic option) Dynamically relocatable code Relocated at load time Or use logical addresses Absolute code with with addresses translated at run time Need special memory translation hardware

Dynamic Linking compiler linker loader High-level code Object module Executable binary In-memory image Symbolic addresses Offsets or cross-references to external symbols Other object modules/librarie s Dynamic libraries/module s Load-time / run-time linking

Dynamic Linking A process loads libraries at load time Symbol references are resolved at load time OS loader finds the dynamic libraries and brings them into the process memory address space

Dynamic Loading A process can load a module at runtime on request Similar to dynamic linking Program is written to load a specific library Resolve symbols to get pointers to data & functions The library can be unloaded when not needed

Shared libraries Dynamic linking + sharing Libraries that are loaded by programs when they start All programs that start later use the shared library Program loader searches for needed shared libraries Object code is linked with a stub Stub checks whether the needed library is in memory If not, the stub loads it Stub is then replaced with the address of the library Operating system: Checks if the shared library is already in another process memory Shares memory region among processes Need position independent code or pre-mapped code (reserved regions of memory that processes share)

Logical addressing Memory management unit (MMU): Real-time, on-demand translation between logical (virtual) and physical addresses CPU read/write MMU read/write memory Logical addresses Physical addresses

Relocatable addressing Base & limit Physical address = logical address + base register But first check that: logical address < limit limit register base register CPU Logical address < + trap Physical address memory

Allocating memory

Multiple Fixed Partitions Divide memory into predefined partitions (segments) Partitions don t have to be the same size For example: a few big partitions and many small ones New process gets queued for a partition that can hold it Unused memory in a partition is wasted Internal fragmentation Unused partitions: external fragmentation Contiguous allocation: Process takes up a contiguous region of memory

Variable partition multiprogramming Create partitions as needed New process gets queued OS tries to find a hole for it Program 4 Program 3 Program 2 Program 1 Program 0 OS

Variable partition multiprogramming Create partitions as needed New process gets queued OS tries to find a hole for it fragments Program 4 Program 3 Program 2 Program 1 program 3 exits program 1 exits Program 4 hole Program 2 hole Program 0 Program 0 OS OS

Allocation algorithms First fit: find the first hole that fits Best fit: find the hole that best fits the process Worst fit: find the largest available hole Why? Maybe the remaining space will be big enough for another process. In practice, this algorithm does not work well.

Variable partition multiprogramming What if a process needs more memory? Always allocate some extra memory just in case Find a hole big enough to relocate the process Combining holes (fragments) Memory compaction Usually not done because of CPU time to move a lot of memory

Segmentation hardware Divide a process into segments and place each segment into a partition of memory Code segment, data segment, stack segment, etc. Discontiguous memory allocation limit register segment register CPU Logical address < + trap Physical address memory

Paging Memory management scheme Physical space can be non-contiguous No fragmentation problems No need for compaction Paging is implemented by the Memory Management Unit (MMU) in the processor

Paging Translation: Divide physical memory into fixed-size blocks: page frames A logical address is divided into blocks of the same size: pages All memory accesses are translated: page page frame A page table maps pages to frames Example: 32-bit address, 4 KB page size: Top 20 bits identify the page number Bottom 12 bits identify offset within the page/frame Page number, p Displacement (offset), d

Page translation Page number, p Displacement (offset), d f = page_table[p] CPU Logical address p d f d Page table f f f f f f f Physical address f = page_table[p] Physical memory

Logical vs. physical views of memory frame 7 Page 2 6 Page 3 page 2 3 2-7 page 3 not mapped 5 4 Page 0 page 1 1 2 3 page 0 0 4 2 Page 1 Logical Memory Page Table 1 0 Physical Memory

Hardware Implementation Where do you keep the page table? In memory Each process gets its own virtual address space Each process has its own page table Change the page table by changing a page table base register CR3 register on Intel IA-32 and x86-64 architectures Memory translation is now slow! To read a byte of memory, we need to read the page table first Each memory access is now 2x slower!

Hardware Implementation: TLB Cache frequently-accessed pages Translation lookaside buffer (TLB) Associative memory: key (page #) and value (frame #) TLB is on-chip & fast but small (64-1,024 entries) Locality in the program ensures lots of repeated lookups TLB miss = page # not cached in the TLB Need to do page table lookup in memory Hit ratio = % of lookups that come from the TLB

Address Space Identifiers: Tagged TLB There is only one TLB per system When we context switch, we switch address spaces New page table BUT TLB entries belong to the old address space Either: Flush (invalidate) the entire TLB Have a Tagged TLB with an Address Space Identifier (ASID)

Protection An MMU can enforce memory protection Page table stores status & protection bits per frame Valid/invalid: is there a frame mapped to this page? Read-only No execute Kernel only access Dirty: the page has been modified since the flag was cleared Accessed: the page has been accessed since the flag was cleared

Multilevel (Hierarchical) page tables Most processes use only a small part of their address space Keeping an entire page table is wasteful Example 32-bit system with 4KB pages: 20-bit page table 2 20 = 1,048,576 entries in the page table

Multilevel page table Origin, b Virtual address + p 0 p 1 d b 0 + p 0 b n + b n + p 1 p' p' d real address index table base = b n partial page table

Inverted page tables # of pages on a system may be huge # of page frames will be more manageable (limited by physical memory) Inverted page table i th entry: contains info on what is in page frame i Table access is no longer a simple index but a search Use hashing and take advantage of associative memory

Next Lecture Sharing memory across address spaces Copy on write Demand paging Load needed pages on demand Page faults Page replacement: FIFO, LRU, second chance Thrashing Working set: time window March 9, 2015 2014-2015 Paul Krzyzanowski 32

The End March 9, 2015 2014-2015 Paul Krzyzanowski 33