CS 416: Operating Systems Design March 9, 2015

Similar documents
Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Virtual Memory. CS 351: Systems Programming Michael Saelee

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

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

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

Chapter 8: Memory-Management Strategies

Chapter 8: Main Memory

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

Virtual Memory Outline

Chapter 8: Main Memory

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

Chapter 8 Main Memory

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 9: Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory

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

Virtual Memory III. Jo, Heeseung

Operating Systems Design Exam 2 Review: Spring 2011

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

Operating Systems. Operating Systems Sina Meraji U of T

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Memory management, part 2: outline

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

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

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

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Module 9: Virtual Memory

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Operating System Concepts 9 th Edition

Operating System Concepts

Module 9: Virtual Memory

Chapter 9: Virtual-Memory

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 10: Virtual Memory

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

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

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

Basic Memory Management

CS370 Operating Systems

Chapter 9: Virtual Memory

Operating Systems Design Exam 2 Review: Fall 2010

CS307: Operating Systems

a process may be swapped in and out of main memory such that it occupies different regions

Address spaces and memory management

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

Operating Systems. IV. Memory Management

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

CS307: Operating Systems

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

CS 550 Operating Systems Spring Memory Management: Page Replacement

Virtual Memory Management

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

Memory Management. Outline. Memory. Virtual Memory. Instructor: Dr. Tongping Liu

Lecture 12: Demand Paging

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

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

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

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

Memory Management. Goals of Memory Management. Mechanism. Policies

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

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

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

CS370 Operating Systems

Motivation. Memory Management. Memory Management. Computer Hardware Review

Chapter 8 Memory Management

CSE 120 Principles of Operating Systems

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

CS370 Operating Systems

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

Memory Management Ch. 3

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

Where are we in the course?

Virtual Memory. Yannis Smaragdakis, U. Athens

ECE 598 Advanced Operating Systems Lecture 14

Chapter 10: Virtual Memory. Background

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

Memory Management. Dr. Yingwu Zhu

First-In-First-Out (FIFO) Algorithm

Chapter 4 Memory Management. Memory Management

ECE 571 Advanced Microprocessor-Based Design Lecture 12

CS 153 Design of Operating Systems Winter 2016

Chapter 10: Virtual Memory. Background. Demand Paging. Valid-Invalid Bit. Virtual Memory That is Larger Than Physical Memory

Chapter 6: Demand Paging

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

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory Oct. 29, 2002

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Chapter 9: Virtual Memory

Week 2: Tiina Niklander

Transcription:

Page translation Operating Systems 10. Memory Management Part 2 Paging Page number, p Displacement (oset), d = page_table[p] Page Paul Krzyzanowski Rutgers University Spring 2015 CPU Logical address p d d Page table Physical address Page Table Entry (PTE) Page Frame Physical memory 1 2 Page table Accessing memory One page table per process Contains page table entries (PTEs) Each PTE contains Corresponding page rame # or a page # Permissions Permissions (read-only, read-write, execute-only, privileged access only ) Access lags Valid? Is the page mapped? Modiied? Reerenced? CPU starts in physical addressing mode Someone has to set up page tables Divide address space into user & kernel spaces Switch to Virtual addressing mode Each process makes virtual address reerences or all memory access MMU converts to physical address via a per-process page table Page number Page rame number Page ault trap i not a valid reerence Page table is selected by setting a page table base register with the address o the table 3 4 Improving look-up perormance: TLB Page-Based Virtual Memory Beneits Cache requently-accessed pages Translation lookaside buer (TLB) Associative memory: key (page #) and value (rame #) Allow discontiguous allocation Simpliy memory management or multiprogramming MMU gives the illusion o contiguous allocation o memory TLB is on-chip & ast but small (64 1,024 entries) TLB miss: result not in the TLB Need to do page table lookup in memory Hit ratio = % o lookups that come rom the TLB Address Space Identiier (ASID): share TLB among address spaces Process can get memory anywhere in the address space Allow a process to eel that it has more memory than it really has Process can have greater address space than system memory Enorce memory Protection Each process address space is separate rom others MMU allows pages to be protected: Writing, execution, kernel vs. user access 5 6 2014-2015 Paul Krzyzanowski 1

