Virtual Memory Management in Linux (Part II)

Size: px
Start display at page:

Download "Virtual Memory Management in Linux (Part II)"

Transcription

1 Virtual Memory Management in Linux (Part II) Minsoo Ryu Department of Computer Science and Engineering

2 2 1 Page Table and Page Fault Handling Page X 2 Page Cache Page X 3 Page Frame Reclamation (Swapping and OOM) Page X 4 Q & A Page X 2

3 3 Page Table In Linux, the page tables consist of three levels Page global directory (PGD) Consists of an array of pgd_t Entries in PGD point to entries in PMD Page middle directory (PMD) Consists of an array of pmd_t Entries in PMD point to entries in PTE Page table (PTE) Consists of an array of pte_t Page table entries point to physical pages 3

4 4 Virtual Address Structure Not only the length but also the way are different depending on the processor architectures 4

5 5 Three-Level Page Table 5

6 6 Page Fault Handling An assembler routine serves as the entry point for page fault (in arch/x86/kernel/entry_32.s) Invokes do_page_fault()(in arch/x86/mm/fault.c) 6

7 7 Page Fault Handling Complex logic: Easier to read code than read this slide! 7

8 8 Page Fault Handling The page fault is finally handled by the handle_pte_fault() function 8

9 9 Demand Fetching via Page Faults 9

10 Page Cache

11 11 Page Cache The page cache is a cache of pages in RAM that correspond to physical blocks on a disk The pages originate from reads and writes of regular filesystem files, block device files, and memory-mapped files During a page I/O operation, such as read(), The kernel checks whether the data resides in the page cache If the data is in the page cache, the kernel can quickly return the requested page from memory rather than read the data off the comparatively slow disk 11

12 12 The address_space Object Linux page cache uses a new object to manage entries in the cache and page I/O operations That object is the address_space structure The address_space object is the physical analogue to the virtual vm_area_struct While a single file may be represented by 10 vm_area_struct structures (if, say, five processes each mmap() it twice), the file has only one address_space structure A physical page is 4KB in size on the x86 architecture, whereas a disk block on many filesystems can be as small as 512 bytes Therefore, 8 blocks might fit in a single page The blocks need not be contiguous because the files might be laid out all over the disk 12

13 13 The address_space Object The address_space structure is defined in <linux/fs.h>: 13

14 14 Finding a Cached Page Whenever a process issues the read() system call Kernel checks if the requisite data is in the page cache 14

15 15 Radix Tree Each address_space has a unique radix tree stored as page_tree A radix tree is a type of binary tree The radix tree enables quick searching for the desired page, given only the file offset Page cache searching functions such as find_get_page() call radix_tree_lookup(), which performs a search on the given tree for the given object The find_get_page() function receives as its parameters a pointer to an address_space and an offset value The offset value is used as the key for radix tree searching 15

16 16 Binary Trie Trie (comes from retrieval) An ordered tree data structure to store a dynamic set or associative array where the keys are usually strings 16

17 17 Radix Trie (Patricia Trie or Radix Tree) Searching for R = move right (since bit 0 is 1), then left (since bit 4 is 0) On the way down the tree, we check only the key bits indicated in the numbers over the nodes (and ignore the keys in the nodes) Searching for S = or I = 01001? 17

18 18 Radix Trie (Patricia Trie) Inserting I = We add a new node to check bit 4, since H = and I = differ in only that bit (top) 18

19 19 Radix Tree for Page Cache Consists of three data structures radix_tree_root The root node radix_tree_node Node for the intermediate node page The leaf node 19

20 20 Radix Tree for Page Cache The root of the tree: radix_tree_root Holds the height of the tree and a pointer to the first node data structure height specifies the current height of the tree Maximum number of pages that can be stored in a tree can be derived from height rnode points the first node of the tree 20

21 21 Radix Tree for Page Cache The node of the tree: radix_tree_node Basically arrays with 2 RADIX_TREE_MAP_SHIFT entries Typically RADIX_TREE_MAP_SHIFT = 6 (2 6 = 64 entries) Each entry is called slot Points either to other nodes or to data elements (pages) Unused entries have null pointers 21

22 22 Write Caching Data ends up in the page cache via read operations, but what happens when a process writes to disk? Two strategies Write-through: automatically update both the in memory cache and the on-disk file Write-back: perform write operations directly into the page cache, but the backing store is not immediately or directly updated Instead, the written-to pages in the page cache are marked as dirty and are added to a dirty list Periodically, pages in the dirty list are written back to disk 22

