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 – ZONE_NORMAL – ZONE_HIGHMEM
0 – 16 MB 16-896 MB 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 );