Kernel s view o memory Sample memory map per process A process sees a lat linear address space Accessing regions o memory mapped to the kernel causes a page ault Kernel s view: Address space is split into two parts User part: changes with context switches Kernel part: remains constant across context switches Split is conigurable: 32-bit x86: PAGE_OFFSET: 3 GB or process + 1 GB kernel Interrupt stack Data Text (code) argv, envp user stack kernel Kernel memory (1 GB) Process memory (context-speciic) (3 GB) 0x 0xc0000000 Kernel memory (2 GB) (8 TB on 64-bit) Process memory (context-speciic) (2 GB) 0x 0x80000000 heap data text User process A lot o unused space! 0x00000000 0x00000000 7 8 Multilevel (Hierarchical) page tables Multilevel page table Most processes use only a small part o their address space base, b 0 Virtual address Keeping an entire page table is wasteul 32-bit system with 4KB pages: 20-bit page table 2 20 = 1,048,576 entries in a page table b 0 + p 0 + b n p 0 p 1 d + b n + p 1 p' p' d real address index table partial page table 9 10 Virtual memory makes memory sharing easy Virtual memory makes memory sharing easy Shared library or Shared memory Sharing is by page granularity Sharing is by page granularity. Keep reerence counts! 11 12 2014-2015 Paul Krzyzanowski 2

Copy on write Share until a page gets modiied Example: ork() Set all pages to read-only Trap on write I legitimate write Allocate a new page and copy contents rom the original MMU Example: ARM 13 14 ARMv7-A architecture Cortex-A8 iphone 3GS, ipod Touch 3G, Apple A4 processor in iphone 4 & ipad, Droid X, Droid 2, etc.) Cortex-A9 Multicore support TI OMAP 44xx series, Apple A5 processor in ipad 2 Apple A6 32-bit AMD Cortex-A15 processor Used in iphone 5, 5C, 4 th gen ipad Apple A7 64-bit ARMv8-A architecture Used in iphone 5S, 2 nd gen ipad mini, ipad Air Pages Four page (block) sizes: Supersections: 16MB memory blocks Sections: 1MB memory blocks Large pages: 64KB memory blocks Small pages: 4KB memory blocks 15 16 Two levels o tables ARM Page Tables First level table (aka translation tables) Base address, descriptors, and translation properties or sections and supersections (1 MB & 16 MB blocks) Translation properties and pointers to a second level table or large and small pages (4 KB and 64 KB pages) Second level tables (aka page tables) Each contains base address and translation properties or small and large pages Beneit: a large region o memory can be mapped using a single entry in the TLB (e.g., OS) base 1 st level table (per process) 2 nd level tables (set per process) 17 18 2014-2015 Paul Krzyzanowski 3

32 entries 32 entries 8 + 64 entries TLB 1 st level: MicroTLB one each or instruction & data sides 32 entries (10 entries in older v6 architectures) Address Space Identiier (ASID) [8 bits] and Non-Secure Table Identiier (NSTID) [1 bit]; entries can be global Fully associative; one-cycle lookup Lookup checks protection attributes: may signal Data Abort Replacement either Round-Robin (deault) or Random ARM Page Tables (1) MicroTLB lookup (2) Main TLB lookup (3) Translation table walk Instruction MicroTLB Main TLB 2 nd level: Main TLB catches cache misses rom microtlbs 8 ully associative entries (may be locked) + 64 low associative entries variable number o cycles or lookup lockdown region o 8 entries (important or real-time) Entries are globally mapped or associated ASID and NSTID base Data 1 st level table MicroTLB (per process) One o two base registers (TTBR0/TTRBR1) is used I N most signiicant bits o virtual address are 0 then use TTBR0 else use TTBR1 N is deined by the Translation Table Base Control Register (TTBCR) 2 nd level tables (set per process) 19 20 Translation low or a section (1 MB) Translation low or a supersection (16 MB) 31 20 19 0 31 24 23 12 11 0 Virtual address Table index (12 bits) Section oset (20 bits) Virtual address Table index (8 bits) Supersection oset (24 bits) Physical section = read [Translation table base + table index] Physical address = physical section : section oset Supersection base address, Extended base address = read [Translation table base + table index] Real address = Extended base address : physical section : section oset Real address 31 20 19 0 Physical section (12 bits) Section oset (20 bits) Real address 39 32 31 24 23 0 Extended base address (8 bits) Supersection base address (8 bits) Supersection oset (24 bits) 40 bit address (1 TB) 21 22 Translation low or a small page (4KB) Translation low or a large page (64KB) Virtual address 31 20 19 12 11 0 Second-level index First level index (12 bits) Page oset (12 bits) (8 bits) Virtual address 31 20 19 16 15 0 Second-level First level index (12 bits) Page oset (16 bits) index (4 bits) Page table address = read [Translation table base + irst-level index] Physical page = read[page table address + second-level index] Real address = physical page : page oset Page table address = Read [Translation table base + irst-level index] Physical page = read[page table address + second-level index] Physical address = physical page : page oset 31 12 11 0 31 16 15 0 Real address Physical page (20 bits) Page oset (12 bits) Real address Physical page (16 bits) Page oset (16 bits) 23 24 2014-2015 Paul Krzyzanowski 4

