Kernel memory allocation

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

Part IV: Memory Management
The Linux Kernel: Memory Management
Chapter 12. Kernel Memory Allocation
Memory Management Today Basic memory management Swapping Kernel memory allocation Next Time Virtual memory.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Allocating Memory.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Virtual Memory Chapter 8.
Linux Vs. Windows NT Memory Management Hitesh Kumar
Memory Design Example. Selecting Memory Chip Selecting SRAM Memory Chip.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Memory Management 2010.
Chapter 8 Operating System Support (Continued)
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.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 3.2 : Virtual 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.
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
Computer Organization and Architecture
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.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice, FL ©2008,
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Computer Organization and Architecture Operating System Support Chapter 8.
Memory Allocation CS Introduction to Operating Systems.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Operating Systems Chapter 8
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.
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.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Memory Management Chapter 7.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
CS333 Intro to Operating Systems Jonathan Walpole.
Memory Management -Memory allocation -Garbage collection.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
Virtual Memory – Managing Physical Memory
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Jonathan Walpole Computer Science Portland State University
Memory Management Fred Kuhns.
Day 21 Virtual Memory.
Day 22 Virtual Memory.
Virtual Memory Chapter 8.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
CS Introduction to Operating Systems
Page Replacement.
Dynamic Memory Allocation
Virtual Memory: Working Sets
CS703 - Advanced Operating Systems
Lecture 9: Caching and Demand-Paged Virtual Memory
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Kernel memory allocation Unix divides memory into fixed size pages Page size is a power of two – typical size is 4kbytes Because Unix is a VM system, logically contiguous pages need not to be physically adjacent Memory management subsystem maintains mapping between the logical pages and physical frames

Memory allocators in the kernel Page-level allocator – - paging system - - user processes - - block buffer cache, - kernel memory allocator - - network buffers - - proc structures - - inodes, - - file descriptors

Functional requirements Kernel allocator services requests for dynamic memory allocation for its clients not for user processes Must use the allocated space efficiently – allocation may be fixed or not, it may be possible to exchange it with paging system If it runs out of memory it blocks the caller, until more memory is free Must monitor which parts of its pool are allocated and which are free

Evaluation criteria Efficiency - utilization factor - ratio of total memory requested to that required to satisfy the requests Speed – average and worst case latency Simple programming interface suitable for a wide variety of clients Allocated memory should be properly aligned for faster access – minimum allocation size Handle requests of different sizes Interact with the paging system for exchange of memory space

The buddy system Combines free buffer coalescing with a-power-of-two allocator Creates small buffers by repeatedly halving a large buffer and coalescing adjacent free buffer Each half of a split buffer is called a buddy Advantages – flexible – allows to use buffers of different sizes, easy exchange of memory between the allocator and the paging system Disadvantage - poor performance, inconvenient programming interface, impossible to release a part of a buffer

SVR4 lazy buddy algorithm Coalescing delay – time taken to coalesce a single buffer with its buddy. To avoid coalescing delay we can defer coalescing until it becomes necessary, and then coalesces as many buffers as possible. It improves the average time for allocation and release, but results in slow response for requests invoking coalescing routine. SVR4 offers an intermediate solution which is more efficient.

SVR4 lazy buddy algorithm Buffer release involves two steps. First the buffer is put on the free list. Second, the buffer is marked as free in the bitmap and coalesced with adjacent buffers if possible. The lazy buddy system always performs the first step. Whether it performs the second step it depends on the state of the buffer class. A buffer class can be in one of three states : lazy – coalescing is not necessary, reclaiming – coalescing is needed, accelerated – allocator must coalesce faster

SVR4 lazy buddy algorithm State of the buffer is determined by the slack: slack = N – 2L – G where N number of buffers in the class, L – numbers of locally free buffers, G – numbers of globally free buffers, System is in: lazy state when slack >= 2 reclaiming state when slack = 1 accelerated state when slack = 0

SVR4 lazy buddy algorithm

Solaris 2.4 Slab allocator Design issues Object reuse Hardware cash utilization Allocator footprint

Object reuse Allocate memory Construct (initialize object) Use the object Deconstruct it Free the memory

Hardware cash utilization When the hardware references an address, it first checks the cache location to see if the data is in the cache. If it is not, the hardware fetches the data from main memory into the cache, overwriting the previous contents of the cache location.

Allocator footprint It is the portion of the hardware cache and the Translation Lookaside Buffer that is overwritten by the allocation itself. The slab allocator has a small footprint, since it determines the correct pool of buffers by a simple computation and merely removes a buffer from the appropriate free list.

Linux Memory Management Page directory Page middle directory Page table

Page allocation Buddy system is used Kernel maintains a list of contiguous page frame groups of fixed size (e.g. 1, 2, 4, ..32 page frames) As pages are allocated and deallocated in main memory, the available groups are split and merged

Page replacement algorithm Based on the clock algorithm The use bit is replaced with an 8-bit age variable Each time that a page is accessed, the age variable is incremented A page with an ago of 0 is best candidate for replacement The larger the value of age of the page, the least it is eligible for replacement It is a version of least frequently used policy.

Kernel memory allocation Page allocation for kernel uses the same scheme as for user virtual memory management buddy algorithm is used so that kernel can be allocated in units of one or more pages To allocate chunks smaller than a page Linux uses slab allocation The chunks can be 32 to 4080 bytes Chunks are on a linked list, one for each size of a chunk Chunks may be split and aggregated and moved between lists