Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel)

Slides:



Advertisements
Similar presentations
The Linux Kernel: Memory Management
Advertisements

Kernel memory allocation
Kernel Memory Allocator
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.
File Systems.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Memory Management (II)
Linux Vs. Windows NT Memory Management Hitesh Kumar
Lecture 11: Memory Management
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management 2010.
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.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
1 Memory Management in Representative Operating Systems.
Memory Management Joe O’Pecko CS-520-A. What is Memory Management? The art and the process of coordinating and controlling the use of memory in a computer.
Virtual Memory By: Dinouje Fahih. Definition of Virtual Memory Virtual memory is a concept that, allows a computer and its operating system, to use a.
Memory Allocation CS Introduction to Operating Systems.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Memory Management Ch.8.
Presentation of Chapter 4, LINUX Kernel Internals Zhihua (Scott) Jiang Computer Science Department University of Maryland, Baltimore County Baltimore,
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
Operating Systems Chapter 8
CS333 Intro to Operating Systems Jonathan Walpole.
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 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
Lecture 2: CS623 2/3/2004 © Joel Wein 2003, modified by T. Suel.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory.
Linux File system Implementations
Memory Management CS Spring Overview Partitioning, Segmentation, and Paging External versus Internal Fragmentation Logical to Physical Address.
Virtual Memory – Managing Physical Memory
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Linux Kernel Development Memory Management Pavel Sorokin Gyeongsang National University
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.
Memory Management.
Last lecture: VM Implementation
Virtual memory.
Chapter 2: The Linux System Part 4
Memory Management.
Chapter 9: Virtual Memory – Part II
CS703 - Advanced Operating Systems
26 - File Systems.
Database Management Systems (CS 564)
CS Introduction to Operating Systems
Computer Architecture
So far… Text RO …. printf() RW link printf Linking, loading
Lecture 32 Syed Mansoor Sarwar
CS399 New Beginnings Jonathan Walpole.
CSC 660: Advanced Operating Systems
Memory management, part 3: outline
Operating System Chapter 7. Memory Management
Virtual Memory Overcoming main memory size limitation
CSE 451 Autumn 2003 November 13 Section.
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
CS703 - Advanced Operating Systems
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel) J. H. Wang Nov. 6, 2009

Outline Page Frame Management Memory Area Management Noncontiguous Memory Area Management

Page Frame Management Two different page frame sizes Page Descriptors 4KB: standard memory allocation unit 4MB Page Descriptors Of type page Stored in the mem_map array

The Fields of the Page Descriptor Type Name Description unsigned long flags Array of flags atomic_t _count Page frame's reference counter _mapcount Number of Page Table entries that refer to the page frame private Available to the kernel component that is using the page struct address_space * mapping Used when the page is inserted into the page cache index Used by several kernel components with different meanings struct list_head lru Contains pointers to the least recently used doubly linked list of pages.

Flags Describing the Status of a Page Frame PG_locked, PG_error, PG_referenced, PG_uptodate, PG_dirty, PG_lru, PG_active, PG_slab, PG_skip, PG_highmem, PG_checked, PG_arch_1, PG_reserved, PG_private, PG_writeback, PG_nosave, PG_compound, PG_swapcache, PG_mappedtodisk, PG_reclaim, PG_nosave_free

NUMA (Non-Uniform Memory Access) The physical memory of the system is partitioned in several nodes Each node has a descriptor (Table 8-3) The physical memory inside each node can be split into several zones ZONE_DMA: < 16MB ZONE_NORMAL: 16MB-896MB ZONE_HIGHMEM: > 896MB Each zone has its descriptor (Table 8-4)

The Pool of Reserved Page Frames The amount of the reserved memory (in kilobytes) is stored in the min_free_kbytes variable

Zoned Page Frame Allocator

Requesting and Releasing Page Frames alloc_pages(), alloc_page(), __get_free_pages(), __get_free_page(), get_zoned_page(), __get_dma_pages() Release: __free_pages(), free_pages(), __free_page(), free_page(),

Buddy System Algorithm To avoid external fragmentation without paging Contiguous page frames are sometimes necessary Advantage of leaving kernel page tables unchanged Large chunks of contiguous physical memory can be accessed by the kernel through 4MB pages

The Buddy System 11 lists of blocks: groups of 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 contiguous page frames 3 buddy systems in Linux 2.6 For DMA, normal page frames, and high-memory page frames Allocating a block: __rmqueue() Freeing a block: __free_pages_bulk()

Per-CPU Page Frame Cache Each per-CPU cache includes some pre-allocated page frames Hot cache Cold cache The fields of per_cpu_pages descriptor (Table 8-7) Allocating page frames: buffered_rmqueue() Releasing page frames: free_hot_page(), free_cold_page()

Memory Area Management To avoid internal fragmentation Early Linux version adopt buddy system Not efficient A better algorithm is derived from slab allocator Adopted in Solaris 2.4

The Slab Allocator

The Slab Allocator The slab allocator groups objects into caches Each cache is a store of objects of the same type A cache is divided into slabs Each slab consists of one or more contiguous page frames that contain both allocated and free objects Cache descriptor of type kmem_cache_t (Table 8-8) Slab descriptor of type slab (Table 8-10) Object descriptor of type kmem_bufctl_t

Relationship between Cache and Slab Descriptors

General vs. Specific Caches General cache: kmem_cache_init() kmem_cache 26 caches: two caches for each of the 13 sizes Specific cache: kmem_cache_create()

Allocating a slab to a cache Releasing a slab from a cache cache_grow() Releasing a slab from a cache slab_destroy()

Relationships between Slab and Object Descriptors

Allocating a slab object Freeing a slab object General purpose objects kmem_cache_alloc() Freeing a slab object kmem_cache_free() General purpose objects kmalloc() kfree()

Memory Pools New in Linux 2.6 Type mempool_t mempool_alloc() mempool_free()

Noncontiguous Memory Area Management To avoid external fragmentation Descriptor of type vm_struct (Table 8-13) get_vm_area(): look for a free range of linear address Allocating a noncontiguous memory area vmalloc() Releasing a noncontiguousa memory area vfree()

Linear Address Interval Starting from PAGE_OFFSET

Thanks for Your Attention!