CSE506: Operating Systems Physical Page Reclamation.

Slides:



Advertisements
Similar presentations
Paging: Design Issues. Readings r Silbershatz et al: ,
Advertisements

Memory management.
Case Study: Virtual Memory in UNIX Reference – Maurice J.Bach, The Design of the UNIX Operating System Terminology - Physical Memory (Main Memory) Secondary.
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSE506: Operating Systems Block Cache. CSE506: Operating Systems Address Space Abstraction Given a file, which physical pages store its data? Each file.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Computer ArchitectureFall 2008 © CS : Computer Architecture Lecture 22 Virtual Memory (1) November 6, 2008 Nael Abu-Ghazaleh.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Multiprocessing Memory Management
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Memory Management 2010.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
CS333 Intro to Operating Systems Jonathan Walpole.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Demand Paging Reference Reference on UNIX memory management
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
LINUX 15 : Memory Management
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Lecture 14 PA2. Lab 2: Demand Paging Implement the following syscalls xmmap, xmunmap, vcreate, vgetmem/vfreemem, srpolicy Deadline: November , 10:00.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
COS 318: Operating Systems Virtual Memory Paging.
Virtual Memory.
CS161 – Design and Architecture of Computer
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Chapter 2: The Linux System Part 4
Jonathan Walpole Computer Science Portland State University
CS161 – Design and Architecture of Computer
Memory Caches & TLB Virtual Memory
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Chapter 9: Virtual Memory
Modeling Page Replacement Algorithms
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
Virtual Memory Management
CSE 153 Design of Operating Systems Winter 2018
Chapter 9: Virtual-Memory Management
Page Replacement.
Modeling Page Replacement Algorithms
Virtual Memory.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Virtual Memory: Systems CSCI 380: Operating Systems
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
Lecture 9: Caching and Demand-Paged Virtual Memory
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
CSE 542: Operating Systems
Presentation transcript:

CSE506: Operating Systems Physical Page Reclamation

CSE506: Operating Systems VA to PA, PA to VA Saw how virtual addresses translate to physical – Where is address 0x1000 in process 100? How to do the reverse? – Given physical page X, what has a reference to it? – Why would you want to know?

CSE506: Operating Systems Motivation: Paging / Swapping Most OSes allow memory overcommit – Allocate more virtual memory than physical memory How does this work? – Physical pages allocated on demand only – If free space is low… OS frees some pages non-critical pages (e.g., cache) Worst case, page some stuff out to disk

CSE506: Operating Systems Paging Memory To swap a page out… – Save contents of page to disk – What to do with page table entries pointing to it? Clear the PTE_P bit If we get a page fault for a swapped page… – Allocate a new physical page Read contents of page from disk – Re-map the new page (with old contents)

CSE506: Operating Systems Shared Pages VMA represents a region of virtual address space – VMA is private to a process Physical pages can be shared – Files loaded from disk, opened by multiple processes Most commonly, shared libraries (libc.so) – Anonymous pages are shared too Remember COW fork()?

CSE506: Operating Systems Tracking Anonymous Memory Mapping anonymous memory creates VMA – Pages are allocated on demand Keep track of VMAs that reference this page in list – List linked from page descriptor Along-side the ->next pointer used when page was free Linux creates extra structure anon_vma – Newer versions create anon_vma_chain – Tradeoff between space/complexity and performance

CSE506: Operating Systems Linux Example Physical memory Process AProcess B (forked) Virtual memory Page Tables Physical page descriptors vma anon vma anon vma

CSE506: Operating Systems Linux Example (2nd Page) Physical memory Process A Process B Virtual memory Page Tables Physical page descriptors vma anon vma anon vma No update? Anonymous VMAs tend to be COW

CSE506: Operating Systems Reverse Mapping Pick a physical page X, what is it being used for? Linux example – Add 2 fields to each page descriptor – _mapcount: Tracks the number of active mappings -1 == unmapped 0 == single mapping (unshared) 1+ == shared – mapping: Pointer to the owning object Address space (file/device) or anon_vma (process) Least Significant Bit encodes the type (1 == anon_vma)

CSE506: Operating Systems Anonymous Page Lookup Given a page descriptor: – Look at _mapcount to see how many mappings. If 0+: Read mapping to get pointer to the anon_vma Iterate over VMAs on the anon_vma list – Linear scan of page table entries for each VMA VMA -> mm -> pgdir

CSE506: Operating Systems Example Physical memory Process A Process B Virtual memory Page Tables Physical page descriptors vma anon vma anon vma Page 0x10000 Divide by 0x1000 (4k) Page 0x10000 Divide by 0x1000 (4k) Page 0x10 _mapcount: 1 mapping: (anon vma + low bit) Page 0x10 _mapcount: 1 mapping: (anon vma + low bit) foreach vma Linear scan of page tables

CSE506: Operating Systems Reclaiming Pages Until we run out of memory… – Kernel caches and processes go wild allocating memory When we run out of memory… – Kernel needs to reclaim physical pages for other uses – Doesn’t necessarily mean we have zero free memory Maybe just below a “comfortable” level Where to get free pages? – Goal: Minimal performance disruption Should work on phone, supercomputer, and everything in between

CSE506: Operating Systems Types of Pages Unreclaimable: – Free pages (obviously) – Pinned/wired pages – Locked pages Swappable: anonymous pages Dirty Cache: data waiting to be written to disk Clean Cache: contents of disk reads

CSE506: Operating Systems General Principles Free harmless pages first – Consider dropping clean disk cache (can read it again) – Steal pages from user programs Especially those that haven’t been used recently Must save them to disk in case they are needed again – Consider dropping dirty disk cache But have to write it out to disk first Doable, but not preferable When reclaiming page, remove all references at once – Removing one reference is a waste of time – Consider removing entire object (needs extra linked list)

CSE506: Operating Systems Finding Candidates to Reclaim Try reclaiming pages not used for a while – All pages are on one of 2 LRU lists: active or inactive – Access causes page to move to the active list – If page not accessed for a while, moves to the inactive list How to know when an inactive page is accessed? – Remove PTE_P bit Page fault is cheap compared to paging out active page How to know when page isn’t accessed for a while? – Would page fault too often on false candidates – Use PTE_Accessed bit (e.g., clock algorithm)

CSE506: Operating Systems Big Picture Kernel keeps a heuristic “target” of page ratios – Free+Zeroed, Free, Cached, Active, Inactive, … – Makes a best effort to maintain that target Can fail – Miserably Kernel gets worried when allocations start failing – Some allocations simply can’t fail Kernel panic if they do – Some allocations can fail User process called malloc() If things get bad, OOM kill processes?