Virtual Memory – Managing Physical Memory

Slides:



Advertisements
Similar presentations
Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
Advertisements

The Linux Kernel: Memory Management
Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel)
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
File Systems.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Advanced Operating Systems - Spring 2009 Lecture 17 – March 23, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Fixed/Variable Partitioning
Allocating Memory.
CS 311 – Lecture 21 Outline Memory management in UNIX
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Operating Systems File Systems CNS 3060.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
File System Implementation: beyond the user’s view A possible file system layout on a disk.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Operating Systems File Systems (in a Day) Ch
Understanding Operating Systems1 Operating Systems Virtual Memory Thrashing Single-User Contiguous Scheme Fixed Partitions Dynamic Partitions.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
1 Memory Management in Representative Operating Systems.
Memory Allocation CS Introduction to Operating Systems.
The memory allocation problem Define the memory allocation problem Memory organization and memory allocation schemes.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Paging Example What is the data corresponding to the logical address below:
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
CE Operating Systems Lecture 14 Memory management.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
CS 3204 Operating Systems Godmar Back Lecture 21.
Paging Paging is a memory-management scheme that permits the physical-address space of a process to be noncontiguous. Paging avoids the considerable problem.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
W4118 Operating Systems Instructor: Junfeng Yang.
Virtual Memory By CS147 Maheshpriya Venkata. Agenda Review Cache Memory Virtual Memory Paging Segmentation Configuration Of Virtual Memory Cache Memory.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 33 Paging Read Ch. 9.4.
Memory Management & Virtual Memory. Hierarchy Cache Memory : Provide invisible speedup to main memory.
CS 3204 Operating Systems Godmar Back Lecture 18.
Non Contiguous Memory Allocation
Chapter 8: Main Memory.
CS Introduction to Operating Systems
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
File Systems Implementation
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 32 Syed Mansoor Sarwar
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Dynamic Memory Allocation
Buddy Allocation CS 161: Lecture 5 2/11/19.
Presentation transcript:

Virtual Memory – Managing Physical Memory CS 4284 Systems Capstone Virtual Memory – Managing Physical Memory Godmar Back

Physical Memory Management

Physical Memory Management Aka frame table management Task: keep efficiently track of which physical frames are used Allocate a frame when paging in, or eager loading Deallocate a frame when process exits or when page is evicted (later) MAX_PHYSICAL frames CS 4284 Spring 2015

Approach 1: Bitmaps Use bitmap to represent free, used pages Sometimes division in user & kernel pool Pintos (palloc.c) does that: keeps two bitmaps Kernel pool: 010010 User pool: 0000001 You will manage user pool only MAX_PHYSICAL user pool kernel pool frames 0100100000001 CS 4284 Spring 2015

Approach 2: Buddy Allocator Logically subdivide memory in power-of-two blocks Round up on allocation to next power of 2 Split block on allocation (if necessary) Coalesce on deallocation (if possible) Coalescing can be delayed Used in Linux: allocation requests are always multiple of pages, max blocksize is 4MB. Check out /proc/buddyinfo CS 4284 Spring 2015

Buddy Allocator Freelists Note: tree view is conceptual, not tree is actually built in implementation Implementation uses n freelists for free blocks of order k, representing allocation sizes of 2^(k+B) bytes. E.g., Linux uses orders 0-10 for 4KB, 8KB, … 4MB or 2^(0+12) … 2^(10+12) bytes. Note that free list pointers are kept entirely inside unused pages Needs a memory map to record size of used pages (ranges of pages) CS 4284 Spring 2015

Buddy Example - Allocation 64 KB Alloc (16KB) 16KB 16KB 32KB Alloc (32KB) 16KB 16KB 32KB Alloc (4KB) 16KB 4KB 4KB 8KB 32KB Alloc (4KB) 16KB 4KB 4KB 8KB 32KB Alloc (4KB) 16KB 4KB 4KB 4KB 4KB 32KB CS 4284 Spring 2015

Buddy Example - Deallocation 16KB 4KB 4KB 4KB 4KB 32KB Free() 16KB 4KB 4KB 4KB 4KB 32KB Free() 16KB 8KB 4KB 4KB 32KB Free() 16KB 16KB 32KB Free() 32KB 32KB Free() 64 KB CS 4284 Spring 2015

Fragmentation Def: The inability to use memory that is unused. Internal fragmentation: Not all memory inside an allocated unit is used; rest can’t be allocated to other users External fragmentation: Impossible to satisfy allocation request even though total amount of memory > size requested CS 4284 Spring 2015

Internal Fragmentation 64 KB Alloc (12KB) 12KB 16KB 32KB Alloc (24KB) 12KB 16KB 24KB Alloc (4KB) 12KB 4KB 4KB 8KB 24KB Alloc (4KB) 12KB 4KB 4KB 8KB 24KB Alloc (3KB) 12KB 4KB 4KB 3KB 4KB 24KB CS 4284 Spring 2015

External Fragmentation 16KB 4KB 4KB 4KB 4KB 32KB Free() No external fragmentation 16KB 4KB 4KB 4KB 4KB 32KB Free() Have 8 KB free, but can‘t Alloc(8KB) 16KB 8KB 4KB 4KB 32KB Free() Have 12 KB free, but can‘t Alloc(12KB) 16KB 16KB 32KB Free() No external fragmentation 32KB 32KB Free() 64 KB CS 4284 Spring 2015

Buddy Allocator & Fragmentation Q.: what is the average internal fragmentation (per allocated object) for buddy allocator with size 2^n? in bitmap allocator for objects of size n*s, where each bit represents a unit of size s? in first-fit allocator? Q.: what external fragmentation can you expect from buddy allocator scheme? Q.: what’s a good way to measure fragmentation in general? CS 4284 Spring 2015

Page Size & Fragmentation How should a system’s architect choose the page size? – Trade-Off Large pages: Larger internal fragmentation (not an issue if most pages are full…) Page-in & write-back cost larger Small pages: Higher overhead to store page table (more entries to maintain) Modern architectures provide support for “super pages” – 2MB or 4MB CS 4284 Spring 2015

Linux allocator characteristics Buddy allocator can suffer from bad external fragmentation, but: Most allocations are 1 page (all allocations for anonymous memory and file caching `page cache’ are). Large blocks of physically contiguous memory are rarely needed. Variety of intermediate allocators are used to reduce buddies’ fragmentation: slab allocators CS 4284 Spring 2015

Linux Memory Map Affine mapping from physical address to location in ‘memory map’ array struct page Careful bootstrapping process needed CS 4284 Spring 2015

Miscellaneous Support for non-contiguous zones Support for NUMA (one map per NUMA zone) NUMA-aware allocation Support for page migration Support for hot-swapping/turning memory banks off See [LWN 2013] update CS 4284 Spring 2015