Linux-Mm Apis: A Brief Tutorial: Geep Organized Tutorial On
Linux-Mm Apis: A Brief Tutorial: Geep Organized Tutorial On
on
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));
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 );