Memory Protection & Control Domains Clients execute & access data within a domain. Each access is checked against access permissions or each memory block Memory region attributes Execute never Read-only, read/write, no access Privileged read-only, privileged & user read-only Non-secure (is this secure memory or not?) Sharable (is this memory shared with other processors) Strongly ordered (memory accesses must occur in program order) Device/shared, device/non-shared Normal/shared, normal/non-shared Signal Memory Abort i permission is not valid or access MMU Example: x86-64 25 26 IA-32 Memory Models Flat memory model Linear address space Single, contiguous address space Segmented memory model Memory appears as a group o independent address spaces: segments (code, data, stack, etc.) Logical address = {segment selector, oset} 16,383 segments; each segment can be up to 2 32 bytes Real mode 8086 model Segments up to 64KB in size maximum address space: 2 20 bytes Segments Each segment may be up to 4 GB Up to 16 K segments per process Two partitions per process Local: private to the process Up to 8 K segments Ino stored in a Local Descriptor Table (LDT) Global: shared among all processes Up to 8 K segments Ino stored in a Global Descriptor Table (GDT) Logical address is (segment selector, oset) Segment selector = 16 bits: 13 bits segment number + 1 bit LDT/GDT ID + 2 bits protection 27 28 IA-32 Segmentation & Paging Segment selector 16 bits Logical Address (Far Pointer) Segment Descriptor Segment Descriptor Oset 32 bits Global Descriptor Table (GDT) Local Descriptor Table (LDT) Segment base address Segmentation + Linear Address Space segment Linear Addr page Linear Address Dir Table Oset Page Directory Entry + Paging Entry Page Table + Physical Address Space Physical Addr Segment protection S lag in segment descriptor identiies code or data segment Accessed (reerenced) has the segment been accessed since the last time the OS cleared the bit? Dirty Has the page been modiied? Data Write-enable Read-only or read/write? Expansion direction Expand down (e.g., or stack): dynamically changing the segment limit causes space to be added to the bottom o the stack Code Execute only, execute/read (e.g., constants in code segment) Conorming: Execution can continue even i privilege level is elevated 29 30 2014-2015 Paul Krzyzanowski 5

IA-32 Paging Intel 64-bit mode 32-bit registers, 36-bit address space (64 GB) Physical Address Extension (PAE) Bit 5 o control register CR4 52 bit physical address support (4 PB o memory) Only a 4 GB address space may be accessed at one time Page Size Extensions (PSE-36) 36-bit page size extension (64 GB o memory) Supports up to 4 MB page size Segments supported only in IA-32 emulation mode Mostly disabled or 64-bit mode 64-bit base addresses where used Three paging modes 32-bit paging 32-bit virtual address; 32-40 bit physical address 4 KB or 4 MB pages PAE 32-bit virtual addresses; up to 52-bit physical address 4 KB or 2 MB pages IA-32e paging 48-bit virtual addresses; up to 52-bit physical address 4 KB, 2 MB, or 1 GB pages 31 32 32-bit paging with 4 KB pages 32-bit paging with 4 MB pages 31 22 21 12 11 0 Virtual address Directory (10 bits) Page table (10 bits) Oset (12 bits) Virtual address 31 22 21 0 Directory (10 bits) Oset (22 bits) PDE PTE Physical address PDE Physical address 18 bits CR3 register Page directory Page Table 4 KB page CR3 register Page directory 4 MB page 33 34 32-bit paging with 4 KB pages & PAE paging IA-32e paging with 4 KB pages 31 30 29 21 20 12 11 0 Virtual address Directory () Page table () Oset (12 bits) 47 39 38 30 29 21 20 12 11 0 Virtual address PML4 () Directory ptr () Directory () Page table () Oset (12 bits) 12 bits PDE PTE Physical address PDE PTE Physical address 40 bits 40 bits PDPTE value Page directory pointer table CR3 register Page directory Page Table 4 KB page PML4E CR3 register PDPTE Page directory pointer table Page directory Page Table 4 KB page 35 36 2014-2015 Paul Krzyzanowski 6

