Chapter 12. Kernel Memory Allocation

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Dynamic Memory Management
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.
The Linux Kernel: Memory Management
Liu Meihua Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory.
Kernel memory allocation
Memory Management Today Basic memory management Swapping Kernel memory allocation Next Time Virtual memory.
File Systems.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
1 Optimizing Malloc and Free Professor Jennifer Rexford COS 217 Reading: Section 8.7 in K&R book
Chapter 11: File System Implementation
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Linux Vs. Windows NT Memory Management Hitesh Kumar
Memory Management Memory Areas and their use Memory Manager Tasks:
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 12: File System Implementation
1 Optimizing Malloc and Free Professor Jennifer Rexford
Memory Management 2010.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Virtual Memory Chapter 8.
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
1 Outline File Systems Implementation How disks work How to organize data (files) on disks Data structures Placement of files on disk.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
1 Memory Management in Representative Operating Systems.
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Memory Allocation CS Introduction to Operating Systems.
The memory allocation problem Define the memory allocation problem Memory organization and memory allocation schemes.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
1. Memory Manager 2 Memory Management In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.
Subject: Operating System.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
File System Implementation
Chapter 17 Free-Space Management Chien-Chung Shen CIS, UD
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
Memory Management -Memory allocation -Garbage collection.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Virtual Memory – Managing Physical Memory
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
Lecture 7 Page 1 CS 111 Summer 2013 Dynamic Domain Allocation A concept covered in a previous lecture We’ll just review it here Domains are regions of.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
Chapter 17 Free-Space Management
Chapter 2: The Linux System Part 4
Memory Management Fred Kuhns.
File System Implementation
Chapter 11: File System Implementation
Chapter 9 – Real Memory Organization and Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Chapter 11: File System Implementation
Optimizing Malloc and Free
CS Introduction to Operating Systems
Page Replacement.
Memory Management Overview
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Presentation made by Steponas Šipaila
Dynamic Memory Allocation
COMP755 Advanced Operating Systems
Presentation transcript:

Chapter 12. Kernel Memory Allocation Introduction Resource Map Allocator Simple Power-of-Two Free Lists Mckusick-Karels Allocator Buddy System Mach-OSF/1 Zone Allocator Solaris 2.4 Slab Allocator

Introduction Page-level allocator Paging system Supports virtual memory system Kernel memory allocator Provides odd-sized buffers of memory to various kernel subsystems Kernel frequently needs chunks of memory of various sizes usually for short periods of time

Introduction (cont) Users of the kernel memory allocator pathname translation routine allocb( ) allocates STREAMs buffers of arbitrary size In SVR4, the kernel allocates many objects (proc structures, vnodes, file descriptor blocks) dynamically when needed

Introduction (cont) physical memory Page-level allocator kernel memory Paging system network buffers proc structures inodes, file descriptors user processes block buffer cache

Kernel Memory Allocator (KMA) Functional requirements Page-level allocator pre-allocates part of main memory to KMA, which must use this memory pool efficiently KMA also have to monitor which part of its pool are allocated and which are free Evaluation criteria Utilization factor KMA must be fast Both average and worst-cast latency are important Interaction with the paging system

Resource Map Allocator set of <base, size> for free memory First fit, Best fit, Worst bit policies Advantages Easy to implement Not restricted to memory allocation Allocates the exact numbers of bytes requested Client is not constrained to release the exact region it has allocated Allocator coalesces adjacent free regions

Resource Map Allocator (cont) Drawbacks Map may become highly fragmented As the fragmentation increases, so does the size of the map Sorting for coalescing adjacent regions is expensive Linear search to find a free region

Simple Power-of-Two Free List headers free buffers allocated blocks 32 64 128 256 512 1024

Simple Power-of-Two Free List (cont) Used frequently to implement malloc( ), and free( ) in the user-level C library One-word header for each buffer Advantages Avoids the lengthy linear search of the resource map method Eliminates the fragmentation problem

Simple Power-of-Two Free List (cont) Drawbacks Rounding of requests to the next power of two results in poor memory utilization No provision for coalescing adjacent free buffer to satisfy larger requests No provision to return surplus free buffers to the page-level allocator

Mckusick-Karels Allocator freelistaddr[ ] free buffers 32 allocated blocks 64 128 256 512 kmemsizes[ ] 32 512 64 F 32 128 F 32 32 256 64 F 2K F 128 freepages

Mckusick-Karels Allocator (cont) Used in 4.4BSD, Digital UNIX Requires that a set of contiguous pages all buffers belonging to the same page to be the same size States of each page Free corresponding element of kmemsizes[ ] contains a pointer to the element for the next free page Divided into buffers of a particular size kmemsizes[ ] element contains the size

