Memory management OS

Similar documents
Preview. Memory Management

Processes and Tasks What comprises the state of a running program (a process or task)?

Memory management: outline

Memory management: outline

Chapter 3 - Memory Management

CS399 New Beginnings. Jonathan Walpole

12: Memory Management

Virtual Memory 1. To do. q Segmentation q Paging q A hybrid system

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

16 Sharing Main Memory Segmentation and Paging

Memory Management. CSE 2431: Introduction to Operating Systems Reading: , [OSC]

Memory and multiprogramming

Operating Systems, Fall

Operating Systems, Fall

CS450/550 Operating Systems

Virtual Memory. Today. Segmentation Paging A good, if common example

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

15 Sharing Main Memory Segmentation and Paging

Memory Management Prof. James L. Frankel Harvard University

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

4 MEMORY MANAGEMENT 4.1 BASIC MEMORY MANAGEMENT

Course: Operating Systems Instructor: M Umair. M Umair

Goals of Memory Management

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

Chapter 4 Memory Management

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

Registers Cache Main memory Magnetic disk Magnetic tape

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Motivation. Memory Management. Memory Management. Computer Hardware Review

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

Operating Systems Lecture 6: Memory Management II

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Memory Management. Jo, Heeseung

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

Chapter 4 Memory Management. Memory Management

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

Chapter 9 Memory Management

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

Virtual Memory: Mechanisms. CS439: Principles of Computer Systems February 28, 2018

Memory Management. Memory Management. G53OPS: Operating Systems. Memory Management Monoprogramming 11/27/2008. Graham Kendall.

Lecture 7. Memory Management

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

CS307 Operating Systems Main Memory

Objectives and Functions Convenience. William Stallings Computer Organization and Architecture 7 th Edition. Efficiency

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

CS 153 Design of Operating Systems Winter 2016

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Operating System Support

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

Introduction to Operating Systems

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

MEMORY MANAGEMENT. Jo, Heeseung

Chapter 8: Memory-Management Strategies

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

CS399 New Beginnings. Jonathan Walpole

CS/COE 1550

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

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

Virtual to physical address translation

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

Chapter 8: Main Memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Chapter 8 Memory Management

Virtual Memory 2. q Handling bigger address spaces q Speeding translation

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

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

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

CS307: Operating Systems

Memory Management. Goals of Memory Management. Mechanism. Policies

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

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

Chapter 8: Memory- Management Strategies

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

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

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

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

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

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

How to create a process? What does process look like?

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

Virtual Memory. Yannis Smaragdakis, U. Athens

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

Chapter 8: Main Memory

Chapter 8: Main Memory

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Unit II: Memory Management

Process. Memory Management

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

CS 134: Operating Systems

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

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management Seventh Edition William Stallings

CSCI 4717 Computer Architecture. Memory Management. What is Swapping? Swapping. Partitioning. Fixed-Sized Partitions (continued)

Transcription:

Memory management 1

Memory (ideally) 2 Ideally Extremely fast (faster than the CPU in executing an instruction) Abundantly large Dirt cheap

Memory (for real) 3 Typical access time 1 nsec Registers 2 nsec Cache 10 nsec Main memory 10 msec Magnetic disk 100 sec Magnetic tape Size < 1K ~ 1M ~ 1-4G ~ 5-100G > 20G

Memory cntd. Registers: typical 32 in a 32 bit CPU Cache: divided into cache lines (64 bytes each) 4 Cache hit no main memory access, no bus involvement Cache miss costly Main memory Disk (multiple plates, heads, arms) Logical structure: sectors, tracks, cylinders Magnetic tape: backup, cheap, removable

OS management of memory The part of the OS that handles the management of the memory is called: Surprise, surprise: memory manager! Various levels of complicacy Depending on the type of OS E.g. mono-programming, multiprogramming, i and so forth 5

Specifics of memory management Basic memory management strategies Monoprogramming without swapping or paging Multiprogramming with fixed partitions Multiprogramming li i with ih variable partitions ii Swapping Virtual memory: paging Virtual memory: segmentation 6

Mono-programming No swapping, a couple of options 7 0xFFFF Operating system (ROM) 0xFFFF Device drivers (BIOS) User program and data User program and data 0x00000000 Some embedded systems (e.g. PALM) 0x00000000 Operating system (e.g. DOS)

Multiprogramming with fixed partitions Curiosity: used by the IBM OS/360 (1960 or so) in version called MFT (multiprogramming with fixed number of tasks) 8 Partition 4 Partition 4 Partition 3 Partition 3 Partition 2 Partition 2 Partition 1 Partition 1 Operating system Operating system Multiple queues Single queue

Modeling multiprogramming Each process spends a fraction p of its time waiting for I/O to complete If we have n processes, the probability that all of n them are simultaneously waiting for I/O is: CPU utilization is thus: 9 1 p n p

CPU utilization 10 CPU ut tilization 100 20% I/O wait 50% I/O wait 80% I/O wait Number of processes (n)

Example 11 A system has 32Mbyte of RAM, OS takes 16Mbytes Each process occupies on average 4Mbytes (4 processes simultaneously in memory) and has 20% utilization time (80% blocked on I/O) CPU utilization approx 60% Buying 16M additional RAM will allow to increase multiprogramming i to 8, CPU utilization will get to about 83% Another 16M will get from 83 to 93%, depending on memory price we can make an informed choice

Relocation and protection Relocation when loading the code. The linker stores some additional information which is used at load time to relocate (rewrite) every single instruction referencing memory. HW support through the use of base and limit registers Partial support, only base but no limit 12

Swapping and virtual memory 13 Swapping: whole process data/code in memory when running Virtual memory: only part of the data/code in memory