IA-32e paging with 2 MB pages IA-32e paging with 1 GB pages Virtual address 47 PML4 () 39 38 30 29 21 20 0 Directory ptr () Directory () Oset (21 bits) Virtual address 47 PML4 () 39 38 30 29 0 Directory ptr () Oset (30 bits) 21 bits 30 bits PDE Physical address Physical address 31 bits PML4E PDPTE Page directory 2 MB page PML4E PDPTE 22 bits 2 MB page CR3 register Page directory pointer table CR3 register Page directory pointer table 37 38 Example: TLBs on the Core i7 Managing Page Tables 4 KB pages Instruction TLB: 128 entries per core Data TLB: 64 entries Core 2 Duo: 16 entries TLB0; 256 entries TLB1 Atom: 64-entry TLB, 16-entry PDE Linux: architecture independent (mostly) Avoids segmentation (only Intel supports it) Abstract structures to model 4-level page tables Actual page tables are stored in a machine-speciic manner Second-level uniied TLB 512 entries 39 40 Recap Fragmentation is a non-issue Page table Page table entry (PTE) Multi-level page tables Demand Paging Segmentation Segmentation + Paging Memory protection Isolation o address spaces Access control deined in PTE 41 42 2014-2015 Paul Krzyzanowski 7

Executing a program Executing a program Allocate memory + stack Load the entire program rom memory (including any dynamically linked libraries) Then execute the loaded program Allocate memory + stack Load the entire program rom memory (including any dynamically linked libraries) Then execute the loaded program This can take a while! There s a better way 43 44 Demand Paging Demand Paging: At Process Start Load pages into memory only as needed On irst access Pages that are never used never get loaded Open executable ile Set up memory map (stack & text/data/bss) But don t load anything! Use valid bit in page table entry Valid: the page is in memory ( valid mapping) Invalid: out o bounds access or page is not in memory Have to check the process memory map in the PCB to ind out Load irst page & allocate initial stack page Run it! Invalid memory access generates a page ault 45 46 Memory Mapping Demand Paging: Page Fault Handling Executable iles & libraries must be brought into a process virtual address space File is mapped into the process memory As pages are reerenced, page rames are allocated & pages are loaded into them vm_area_struct Deines regions o virtual memory Used in setting page table entries Start o VM region, end o region, access rights Several o these are created or each mapped image Executable code, initialized data, uninitialized data Eventually the process will access an address without a valid page OS gets a page ault rom the MMU What happens? Kernel searches a tree structure o memory allocations or the process to see i the aulting address is valid I not valid, send a SEGV signal to the process Is the type o access valid or the page? Send a signal i not We have a valid page but it s not in memory Go get it rom the ile! 47 48 2014-2015 Paul Krzyzanowski 8

Keeping track o a processes memory region Page Replacement vm_end Linux stores inormation about a process address space in the memory descriptor o the PCB. vm_start vm_area_struct Memory descriptor Memory region Memory region Memory region Memory region vm_end vm_start vm_end vm_start vm_end A process can run without having all o its memory allocated It s allocated on demand I the {address space used by all processes + OS} physical memory then we re ok Otherwise: Make room: discard or store a page onto the disk I the page came rom a ile & was not modiied Discard we can always get it I the page is dirty, it must be saved in a page ile (aka swap ile) Page ile: a ile (or disk partition) that holds excess pages Windows: pageile.sys Linux: swap partition or swap ile OS X: multiple swap iles in /private/var/vm/swapile* vm_start Process virtual address space 49 50 Demand Paging: Getting a Page Cost The page we need is either in the a mapped ile (executable or library) or in a page ile I PTE is not valid but page # is present The page we want has been saved to a swap ile Page # in the PTE tells us the location in the ile I the PTE is not valid and no page # Load the page rom the program ile rom the disk Read page into physical memory 1. Find a ree page rame (evict one i necessary) 2. Read the page: This takes time: context switch & block 3. Update page table or the process 4. Restart the process at the instruction that aulted Handle page ault exception: ~ 400 usec Disk seek & read: ~ 10 msec Memory access: ~ 100 ns Page ault degrades perormance by around 100,000!! Avoid page aults! I we want < 10% degradation o perormance, we must have just one page ault per 1,000,000 memory accesses 51 52 Page replacement FIFO Replacement We need a good replacement policy or good perormance First In, First Out Good May get rid o initialization code or other code that s no longer used Bad May get rid o a page holding requently used global variables 53 54 2014-2015 Paul Krzyzanowski 9

