OPERATING SYSTEMS 8 – VIRTUAL MEMORY PIETER HARTEL 1.

Slides:



Advertisements
Similar presentations
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Advertisements

Memory Management.
Chapter 8 Virtual Memory
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Virtual Memory Introduction to Operating Systems: Module 9.
Segmentation and Paging Considerations
1 Memory Management Managing memory hierarchies. 2 Memory Management Ideally programmers want memory that is –large –fast –non volatile –transparent Memory.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8.
Operating System Support Focus on Architecture
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Lecture 11: Memory Management
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Memory Management 2010.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Virtual Memory (Chapter 8) Memory Management is an intimate and complex interrelationship between processor hardware and operating system software. Paging.
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
CS 153 Design of Operating Systems Spring 2015 Final Review.
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
CS 241 Fall 2007 System Programming 1 Virtual Memory Lawrence Angrave and Vikram Adve.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles Seventh Edition William Stallings.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
OPERATING SYSTEMS 1 - HARDWARE PIETER HARTEL 1. Hardware 2.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill. What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data.
Virtual Memory What if program is bigger than available memory?
Virtual Memory Chapter 8.
Virtual memory.
Virtual Memory: Systems
Chapter 8 Virtual Memory
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Virtual Memory: Systems
Virtual Memory: Systems
Making Virtual Memory Real: The Linux-x86-64 way
Page Replacement.
CPSC 457 Operating Systems
Virtual Memory فصل هشتم.
Virtual Memory Overcoming main memory size limitation
Virtual Memory: Systems CSCI 380: Operating Systems
Translation Lookaside Buffers
CSE 542: Operating Systems
4.3 Virtual Memory.
CSE 542: Operating Systems
Presentation transcript:

OPERATING SYSTEMS 8 – VIRTUAL MEMORY PIETER HARTEL 1

Principle of locality: memory references tend to cluster  Only resident set of pages in memory  Page fault brings in a missing page  Page fault may need to free a frame  Advantages  Process size can be > memory size  The resident set of many processes in memory at the same time  Challenges  OS has to predict future  Avoid thrashing  Concurrency may spoil locality 2 time pagespages

Principle of separation: mechanism and policy  A policy describes what is allowed to be done  A mechanism describes how it is done  Examples: 3 $ ls -l total rw-r--r-- 1 pieter ewi :00 1-Hardware.pptx -rw-r--r-- 1 pieter ewi :58 2-Overview.pptx $ ps -l F S UID PID PPID PRI NI SZ TTY TIME CMD 1 S ? 00:00:00 cqueue 5 S pieter ? 00:00:00 sshd 0 S pieter pts/1 00:00:00 bash 0 R pieter pts/1 00:00:00 ps

Paging address translation mechanism  Page table per process (how large?)  Cache page table entries in Translation Look aside buffer (TLB) 4

Hierarchical page table  Page table in virtual memory  Disadvantage? 5 Always in memory

Alternative mechanism: Inverted page table  One entry per frame instead of one entry per page (n > m)  Disadvantage? 6

Policies  Replacement policies  Optimal, LRU, FIFO, and Clock (more…)  Resident set policies  Fixed and variable (more…)  Others… 7

Page replacement policies 8 Difficult Easy

Resident set management policies  Choices: Fixed vs variable allocation and Local vs global scope  Working set size depends on the time t (can we measure this?)  Use page fault frequency changes as a trigger (how?) 9

Linux  Three level page table  Clock algorithm with 8 bit age 10

int main(int argc, char* argv[]) { int cnt, flt; char buffer[N*P]; struct rusage usage; if(argc > 1) mlock(buffer, N*P); getrusage(RUSAGE_SELF, &usage); flt = usage.ru_minflt; for (cnt=0; cnt < N*P; cnt++) { buffer[cnt] = 0; getrusage(RUSAGE_SELF, &usage); if( flt != usage.ru_minflt ) { flt = usage.ru_minflt; /* save cnt and flt to print later */ } /* print table of cnt and flt */ } Page faults  gcc Getrusage.c ./a.out ./a.out xx  cd /usr/include/bits/  more resource.h  man mlock 11

int main(int argc, char *argv[]) { void *src, *tgt; int in = open(argv[1], O_RDONLY); int out = open(argv[2], O_RDWR| O_CREAT|O_TRUNC, 0666); int flags = (argc > 3 ? MAP_PRIVATE : MAP_SHARED); size_t sz = lseek(in, 0, SEEK_END); lseek(out, sz - 1, SEEK_SET); write(out, "\0", 1); src = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, in, 0); tgt = mmap(NULL, sz, PROT_WRITE, flags, out, 0); memcpy(tgt, src, sz); munmap(src, sz); munmap(tgt, sz); close(in); close(out); return 0; } Sharing  Output?  gcc Mmap.c  strace./a.out Mmap.c Foo.c ./a.out Mmap.c Bar.c xx  diff Mmap.c Foo.c  diff Mmap.c Bar.c  od –c Bar.c  man mmap 12

Summary  Principles of locality and separation  Memory management necessary to match slow I/O to fast processor  Clean separation of logical from physical addresses  Every modern system has virtual memory 13