Swapping 14 C C B B B A A A D Operating system Operating system Operating system Operating system

Swapping cntd. Memory compaction (remove holes) If processes could grow (by allocating memory on a heap like in many programming languages), how does the OS take care of it? Many different solutions: e.g. reserve room for growth or swap the process out and relocate it to a bigger memory partition, etc. 15

Bitmaps How is it implemented? Memory is divided into allocation units Each bit of the bitmap represents a unit (1 = used, 0 = free) The size of allocation unit is an important design issue (less unused memory, bigger bitmap) Search bitmaps when loading in a new process for k consecutive free allocation units 16

Linked lists A linked list may store: How is it implemented? 17 Information about a process or a hole Address where it starts Length Pointer to the next element Merging operation (e.g. two consecutive holes) Process table entry will contain a pointer to the element in the list relative to it

Different algorithms 18 First fit: the first hole that fits the process is used (hole is broken down into two pieces) Next fit: it doesn t start from the beginning, simply restart from where it left the previous search Best fit: search the whole list for the smallest hole that fits Performance: best fit creates a lot of fragmentation in practice, first fit tends to leave larger holes (less fragmentation)

Fragmentation 19 Internal: partition or page not fully used by a given process External: entire partitions or free space (holes) not used because no process fits in the size of any of the holes

Fragmentation 20 D External: processes are all too big to run on empty partitions C B D Operating system Internal: using the partition but leaving some memory unused

MVT Curiosity: used by the IBM OS/360 (1960 or so) in a version called MVT (multiprogramming with variable number of tasks): Dynamical partitions: sized as the size of processes Swapping: as described earlier 21

Virtual memory Once upon a time there was the overlay In practice programmer divided the program (by hand) into many parts that could be swapped in and out from disk (overlaid onto unused parts) Why don t we delegate this function to the machine itself? Virtual memory was born! 22

Demand paging Pages are loaded from disk only when needed (demanded) 23 Process that causes the page fault can be considered blocked for I/O (and another process could run) Swapping (of pages), lazy backing store (e.g. lazy means that pages are only loaded when needed otherwise the system does nothing, it doesn t swap entire processes)

Paging 24 CPU package MMU CPU CPU sends virtual addresses to the MMU Memory Disk controller MMU sends physical addresses to memory Bus

Paging can be Pure: for every logical page there exists a physical page, always everything available in memory 25 On demand: at any given instant only a subset of the virtual address space is in memory (but everything is still consistent) t)

MMU s internals Virtual address space 60-64K X 56-60K60K X 52-56K X 48-52K X 44-48K 7 40-44K X 36-40K 5 32-36K X 28-32K X 24-28K X 20-24K 3 16-20K 4 12-16K 0 8-12K 6 4-8K 1 0-4K 2 26 Virtual page Physical address space 28-32K 24-28K 20-24K 16-20K 12-16K16K 8-12K 4-8K 0-4K Page frame

Example 27 MOV REG,0 CPU sends request for address 0 MMU looks for 0 and sees that the page containing virtual address 0 is at frame 2 It thus adds 8192 (frame 2 start address) MMU finally sends 8192 on the bus

Since memory is finite 28 Present/absent bit in the virtual page table (the X s in the picture) Same as before: MOV REG,32780 what happens? Page fault, the page is not in physical memory but rather on the disk The OS needs to evict a page from main memory and to replace it with the missing gpage, to update the MMU s tables, and to restart the instruction that caused the fault

Operation of the MMU 29 To bus 110 000000000100 24580 Virtual page table Present/absent bit for each entry Virtual page index 0010 000000000100 8196

Is it a simple task? The page table can be extremely large 30 32bits systems with a 4K-page size has more than a million pages 64bits 2^52 pages? Gosh! The mapping must be fast (VERY fast) Every memory reference requires a virtual to physical conversion, a single instruction might have >1 reference

Within the MMU Where s the page table? 31 Every context switch requires loading the whole page table into the MMU registers, good because it doesn t require more memory reference afterwards Memory A single pointer to the table needs to be reloaded in a context switch, more memory references (to the page table) are required for mapping each memory reference

Multi-level page tables Example: 32 bits could be partitioned as a 10-bit pointer to level 1 table, 10-bit to level 2 and 12-bit offset fields 32 PT1 PT2 Offset PT1 1023 1023 1023 1023 5 1023 5 1023 5 4 5 4 3 5 4 4 3 5 2 4 3 3 2 4 PT2 1 3 2 1 3 2 0 2 1 0 2 1 1 0 1 0 0 0 Address to the page Offset Each points to 4Mbytes of pages

Present/absent: in memory? About the page table Protection bits: e.g. read/write/execute Modified: whether any address has been changed, rewrite to disk is required before evicting the page Referenced: used by the OS to decide which page to evict Caching: may be used to avoid caching pages required for I/O 33 Caching disabled Referenced Modified Protection Present/Absent Page frame #

TLBs Translation Lookaside Buffers 34 Page tables in memory require additional memory accesses, unpractical Most programs tend to make a large number of references to a small number of pages Use something called a TLB or Associative Memory

What does the TLB do? 35 Small number of entries, within the MMU, fast Association (direct) of virtual page to page frame Parallel compare over the whole table, if virtual page is not there, do the normal lookup (over memory) and then evict an entry and replace with the new one Valid Virtual page Modified Protection Page frame 1 140 1 RW 31 1 20 0 RX 38 1 860 1 RW 14

Additional issues Software TLB management 36 Some microprocessors don t have the TLB completely in HW, the handling of the TLB fault is done in SW (i.e. the OS does it) Inverted Page Tables Imagine a 64 bit computer: page tables would be too big Inverted table, one per page frame rather than per page It requires a search (potentially slow), needs a good implementation (fast) and a possibly large TLB