Mckusick-Karels Allocator (cont) Part of a buffer that spanned multiple pages kmemsizes[ ] element corresponding to the first page of the buffer contains the buffer size Improvement over simple power-of-two Faster, wastes less memory, can handle large and small request efficiently Drawbacks No provision for moving memory from one list to another No way to return memory to the paging system

Buddy System Basic idea Advantages Disadvantages Combines free buffer coalescing with a power-of-two allocator When a buffer is split, each buffer is called the buddy of the other Advantages Coalescing adjacent free buffers Easy exchange of memory between the allocator and the paging system Disadvantages Performance degradation due to coalescing Program interface needs the size of the buffer

allocate(256)  allocate(128)  allocate(64) Buddy System (e.g.) allocate(256)  allocate(128)  allocate(64) bitmap 1 1 1 1 1 1 1 1 1 1 1 1 1 1 free list headers 32 64 128 256 512 256 384 448 512 1023 B C D D’ A’ C’ B’ free in use A

 allocate(128)  release(C, 128) Buddy System (e.g.)  allocate(128)  release(C, 128) bitmap 1 1 1 1 1 1 1 1 1 1 1 1 1 1 free list headers 32 64 128 256 512 256 384 448 512 640 768 1023 B C D D’ F F’ E’ C’ B’ E A A’

Buddy System (e.g.) B B’ F F’ E’  release(D, 64) bitmap 1 1 1 1 1 1 1 1 1 1 1 1 free list headers 32 64 128 256 512 256 512 640 768 1023 B B’ F F’ E’ C’ E A

SVR4 Lazy Buddy System Basic idea Lazy coalescing Defer coalescing until it becomes necessary, and then to coalesce as many buffers as possible Lazy coalescing N buffers, A buffers are active, L are locally free, G are globally free N = A + L + G slack = N - 2L - G = A - L

SVR4 Lazy Buddy System (cont) Lazy state (slack = 0) buffer consumption is in a steady state and coalescing is not necessary Reclaiming state (slack = 1) consumption is borderline, coalescing is needed Accelerated state (slack = 2 or more) consumption is not in a steady state, and the allocator must coalesce faster

Mach-OSF/1 Zone Allocator active zones free objects zone of zones free_elements struct zone struct zone struct zone next_zone first_zone zone of zones struct obj1 struct obj1 struct obj1 last_zone ... zone of zones struct objn struct objn struct objn

Mach-OSF/1 Zone Allocator (cont) Basic idea Each class of dynamically allocated objects is assigned to its own size, which is simply a pool of free objects of that class Any single page is only used for one zone Free objects of each zone are maintained on a linked list, headed by a struct zone Allocation and release involve nothing more than removing objects from and returning objects to the free list If an allocation request finds the free list empty, it asks the page-level allocator for alloc( ) more bytes

Mach-OSF/1 Zone Allocator (cont) Garbage collection Free pages can be returned to the paging system and later recovered for other zones Analysis Zone allocator is fast and efficient No provision for releasing only part of the allocated object Zone objects are exactly the required size Garbage collector provides a mechanism for memory reuse

Hierarchical Allocator for Multiprocessors per-pages freelists Coalesce-to-Page layer Global layer global freelist bucket list target = 3 Per-CPU cache main freelist aux freelist target = 3

Solaris 2.4 Slab Allocator Better performance and memory utilization than other implementation Main issues Object reuse advantage of caching and reusing the same object, rather than allocating and initializing arbitrary chunks of memory Hardware cache utilization Most kernel objects have their important, frequently accessed fields at the beginning of the object

Solaris 2.4 Slab Allocator Allocator footprint Footprint of a allocator is the portion of the hardware cache and the translation lookaside buffer (TLB) that is overwritten by the allocator itself Large footprint causes many cache and TLB misses, reducing the performance of the allocator Large footprint: resource maps, buddy systems Smaller footprint: Mckusick-Karels, zone Design slab allocator is a variant of the zone method and is organized as a collection of object caches

Solaris 2.4 Slab Allocator (cont) page-level allocator back end vnode cache proc cache mbuf cache msgb cache ... front end active vnodes active procs active mbufs active msgbs

Solaris 2.4 Slab Allocator (cont) Implementation slab data coloring area (unused) unused space linked list of slabs in same cache free active free active active free active freelist NULL pointers extra space for linkage

Solaris 2.4 Slab Allocator (cont) Analysis Space efficient Coalescing scheme results in better hardware cache and memory bus utilization Small footprint (only one slab for most requests)