23 23 Flusher Threads Dirty page writeback occurs in three situations: When free memory shrinks below a specified threshold When dirty data grows older than a specific threshold When a user process invokes the sync() and fsync() system calls A gang of kernel threads, the flusher threads, performs write-back operations When free memory drops below this threshold, the kernel invokes the wakeup_flusher_threads() A flusher thread periodically wakes up (unrelated to lowmemory conditions) and writes out old dirty pages 23

24 24 Cache Eviction Cache eviction is required either to make room for more relevant cache entries or to shrink the cache to make available more RAM for other uses Linux simply replaces them with something else The ideal eviction strategy evicts the pages least likely to be used in the future Such a strategy is ideal, but impossible to implement LRU (least recently used) is a good strategy However, one particular failure of the LRU strategy is that many files are accessed once and then never again 24

25 25 Two-List Strategy Linux keeps two lists Active list: pages considered hot and not available for eviction Inactive list: pages available for cache eviction Pages are placed on the active list only when they are accessed while already residing on the inactive list Both lists are maintained in a pseudo-lru manner Items are added to the tail and removed from the head, as with a queue The lists are kept in balance: If the active list becomes much larger than the inactive list, items from the active list s head are moved back to the inactive list 25

26 26 Two-List Strategy The two-list strategy solves the only-used-once failure in a classic LRU and also enables simpler, pseudo-lru semantics to perform well This two-list approach is also known as LRU/2; it can be generalized to n-lists, called LRU/n 26

27 27 Read Ahead Predicts the future requests and read ahead the pages that is expected to be read in the next request Usually pages are read sequentially, it therefore makes sense to read ahead the following data Example When a process has read a file linearly from position A to B, this practice will usually continue for a while 27

28 28 Read Ahead The current Linux controls read-ahead mechanism from three places do_generic_file_read() Standard routines of the kernel to read data Triggered by read() system call filemap_fault() Page fault handler to read missing page from memory mapping generic_file_splice_read() Support the splice system call that allows for passing data between two file descriptors directly in kernel space 28

29 29 Read Ahead When process attempts to perform read operation via do_generic_file_read() It firstly find the contents in the page cache It then perform synchronous read-ahead and asynchronous read-ahead consecutively 29

30 30 Read Ahead Synchronous/asynchronous read-ahead File is equipped with file_ra_state structure 30

31 31 Read Ahead 31

32 Page Frame Reclamation (Swapping & OOM)

33 33 Page Frame Reclamation Page frame reclaiming must be performed before all the free memory has been used up Otherwise, the kernel might be easily trapped in a deadly chain of memory requests that leads to a system crash If no free page frame exists, no page frame can be freed To free a page frame the kernel must write its data to disk, the kernel requires another page frame (to allocate the buffer heads for the I/O data transfer) One of the goals of page frame reclaiming is to conserve a minimal pool of free page frames so that the kernel may safely recover from "low on memory" conditions 33

34 34 Target Pages for Reclamation 34

35 35 Entry Points for Page Frame Reclamation 35

36 36 The try_to_free_pages Function The goal of try_to_free_pages is to free at least 32 page frames Repeatedly invoke the shrink_caches( ) and shrink_slab( ) functions shrink_caches( ) reclaims inactive pages shrink_slab( ) reclaims pages from the shrinkable kernel caches One last resort is killing a process to free all its page frames (out_of_memory) 36

37 37 Two Lists and LRU Linux kernel maintains LRU cache Makes use of page vectors to collect page instances Place them block-by-block on the system s active and inactive lists 37

38 38 Two Lists and LRU Two flags PG_active denotes the current activity rating PG_referenced signals if page has been recently referenced 38

39 39 Two Lists and LRU 39

40 40 Out of Memory Killer The out_of_memory( ) function is invoked by alloc_pages( ) when the free memory is very low and other techniques fail to reclaim page frames Invoke select_bad_process( ) to select a victim among the existing processes Invokes oom_kill_process( ) to perform the sacrifice 40

41 41 Out of Memory Killer Criteria for victim process selection The victim should own a large number of page frames Killing the victim should lose a small amount of work It is not a good idea to kill a batch process that has been working for hours or days The victim should be a low static priority process The victim should not be a process with root privileges The victim should not directly access hardware devices (such as the X Window server), because the hardware could be left in an unpredictable state The victim cannot be swapper (process 0), init (process 1), or any other kernel thread 41

