Kernel Memory Allocator

Slides:



Advertisements
Similar presentations
Memory Management in Linux Anand Sivasubramaniam.
Advertisements

Linux device-driver issues
More on File Management
Part IV: Memory Management
Chapter 6: Memory Management
Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.
The Linux Kernel: Memory Management
Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel)
Liu Meihua Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory.
Kernel memory allocation
Allocating Memory Ted Baker  Andy Wang CIS 4930 / COP 5641.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Management.
Chapter 12. Kernel Memory Allocation
Memory management.
Memory Management All data in memory before and after processing
File Systems.
Memory Management Chapter 7.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Chapter 7 Memory Management
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 Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Operating Systems File Systems (in a Day) Ch
Understanding Operating Systems1 Operating Systems Virtual Memory Thrashing Single-User Contiguous Scheme Fixed Partitions Dynamic Partitions.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Memory Management Chapter 5.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Memory Management Chapter 7.
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.
Subject: Operating System.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
CS333 Intro to Operating Systems Jonathan Walpole.
File Systems cs550 Operating Systems David Monismith.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Virtual Memory – Managing Physical Memory
Linux Kernel Development Memory Management Pavel Sorokin Gyeongsang National University
Memory Management Chapter 5 Advanced Operating System.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
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.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Linux 2.6 Memory Management Joseph Garvin. Why do we care? Without keeping multiple process in memory at once, we loose all the hard work we just did.
Day 28 File System.
Memory Management Chapter 7.
Memory Management Chapter 7.
Chapter 2: The Linux System Part 4
Jonathan Walpole Computer Science Portland State University
Day 19 Memory Management.
Linux device driver development
10CS53 Operating Systems Unit VIII Engineered for Tomorrow
10CS53 Operating Systems Unit VIII Engineered for Tomorrow
Memory Management Overview
Operating System Chapter 7. Memory Management
Semester Review Brian Kocoloski
CSE 451 Autumn 2003 November 13 Section.
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
Dynamic Memory Allocation
Buddy Allocation CS 161: Lecture 5 2/11/19.
Components of a Linux System
Presentation transcript:

Kernel Memory Allocator Exploring memory allocation in Linux kernel 2.4.20

KMA Subsystem Goals Must be fast (this is crucial) Should minimize memory waste Try to avoid memory fragmentation Cooperate with other kernel subsystems

‘Layered’ software structure At the lowest level, the kernel allocates and frees ‘blocks’ of contiguous pages of phyical memory: struct page * __alloc_pages( zonelist_t *zonelist, unsigned long order ); (The number of pages in a ‘block’ is a power of 2.)

The zoned buddy allocator 128 KB 64 KB 32 KB ‘splitting’ a free memory region 32 KB

block allocation sizes Smallest block is 4 KB (i.e., one page) order = 0 Largest block is 128 KB (i.e., 32 pages) order = 5

Inefficiency of small requests Many requests are for less than a full page Wasteful to allocate an entire page! So Linux uses a ‘slab allocator’ subsystem

Idea of a ‘slab cache’ kmem_cache_create() manager The memory block contains several equal-sized ‘slabs’ (together with a data-structure used to ‘manage’ them)

Allocation Flags GFP_KERNEL (might sleep) GFP_ATOMIC (will not sleep) __get_free_pages( flags, order ); GFP_KERNEL (might sleep) GFP_ATOMIC (will not sleep) GFP_USER (low priority) __GFP_DMA (below 16MB) __GFP_HIGHMEM (from high_memory)

Virtual memory allocations Want to allocate a larger-sized block? Don’t need physically contiguous pages? You can use the ‘vmalloc()’ function

The VMALLOC address-region gap gap VMALLOC_END VMALLOC_START vmlist Linked list of ‘struct vm_struct’ objects

‘struct vm_struct’ struct vm_struct { unsigned long flags; void *addr; unsigned long size; struct vm_struct *next; }; Defined in <include/linux/vmalloc.h>

The ‘vmlist’ variable Not a public kernel symbol: $ grep vmlist /proc/ksyms So our modules cannot link to ‘vmlist’  Yet maybe we can find its address anyway

The ‘System.map’ file When the kernel is compiled, a textfile gets created in the ‘source’ directory: /usr/src/linux/System.map Each line shows the name and address for a kernel symbol (function-name or data-object)

Sometimes file gets moved Some Linux distributions copy (or move) the ‘System.map’ file to ‘/boot’ directory Some Linux distributions rename the file (e.g., ‘/boot/System.map-2.4.20’) This file will show where ‘vmlist’ is located (Can we find our ‘System.map’ file?)

Another ‘solution’ We can ‘decompile’ our Linux kernel!  The compiled kernel is written to the file: ‘vmlinux’ gcc puts file in the ‘/usr/src/linux’ directory Some distributions may move (or delete) it It is NOT the same as the file ‘vmlinuz’ ! Can use ‘objdump’ to get a list of symbols

‘objdump’ Here’s how to find the ‘vmlist’ address: $ objdump –t vmlinux > vmlinux.sym $ grep vmlist vmlinux.sym You can also get a code-disassembly: $ objdump –d vmlinux > vmlinux.asm

Looking at ‘vm_struct’ list Let’s write a module (named ‘vmlist.c’) It will create a pseudo-file: ‘/proc/vmlist’ We can look at the current ‘vmlist’ objects: $ cat /proc/vmlist Similar to seeing list of process descriptors

‘my_proc_read()’ struct vm_struct **vmlistp, *vm; vmlistp = (struct vm_struct **)0xD64A5124; vm = *vmlistp; while ( vm ) { /* Display information in this vm_struct; */ vm = vm->next; // point to next vm_struct }