Least Recently Used (LRU) Not Frequently Used Replacement Timestamp a page when it is accessed When we need to remove a page, search or the one with the oldest timestamp Nice algorithm but Timestamping is a pain we can t do it with the MMU! Approximate LRU behavior Each PTE has a reerence bit Keep a counter or each page rame At each clock interrupt: Add the reerence bit o each rame to its counter Clear reerence bit To evict a page, choose the rame with the lowest counter Problem No sense o time: a page that was used a lot a long time ago may still have a high count Updating counters is expensive 55 56 Clock (Second Chance) Enhanced Clock Arrange physical pages in a logical circle (circular queue) Clock hand points to irst rame Paging hardware keeps one reerence bit per rame Set reerence bit on memory reerence I it s not set then the rame hasn t been used or a while On page ault: Advance clock hand Check reerence bit I 1, it s been used recently clear & advance I 0, evict this page Use the reerence and modiy bits o the page Choices or replacement (reerence, modiy): (0, 0): not reerenced recently or modiied Good candidate or replacement (0, 1): not reerenced recently but modiied. The page will have to be saved beore replacement (1, 0): recently used. Less ideal will probably be used again (1, 1): recently used and modiied Least ideal will probably be used again AND we ll have to save it to a swap ile i we replace it. Algorithm: like clock but replace the irst page in the lowest non-empty class 57 58 Kernel Swap Daemon Demand paging summary kswapd on Linux Anticipate out-o-memory problems Decides whether to shrink caches i page count is low Page cache, buer cache Evict pages rom page rames Allocate page table Map kernel memory Initialize stack Memory-map text & date rom executable program (& libraries) But don t load! Load pages on demand (irst access) When we get a page ault 60 61 2014-2015 Paul Krzyzanowski 10

CPU utilization Summary: I we run out o ree page rames Free some page rames Discard pages that are mapped to a ile or Move some pages to a page ile Paging: Multitasking Considerations Clock algorithm Anticipate need or ree page rames kswapd kernel swap dæmon 62 63 Supporting multitasking Working Set Multiple address spaces can be loaded in memory Each process sees its own address space Illusion is created by the page table A CPU page table register points to the current page table OS changes the register set when context switching Includes page table register Perormance increased with Address Space ID in TLB Can cache page number page rame number caching Avoid the need or page table lookups Keep active pages in memory A process needs its working set in memory to perorm well Working set = Set o pages that have been reerenced in the last window o time Spatial locality Size o working set varies during execution More processes in a system: Good Increase throughput; chance that some process is available to run Bad Thrashing: processes do not have enough page rames available to run without paging 64 65 Thrashing Resident Set Management Locality Process migrates rom one working set to another Thrashing Occurs when sum o all working sets > total memory There is not enough room to hold each process working set Resident set = set o a process pages in memory How many pages o a process do we bring in? Resident set can be ixed or variable Replacement scope: global or local Global: process can pick a replacement rom all rames Variable allocation with global scope Simple Replacement policy may not take working sets into consideration Variable allocation with local scope More complex Modiy resident size to approximate working set size Degree o multiprogramming 66 67 2014-2015 Paul Krzyzanowski 11

Working Set Model Page ault requency Approximates locality o a program : working set window: Amount o elapsed time while the process was actually executing (e.g., count o memory reerences) Too small a working set causes a process to thrash Monitor page ault requency per process I too high, the process needs more rames I too low, the process may have too many rames WSS i : working set size o process P i WSS i = set o pages in most recent page reerences System-wide demand or rames D = WSS i I D > total memory size, then we get thrashing 68 69 Dealing with thrashing Real-Time Considerations I all else ails Suspend a process(es) Lowest priority, Last activated, smallest resident set,? Swapping Move an entire process onto the disk: no pages in memory Process must be re-loaded to run Not used on modern systems (Linux, Windows, etc.) Term is now oten used interchangeably with paging Avoid paging time-critical processes The pages they use will sit in memory Watch out or demand paging Might cause latency at a bad time Avoid page table lookup overhead Ensure that process memory is mapped in the TLB Pin high-priority real-time process memory into TLB (i possible) Or run CPU without virtual addressing 70 71 Memory-mapped iles Allocating memory to processes Use the virtual memory mechanism to treat ile I/O as memory accesses Use memory operations instead o read & write system calls Associate part o the virtual address space with a ile Initial access to the ile Results in page ault & read rom disk Subsequent accesses Memory operations mmap system call Multiple processes may map the same ile to share data When a process needs more memory Pages allocated rom kernel Use page replacement algorithms (e.g., clock, enhanced clock, ) When do processes need more memory? Demand paging (loading in text & static data rom executable ile) Memory mapped iles via mmap (same as demand paging) Stack growth (get a page ault) Process needs more heap space malloc is a user-level library: reuses space on the heap brk system call: change the data segment break point malloc requests big chunks to avoid system call overhead More recently, use mmap to map anonymous memory memory not associated with a ile 72 73 2014-2015 Paul Krzyzanowski 12

The End 74 2014-2015 Paul Krzyzanowski 13