42 42 The kswapd Kernel Thread Invoke shrink_zone( ) and shrink_slab( ) to reclaim pages from the LRU lists kswapd works in two different manners When the remaining free page is below WMARK_LOW Swapping daemon is woken up and swaps the pages out When the remaining free page is below WMARK_MIN Kernel directly frees the pages 42

43 43 Swapping Swapping is to use some space on disk as an extension of RAM Swap areas The pages swapped out from memory are stored in a swap area It may be implemented either as a disk partition of its own or as a file Several different swap areas may be defined, up to a maximum number specified by the MAX_SWAPFILES macro (usually set to 32) Each swap area consists of a sequence of page slots: 4,096-byte blocks used to contain a swapped-out page 43

44 44 Swap Area Structure 44

45 45 Swap Cache Transferring pages to and from a swap area is an activity that can induce many race conditions Multiple swap-ins Two processes may concurrently try to swap in the same shared anonymous page Concurrent swap-ins and swap-outs A process may swap-in a page that is being swapped out by the kernel The swap cache has been introduced to solve these kinds of synchronization problems The key rule is that nobody can start a swap-in or swapout without checking whether the swap cache already includes the affected page 45

46 46 Swapping Out Pages Four steps Inserting the page frame in the swap cache The add_to_swap( ) function allocates a new page slot in a swap area and inserts a page frame in the swap cache Updating the Page Table entries Writing the page into the swap area The swap_writepage( ) function invokes submit_bio( ) Removing the page frame from the swap cache Invoke delete_from_swap_cache( ) to remove the page frame from the swap cache 46

47 47 Swapping In Pages Swap-in takes place when a process attempts to address a page that has been swapped out to disk When the page fault is triggered, Chooses page fault handler according to the relevant page table entry If no page table entry is present, Kernel must load the page from scratch via do_linear_fault() or do_anonymous_page() If the page is marked as not present but information on the page is held in the page table, do_swap_page() handles the fault If the page table entry belongs to a nonlinear mapping, do_nonlinear_fault() handles the fault 47

48 48 Procedures for Swapping In Pages At the first time, kernel must check whether the requested page is still in the swap cache by invoking the do_swap_page() Function If it is, read data from the cache 48

49 49 Procedures for Swapping In Pages If the page is not in the swap cache, Cause the page to be read via read_swap_cache_async() Initiate a read-ahead operation to read a few pages in anticipation via swapin_readahead() Read request are issued not only for the desired page but also for a few pages in the adjacent slots 49

50 50 Procedures for Swapping In Pages Code flow for read_swap_cache_async() find_get_page() is invoked to check whether the page is in the swap cache If the page is found in the cache, the desired page is immediately returned 50

51 51 Procedures for Swapping In Pages If the page is not found, page_alloc_vma() is invoked to allocate a fresh memory page to hold the data from the swap area If this function fails to allocate new pages, the higher level code instructs the OOM killer to close the least-important process 51

52 52 Procedures for Swapping In Pages If the page is successfully reserved, Kernel adds the page instance To the swap cache via add_to_swap_cache() To the LRU cache via lru_cache_add_active() The page data are then transferred from the swap area to RAM by means of swap_readpage() 52

53 53 swapin_readahead() As when reading files, the kernel also uses a readahead mechanism to read data from swap areas Ensure that data are read in anticipation so that future page-in requests can be satisfied quickly Improving system performance 53

54 54 Low Memory Killer (LMK) Android has a low-memory-killer which is a in kernel driver that watches memory levels and will kill specified applications before we hit critical OOM levels Avoids poor performance immediately before OOM Uses slab shrinker Particularly useful with no swap Android uses the standard oom_adj process property to prioritize the pool of running processes and choose which to kill to free system memory Enables user-space policies to control which process should be killed on low memory 54

55 55 Low Memory Killer (LMK) oom_adj Represents the importance of process Processes can be persistent, foreground, visible, service, background, and empty process A small value of oom_adj means a more important process min_free Threshold value for the amount of free memory When the free memory drops below a certain min_free value, processes whose oom_adj value is greater than or equal to the specified value will be killed 55

56 56 56

Virtual Memory Management

