KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.

Slides:



Advertisements
Similar presentations
Dynamic Memory Management
Advertisements

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
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Memory Management Today Basic memory management Swapping Kernel memory allocation Next Time Virtual memory.
File Systems.
Memory Management Chapter 7.
1 Optimizing Malloc and Free Professor Jennifer Rexford COS 217 Reading: Section 8.7 in K&R book
Fixed/Variable Partitioning
OS Fall’02 Memory Management Operating Systems Fall 2002.
Dynamic memory allocation and fragmentation Seminar on Network and Operating Systems Group II.
Memory Management Memory Areas and their use Memory Manager Tasks:
File System Implementation: beyond the user’s view A possible file system layout on a disk.
1 Optimizing Malloc and Free Professor Jennifer Rexford
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.
Memory Management Chapter 5.
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.
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.
Memory Management Chapter 7.
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Memory Management Chapter 7.
Subject: Operating System.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
Chapter 4 Memory Management Virtual Memory.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Memory Management Problem: Records (of various lengths) need to be stored. Model: A big array of space to store them, managed by a memory manager. Like.
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management -Memory allocation -Garbage collection.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Dynamic Memory Allocation II
Virtual Memory – Managing Physical Memory
Memory management Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
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.
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
Chapter 5 Record Storage and Primary File Organizations
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory Management I: Dynamic Storage Allocation Oct 8, 1998 Topics User-level view Policies Mechanisms class14.ppt Introduction to Computer Systems.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Chapter 17 Free-Space Management
Memory Management Memory Areas and their use Memory Manager Tasks:
Memory Management Fred Kuhns.
Requirements, Partitioning, paging, and segmentation
Memory Management Memory Areas and their use Memory Manager Tasks:
Optimizing Malloc and Free
CS Introduction to Operating Systems
Lecture 3: Main Memory.
Optimizing Dynamic Memory Management
Operating System Chapter 7. Memory Management
Dynamic Memory Allocation
Memory Management Memory Areas and their use Memory Manager Tasks:
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
Presentation transcript:

KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X

BACKGROUND the kernel reserves part of physical memory for its own text and static data structures Page-level Allocator: This does the job of allocating memory The page-level allocator has two principal clients, paging system and kernel memory allocator. Paging system: is a part of virtual memory system. It allocates pages to user processes to hold portions of their address space. Kernel memory allocator: provides buffers of memory to various kernel subsytems.

efficient use of memory pool return a failure status instead of just blocking monitor which parts of its pool are allocated and which are free an efficient KMA must avoid fragmentation Functional Requirements -- KMA

Evaluation Criteria -- KMA must be space-efficient i.e. minimize wastage. Can be measured by utilization factor must be fast must have a simple programming interface should not force to free the entire allocated area all at once must guard against the wastage of memory must be able to interact with the paging system

Different Allocation Methods: Resource Map Allocator set of pairs that monitor areas of free memory the pool becomes fragmented by the allocation and release of chunks of memory creates one map entry for each contiguous free region. the kernel can satisfy new allocation requests using one of three policies: First Fit, Best Fit, Worst Fit Unix chooses the first-fit method.

Analysis -- Advantages easy to implement not restricted to memory allocation no wastage of space can release any part of the region allows reuse of memory by coalescing

Disadvantages Fragmentation--creation of small free regions results in low utilization Fragmentation--If the map has fixed number of entries, it might overflow needs an allocator for its own entries if the map grows dynamically Needs sorting which is expensive Must perform a linear search which is time consuming

Simple Power-of-Two Free Lists uses a set of free lists each buffer has a one-word header malloc() allocates memory. It returns to the caller a pointer to the byte immediately following the header in the buffer. free() releases the buffer no provision to free only part of the allocated buffer

Analysis Advantages: avoids the lengthy linear searches and eliminates the fragmentation problem. worst-case performance is well bounded when a buffer is available presents a familiar programming interface Disadvantages: poor memory utilization no provision for coalescing adjacent free buffers

The McKusick-Karels Allocator eliminates space wastage memory comprises of a set of contiguous pages uses an additional page usage array (kmemsizes[ ]) to manage its pages. Each page may be in one of three states: Free Divided into buffers of a particular size Part of a buffer that spanned multiple pages do not need a header to store a free list pointer

The McKusick-Karels Allocator (Cont..) locates the page by using free() replaces malloc() by a macro Analysis: saves the memory by eliminating the header is faster, wastes less memory, and can handle large and small requests efficiently The drawbacks are: There is no provision for moving memory from one list to another and there is no way to return memory to the paging system

The Buddy System combines free buffer coalescing with a power-of- two allocator. When a buffer is split, each half is called the buddy of the other uses a bitmap to monitor each chunk of the block BC D D’ A’ Bitmap Free list headers

Analysis -- Advantage: allows memory to be reused allows exchange of memory between the allocator and the paging system Disadvantage: When allocate and release requests alternate, the overhead is more Another drawback is the programming interface

The SVR4 Lazy Buddy Algorithm defers coalescing depending on the state of the buffer class any time, a class has N buffers, of which A buffers are active, L are locally free, and G are globally free. Depending on these parameters, a buffer class is in one of the following states: Lazy, Reclaiming, Accelerated Slack = N – 2L- G system is in the lazy state when slack is 2 or more, in the reclaiming state when the slack is 1, and in the accelerated state when slack is zero

The SVR4 Lazy Buddy Algorithm (Cont..) If the list is in lazy state nothing is done and this buffer is called delayed buffer If the list is in reclaiming state, the allocator marks it as free in the bit map and coalesces it if possible If the list is in accelerated state, the allocator coalesces two buffers– the one just released and an additional delayed buffer, if there is one substantial improvement over the basic buddy system

The Mach-OSF/1 Zone Allocator provides fast memory allocation and performs garbage collection each class of objects is assigned its own zone any single page is only used for one zone initializes the zones it will need using the function zinit (size, max, alloc, name) zinit() allocates a zone structure from the zone of zones all active zone structures are maintained on a linked list