0% found this document useful (0 votes)
106 views

Linux-Mm Apis: A Brief Tutorial: Geep Organized Tutorial On

The document provides an overview of Linux memory management APIs, including: - Virtual memory layout and the buddy/zone allocator for managing physical memory - The vmalloc function for mapping virtual memory and kmap for accessing kernel memory - The slab allocator, which handles small allocations on top of the zone allocator It describes the working of these allocators and lists some key functions for allocating, freeing, and managing memory like alloc_pages, kmem_cache_create, and kmalloc.

Uploaded by

Neependra Khare
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Linux-Mm Apis: A Brief Tutorial: Geep Organized Tutorial On

The document provides an overview of Linux memory management APIs, including: - Virtual memory layout and the buddy/zone allocator for managing physical memory - The vmalloc function for mapping virtual memory and kmap for accessing kernel memory - The slab allocator, which handles small allocations on top of the zone allocator It describes the working of these allocators and lists some key functions for allocating, freeing, and managing memory like alloc_pages, kmem_cache_create, and kmalloc.

Uploaded by

Neependra Khare
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

GeeP organized tutorial

on

Linux-mm APIs : A brief


tutorial

Amey Inamdar

Infrastructure sponsors:
Oasis Technologies
A quick brushup
• Virtual Memory
• Paging
Virtual Memory Layout
Buddy/Zone allocator
• Zones:
– ZONE_DMA 0 – 16 MB
– ZONE_NORMAL 16-896 MB
– ZONE_HIGHMEM 896 MB onwards

• Buddy allocator
– Working
– APIs
struct page * alloc_pages(gfp_t gfp_mask, unsigned int order);
void free_pages(unsigned long addr, unsigned int order);
Vmalloc & Highmem
• Page aligned virtually contiguous memory
• Pages can be physically non-contiguous
• APIs
– void *vmalloc(unsigned long size);
– void vfree(void *addr);
• Kmap & highmem
– void *kmap(struct page *page);
– void kunmap(struct page *page);
– void *kmap_atomic(struct page *page, enum km_type
type);
Slab allocator
• What about small sized allocations e.g. for
structure instances?
• Layer which gets the pages from
zone/buddy allocator and satisfies small
sized allocations.
• Brief working
Slab allocator (continued)
Slab Allocator - APIs
• struct kmem_cache * kmem_cache_create(
const char *name,
size_t size,
size_t align,
unsigned long flags;
void (*ctor)(void*, struct kmem_cache *, unsigned long),
void (*dtor)(void*, struct kmem_cache *, unsigned long));

• void kmem_cache_destroy( struct kmem_cache *cachep );


• void kmem_cache_alloc( struct kmem_cache *cachep, gfp_t

flags );
• void kmem_cache_free( struct kmem_cache *cachep, void *objp );
Slab allocator - APIs
• General purpose cache
• APIs
– void *kmalloc( size_t size, int flags );
– void kfree( const void *objp );

You might also like