Virtual Memory Management Virtual Memory Management CS-3013 Operating Systems Hugh C. Lauer (Slides include materials from Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating

More information

CSE506: Operating Systems CSE 506: Operating Systems

CSE506: Operating Systems CSE 506: Operating Systems CSE 506: Operating Systems Block Cache Address Space Abstraction Given a file, which physical pages store its data? Each file inode has an address space (0 file size) So do block devices that cache data

More information

An Evaluation of the Linux Virtual Memory Manager to Determine Suitability for Runtime Variation of Memory

An Evaluation of the Linux Virtual Memory Manager to Determine Suitability for Runtime Variation of Memory An Evaluation of the Linux Virtual Memory Manager to Determine Suitability for Runtime Variation of Memory by Vijay Kumar Muthukumaraswamy Sivakumar Thesis submitted to the faculty of the Virginia Polytechnic

More information

Memory Management. Fundamentally two related, but distinct, issues. Management of logical address space resource

Memory Management. Fundamentally two related, but distinct, issues. Management of logical address space resource Management Fundamentally two related, but distinct, issues Management of logical address space resource On IA-32, address space may be scarce resource for a user process (4 GB max) Management of physical

More information

File Systems: Consistency Issues

File Systems: Consistency Issues File Systems: Consistency Issues File systems maintain many data structures Free list/bit vector Directories File headers and inode structures res Data blocks File Systems: Consistency Issues All data

More information

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007 15-410...The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007 Dave Eckhardt Bruce Maggs 1 L16_VM2 Wean Synchronization Watch for exam e-mail Please answer promptly Computer Club demo night Thursday (2/22)

More information

CS 4284 Systems Capstone

CS 4284 Systems Capstone CS 4284 Systems Capstone Disks & File Systems Godmar Back Disks & Filesystems Disk Schematics Source: Micro House PC Hardware Library Volume I: Hard Drives 3 Tracks, Sectors, Cylinders 4 Hard Disk Example

More information

Virtual Memory #2 Feb. 21, 2018

Virtual Memory #2 Feb. 21, 2018 15-410...The mysterious TLB... Virtual Memory #2 Feb. 21, 2018 Dave Eckhardt Brian Railing 1 L16_VM2 Last Time Mapping problem: logical vs. physical addresses Contiguous memory mapping (base, limit) Swapping

More information

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 8: Virtual Memory. Operating System Concepts Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2009 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

OPERATING SYSTEM. Chapter 9: Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory OPERATING SYSTEM Chapter 9: Virtual Memory Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory

More information

CSE 506: Opera.ng Systems. The Page Cache. Don Porter

CSE 506: Opera.ng Systems. The Page Cache. Don Porter The Page Cache Don Porter 1 Logical Diagram Binary Formats RCU Memory Management File System Memory Allocators Threads System Calls Today s Lecture Networking (kernel level Sync mem. management) Device

More information

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Swapping Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Swapping Support processes when not enough physical memory User program should be independent

More information

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Swapping Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE0: Introduction to Operating Systems, Fall 07, Jinkyu Jeong (jinkyu@skku.edu) Swapping

More information

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability Topics COS 318: Operating Systems File Performance and Reliability File buffer cache Disk failure and recovery tools Consistent updates Transactions and logging 2 File Buffer Cache for Performance What

More information

Memory Management Day 2. SWE3015 Sung- hun Kim

Memory Management Day 2. SWE3015 Sung- hun Kim Memory Management Day 2 SWE3015 Sung- hun Kim VIRTUAL MEMORY IMPLEMENTATION 2 Linux 32 bit address space layout Process Address Space 3/39 Linux 64 bit address space layout Process Address Space 4/39 Process

More information

Caching and reliability

Caching and reliability Caching and reliability Block cache Vs. Latency ~10 ns 1~ ms Access unit Byte (word) Sector Capacity Gigabytes Terabytes Price Expensive Cheap Caching disk contents in RAM Hit ratio h : probability of

More information

Virtual to physical address translation

Virtual to physical address translation Virtual to physical address translation Virtual memory with paging Page table per process Page table entry includes present bit frame number modify bit flags for protection and sharing. Page tables can

More information

Virtual Memory. Computer Systems Principles

Virtual Memory. Computer Systems Principles Virtual Memory Computer Systems Principles Objectives Virtual Memory What is it? How does it work? Virtual Memory Address Translation /7/25 CMPSCI 23 - Computer Systems Principles 2 Problem Lots of executing

More information

Design of Operating System

Design of Operating System Design of Operating System Architecture OS protection, modes/privileges User Mode, Kernel Mode https://blog.codinghorror.com/understanding-user-and-kernel-mode/ a register of flag to record what mode the

More information

Address spaces and memory management

Address spaces and memory management Address spaces and memory management Review of processes Process = one or more threads in an address space Thread = stream of executing instructions Address space = memory space used by threads Address

More information

CFLRU:A A Replacement Algorithm for Flash Memory

CFLRU:A A Replacement Algorithm for Flash Memory CFLRU:A A Replacement Algorithm for Flash Memory CASES'06, October 23 25, 2006, Seoul, Korea. Copyright 2006 ACM 1-59593-543-6/06/0010 Yen-Ting Liu Outline Introduction CFLRU Algorithm Simulation Implementation

More information

Linux Kernel Architecture

Linux Kernel Architecture Professional Linux Kernel Architecture Wolf gang Mauerer WILEY Wiley Publishing, Inc. Introduction xxvii Chapter 1: Introduction and Overview 1 Tasks of the Kernel v -- 2 Implementation Strategies 3 Elements

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013 CACHING Why: bridge speed difference between CPU and RAM Modern RAM allows blocks of memory to be read quickly Principle

More information

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19 PROCESS VIRTUAL MEMORY PART 2 CS24 Operating Systems Winter 25-26, Lecture 9 2 Virtual Memory Abstraction Last time, officially introduced concept of virtual memory Programs use virtual addresses to refer

More information

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

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t Memory Management Ch. 3 Memory Hierarchy Cache RAM Disk Compromise between speed and cost. Hardware manages the cache. OS has to manage disk. Memory Manager Memory Hierarchy Cache CPU Main Swap Area Memory

More information

Memory Management Ch. 3

Memory Management Ch. 3 Memory Management Ch. 3 Ë ¾¾ Ì Ï ÒÒØ Å ÔÔ ÓÐÐ 1 Memory Hierarchy Cache RAM Disk Compromise between speed and cost. Hardware manages the cache. OS has to manage disk. Memory Manager Ë ¾¾ Ì Ï ÒÒØ Å ÔÔ ÓÐÐ

More information

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28 Outline 1 Paging 2 Eviction policies 3 Thrashing 1 / 28 Paging Use disk to simulate larger virtual than physical mem 2 / 28 Working set model # of accesses virtual address Disk much, much slower than memory

More information

Switching Between Page Replacement Algorithms Based on Work Load During Runtime in Linux Kernel

Switching Between Page Replacement Algorithms Based on Work Load During Runtime in Linux Kernel San Jose State University SJSU ScholarWorks Master's Projects Master's Theses and Graduate Research Spring 5-22-2017 Switching Between Page Replacement Algorithms Based on Work Load During Runtime in Linux

More information

Virtual Memory Outline

Virtual Memory Outline Virtual Memory Outline Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples

More information

CS307: Operating Systems

CS307: Operating Systems CS307: Operating Systems Chentao Wu 吴晨涛 Associate Professor Dept. of Computer Science and Engineering Shanghai Jiao Tong University SEIEE Building 3-513 wuct@cs.sjtu.edu.cn Download Lectures ftp://public.sjtu.edu.cn

More information

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

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management CSE 120 July 18, 2006 Day 5 Memory Instructor: Neil Rhodes Translation Lookaside Buffer (TLB) Implemented in Hardware Cache to map virtual page numbers to page frame Associative memory: HW looks up in

More information

Chapter 8 Virtual Memory

Chapter 8 Virtual Memory Chapter 8 Virtual Memory Contents Hardware and control structures Operating system software Unix and Solaris memory management Linux memory management Windows 2000 memory management Characteristics of

More information

PROJECT 6: PINTOS FILE SYSTEM. CS124 Operating Systems Winter , Lecture 25

PROJECT 6: PINTOS FILE SYSTEM. CS124 Operating Systems Winter , Lecture 25 PROJECT 6: PINTOS FILE SYSTEM CS124 Operating Systems Winter 2015-2016, Lecture 25 2 Project 6: Pintos File System Last project is to improve the Pintos file system Note: Please ask before using late tokens

More information

Memory Mapping. Sarah Diesburg COP5641

Memory Mapping. Sarah Diesburg COP5641 Memory Mapping Sarah Diesburg COP5641 Memory Mapping Translation of address issued by some device (e.g., CPU or I/O device) to address sent out on memory bus (physical address) Mapping is performed by

More information

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

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition Chapter 9: Virtual Memory Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations

More information

Chapter 10: Virtual Memory

Chapter 10: Virtual Memory Chapter 10: Virtual Memory Chapter 10: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations

More information

CS399 New Beginnings. Jonathan Walpole

CS399 New Beginnings. Jonathan Walpole CS399 New Beginnings Jonathan Walpole Memory Management Memory Management Memory a linear array of bytes - Holds O.S. and programs (processes) - Each cell (byte) is named by a unique memory address Recall,

More information

The Page Cache 3/16/16. Logical Diagram. Background. Recap of previous lectures. The address space abstracvon. Today s Problem.

The Page Cache 3/16/16. Logical Diagram. Background. Recap of previous lectures. The address space abstracvon. Today s Problem. The Page Cache Don Porter Binary Formats RCU Memory Management File System Logical Diagram Memory Allocators Threads System Calls Today s Lecture Networking (kernel level Sync mem. management) Device CPU

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

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

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access) Virtual Memory - programmer views memory as large address space without concerns about the amount of physical memory or memory management. (What do the terms 3-bit (or 6-bit) operating system or overlays

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals: Part II Lecture 10, February 17, 2014 Mohammad Hammoud Last Session: DBMS Internals- Part I Today Today s Session: DBMS Internals- Part II Brief summaries

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Chapter 9: Virtual Memory 9.1 Background 9.2 Demand Paging 9.3 Copy-on-Write 9.4 Page Replacement 9.5 Allocation of Frames 9.6 Thrashing 9.7 Memory-Mapped Files 9.8 Allocating

More information

Chapter 8. Virtual Memory

Chapter 8. Virtual Memory Operating System Chapter 8. Virtual Memory Lynn Choi School of Electrical Engineering Motivated by Memory Hierarchy Principles of Locality Speed vs. size vs. cost tradeoff Locality principle Spatial Locality:

More information

Virtual Memory COMPSCI 386

Virtual Memory COMPSCI 386 Virtual Memory COMPSCI 386 Motivation An instruction to be executed must be in physical memory, but there may not be enough space for all ready processes. Typically the entire program is not needed. Exception

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 208 Lecture 23 LAST TIME: VIRTUAL MEMORY Began to focus on how to virtualize memory Instead of directly addressing physical memory, introduce a level of indirection

More information

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

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory Chapter 4: Memory Management Part 1: Mechanisms for Managing Memory Memory management Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design

More information

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 CPU management Roadmap Process, thread, synchronization, scheduling Memory management Virtual memory Disk

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012 ANNOUNCEMENTS Need student input on Lecturer Search Max Morawski Lecture 2:30pm 3:15pm, Fri 12/7, ITE 217 Meet with

More information

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

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Recap: Virtual Addresses A virtual address is a memory address that a process uses to access its own memory Virtual address actual physical

More information

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University Operating Systems CSE 410, Spring 2004 Virtual Memory Stephen Wagner Michigan State University Virtual Memory Provide User an address space that is larger than main memory Secondary storage is used to

More information

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

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Operating System Concepts 9 th Edition

Operating System Concepts 9 th Edition Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 24 LAST TIME Extended virtual memory concept to be a cache of memory stored on disk DRAM becomes L4 cache of data stored on L5 disk Extend page

More information

Memory Management and Protection

Memory Management and Protection Part IV Memory Management and Protection Sadeghi, Cubaleska RUB 2008-09 Course Operating System Security Memory Management and Protection Main Memory Virtual Memory Roadmap of Chapter 4 Main Memory Background

More information

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

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Memory Management 1 Hardware background The role of primary memory Program

More information

Basic Memory Management

Basic Memory Management Basic Memory Management CS 256/456 Dept. of Computer Science, University of Rochester 10/15/14 CSC 2/456 1 Basic Memory Management Program must be brought into memory and placed within a process for it

More information

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS6401- Operating System UNIT-III STORAGE MANAGEMENT UNIT-III STORAGE MANAGEMENT Memory Management: Background In general, to rum a program, it must be brought into memory. Input queue collection of processes on the disk that are waiting to be brought into

More information

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

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses. 1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 205 Lecture 23 LAST TIME: VIRTUAL MEMORY! Began to focus on how to virtualize memory! Instead of directly addressing physical memory, introduce a level of

More information

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU BCA-3 rd Semester 030010304-Fundamentals Of Operating Systems Unit: 1 Introduction Short Answer Questions : 1. State two ways of process communication. 2. State any two uses of operating system according

More information

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory Chapter 8 & Chapter 9 Main Memory & Virtual Memory 1. Various ways of organizing memory hardware. 2. Memory-management techniques: 1. Paging 2. Segmentation. Introduction Memory consists of a large array

More information

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

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed. CHAPTER 8: MEMORY MANAGEMENT By I-Chen Lin Textbook: Operating System Concepts 9th Ed. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the

More information

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo PAGE REPLACEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced

More information

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis Multi-level Translation CS 57 Lecture 9 Paging Michael Swift Problem: what if you have a sparse address space e.g. out of GB, you use MB spread out need one PTE per page in virtual address space bit AS

More information

Virtual Memory III. Jo, Heeseung

Virtual Memory III. Jo, Heeseung Virtual Memory III Jo, Heeseung Today's Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced virtual memory techniques Shared

More information

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

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory Multi-Process Systems: Memory (2) What we will learn A detailed description of various ways of organizing memory Discuss various memory-management techniques, including paging and segmentation To provide

More information

Memory management, part 3: outline

Memory management, part 3: outline Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 1 Segmentation Several address spaces per process a compiler needs segments for o source

More information

Managing Storage: Above the Hardware

Managing Storage: Above the Hardware Managing Storage: Above the Hardware 1 Where we are Last time: hardware HDDs and SSDs Today: how the DBMS uses the hardware to provide fast access to data 2 How DBMS manages storage "Bottom" two layers

More information

Main Points of the Computer Organization and System Software Module

Main Points of the Computer Organization and System Software Module Main Points of the Computer Organization and System Software Module You can find below the topics we have covered during the COSS module. Reading the relevant parts of the textbooks is essential for a

More information

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

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Chapter 9 Memory Management

Chapter 9 Memory Management Contents 1. Introduction 2. Computer-System Structures 3. Operating-System Structures 4. Processes 5. Threads 6. CPU Scheduling 7. Process Synchronization 8. Deadlocks 9. Memory Management 10. Virtual

More information

Virtual Memory. Chapter 8

Virtual Memory. Chapter 8 Chapter 8 Virtual Memory What are common with paging and segmentation are that all memory addresses within a process are logical ones that can be dynamically translated into physical addresses at run time.

More information

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

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD OPERATING SYSTEMS #8 After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD MEMORY MANAGEMENT MEMORY MANAGEMENT The memory is one of

More information

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

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts Memory management Last modified: 26.04.2016 1 Contents Background Logical and physical address spaces; address binding Overlaying, swapping Contiguous Memory Allocation Segmentation Paging Structure of

More information

Virtual Memory #3 Oct. 10, 2018

Virtual Memory #3 Oct. 10, 2018 15-410...The cow and Zaphod... Virtual Memory #3 Oct. 10, 2018 Dave Eckhardt Dave O'Hallaron 1 L19_VM3 Synchronization Exam Thursday! 18:30 Doherty A302 Homework 1 due tonight! Not at midnight! 2 Synchronization

More information

Virtual Memory. Chapter 8

Virtual Memory. Chapter 8 Virtual Memory 1 Chapter 8 Characteristics of Paging and Segmentation Memory references are dynamically translated into physical addresses at run time E.g., process may be swapped in and out of main memory

More information

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes Virtual memory Virtual memory - Swapping Johan Montelius KTH 2017 1: Allowing two or more processes to use main memory, given them an illusion of private memory. 2: Provide the illusion of a much larger

More information

Process size is independent of the main memory present in the system.

Process size is independent of the main memory present in the system. Hardware control structure Two characteristics are key to paging and segmentation: 1. All memory references are logical addresses within a process which are dynamically converted into physical at run time.

More information

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani Memory Management Virtual Memory By : Kaushik Vaghani Virtual Memory Background Page Fault Dirty Page / Dirty Bit Demand Paging Copy-on-Write Page Replacement Objectives To describe the benefits of a virtual

More information

Dan Noé University of New Hampshire / VeloBit

Dan Noé University of New Hampshire / VeloBit Dan Noé University of New Hampshire / VeloBit A review of how the CPU works The operating system kernel and when it runs User and kernel mode Device drivers Virtualization of memory Virtual memory Paging

More information

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

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Most common example today: wireless (cell) phones

Most common example today: wireless (cell) phones Virtual Memory Separate the concept of: address space (name) from physical memory address (location) Most common example today: wireless (cell) phones Phone number is your id or name Location varies as

More information

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1 Paging algorithms CS 241 February 10, 2012 Copyright : University of Illinois CS 241 Staff 1 Announcements MP2 due Tuesday Fabulous Prizes Wednesday! 2 Paging On heavily-loaded systems, memory can fill

More information

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

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization Requirements Relocation Memory management ability to change process image position Protection ability to avoid unwanted memory accesses Sharing ability to share memory portions among processes Logical

More information

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner CPS104 Computer Organization and Programming Lecture 16: Virtual Memory Robert Wagner cps 104 VM.1 RW Fall 2000 Outline of Today s Lecture Virtual Memory. Paged virtual memory. Virtual to Physical translation:

More information

Chapter 8: Memory-Management Strategies

Chapter 8: Memory-Management Strategies Chapter 8: Memory-Management Strategies Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and

More information

The Beast We Call A3. CS 161: Lecture 10 3/7/17

The Beast We Call A3. CS 161: Lecture 10 3/7/17 The Beast We Call A3 CS 161: Lecture 10 3/7/17 But first... Unconfusing Three Confusions Where does the kernel live? Does every kind of processor use a twolevel page table? Does everything have an address?

More information

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University Che-Wei Chang chewei@mail.cgu.edu.tw Department of Computer Science and Information Engineering, Chang Gung University l Chapter 10: File System l Chapter 11: Implementing File-Systems l Chapter 12: Mass-Storage

More information

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Lecture 21: Virtual Memory. Spring 2018 Jason Tang Lecture 21: Virtual Memory Spring 2018 Jason Tang 1 Topics Virtual addressing Page tables Translation lookaside buffer 2 Computer Organization Computer Processor Memory Devices Control Datapath Input Output

More information

Performance and Optimization Issues in Multicore Computing

Performance and Optimization Issues in Multicore Computing Performance and Optimization Issues in Multicore Computing Minsoo Ryu Department of Computer Science and Engineering 2 Multicore Computing Challenges It is not easy to develop an efficient multicore program

More information

Preview. Memory Management

Preview. Memory Management Preview Memory Management With Mono-Process With Multi-Processes Multi-process with Fixed Partitions Modeling Multiprogramming Swapping Memory Management with Bitmaps Memory Management with Free-List Virtual

More information

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory CPS 104 Computer Organization and Programming Lecture 20: Virtual Nov. 10, 1999 Dietolf (Dee) Ramm http://www.cs.duke.edu/~dr/cps104.html CPS 104 Lecture 20.1 Outline of Today s Lecture O Virtual. 6 Paged

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Background Demand Paging Chapter 9: Virtual Memory Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations

More information

The Operating System. Chapter 6

The Operating System. Chapter 6 The Operating System Machine Level Chapter 6 1 Contemporary Multilevel Machines A six-level l computer. The support method for each level is indicated below it.2 Operating System Machine a) Operating System

More information

Linux Memory Management

Linux Memory Management Linux Memory Management Virtual memory layout: a closer look Applications require memory with different properties access permissions sharing file backed vs. anonymous dynamically sized /proc/{pid}/maps

More information

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay Lecture 19: File System Implementation Mythili Vutukuru IIT Bombay File System An organization of files and directories on disk OS has one or more file systems Two main aspects of file systems Data structures

More information

The Journey of an I/O request through the Block Layer

The Journey of an I/O request through the Block Layer The Journey of an I/O request through the Block Layer Suresh Jayaraman Linux Kernel Engineer SUSE Labs sjayaraman@suse.com Introduction Motivation Scope Common cases More emphasis on the Block layer Why

More information

RCU. ò Walk through two system calls in some detail. ò Open and read. ò Too much code to cover all FS system calls. ò 3 Cases for a dentry:

RCU. ò Walk through two system calls in some detail. ò Open and read. ò Too much code to cover all FS system calls. ò 3 Cases for a dentry: Logical Diagram VFS, Continued Don Porter CSE 506 Binary Formats RCU Memory Management File System Memory Allocators System Calls Device Drivers Networking Threads User Today s Lecture Kernel Sync CPU

More information

Memory - Paging. Copyright : University of Illinois CS 241 Staff 1

Memory - Paging. Copyright : University of Illinois CS 241 Staff 1 Memory - Paging Copyright : University of Illinois CS 241 Staff 1 Physical Frame Allocation How do we allocate physical memory across multiple processes? What if Process A needs to evict a page from Process

More information

Percona Live September 21-23, 2015 Mövenpick Hotel Amsterdam

Percona Live September 21-23, 2015 Mövenpick Hotel Amsterdam Percona Live 2015 September 21-23, 2015 Mövenpick Hotel Amsterdam TokuDB internals Percona team, Vlad Lesin, Sveta Smirnova Slides plan Introduction in Fractal Trees and TokuDB Files Block files Fractal

More information