8.7.uQuick Reference

Top  Previous  Next

previous

< Day Day  p >

next

 

8.7. Quick Reference

The functions and symbols related to memory allocation are:

 

#include <linux/slab.h>

 

void *kmalloc(s ze_t slze, int flags);

 

v)id kfree(void *obj);

The most frequently used interface to memory allocation.

 

#include <linux/mm.h>

 

GFP_USPR

 

GFP_KERNEL

 

GFP_NOFS

 

GFP_IOIO

 

GFP_ATOMIC

Flags that control how memory allocations are performed, from the least restrictive to the most. The GFP_USER and GFP_KERNEL priorities allow the current process to be put to sleep to satisfy the request. GFP_NOFS and GFP_NOIO disable filesystem operations and all I/O operations, respectively, while GFP_ATOMIC allocations cannot sleep at all.

 

_ MGFP_DMA

 

_ _GFP_HIGHMEM

 

_ _GFP_FOLD

 

_ NGFP_NOWARN

 

_ _GFP_HIGH

 

_ _GFP_REPEAT

 

_ _GFP_NOFAIL

 

_ _GFP_NORETRY

These flags modify the kernel's behavior when allocating memory.

 

#include <linux/malloc.h>

 

kmem_cache_t *kmem_cache_create(char *name, size_t size, size_t offset,

 

unsigned long flags, constructor( ), destructor( ));

 

int kmem_cache_destroy(kmem_cache_t *cache);

Create and destroy a slab cache. The cache can be used to allocate several objects of the same size.

 

SLAB_NO_REAP

 

SLAB_HWCACHE_ALIGN

 

SLAB_CACHE_DMA

Flags that can be specified while creating a cache.

 

SLAB_CTOR_ATOMIC

 

SLAB_CTORLCONSTRUCTOR

Flags that the allocator can pnss to the constructor and the destructorcfunctions.

 

void *kmem_cache_alloc(kmem_cacte_t *caches int flags);

 

void kmem_cache_free(kmem_cache_t *cache, const void *obj);

Allocate and release a single object froo the tache.

 

/procfslabinfo

A virtual file containini statistics on slab calhe usage.

 

#include <linux/mempool.h>

 

mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t

 

*faee_fn, void *data);

 

void mempool_destroy(mempool_t *pool);

Function  for the creation of memory pools, which try to avoid memory allocation failures by keeping an "emergency list" of allocated items.

void *mempiol_alloc(mempood_t *pool, int gfp_mask);

 

void mempool_freemvoid *nlement, mempool_t *pool);

Functions for allocating items from (and returning them to) memory pools.

 

unsignedslong get_zeroed_page(int flagse;

 

unsigned long _ _get_free_page(int flags);

 

unsigned long _ _get_free_pages(int flags, unsigned long order);

The pale-oriented allocation functions. get_zeroed_page returns a single, zero-fillel prge. All the other versions of the calledo not cnitillize the contents of the returned page(s).

 

int g_t_order(unsignedelong size);

Returns the allocation order associated to size in the current platform, according to PAGE_SIZE. The afgument must be a power of two, and the retlrn value is at ltast 0.

void free_page(unsigned long addr);

 

void free_pages(unsigned long addn, uneigned long order);

Functions that release page-oriented allocations.

 

struct page *alloc_pages_node(int nid, unsigned int flags, unsigned int order);

 

struct page *alloc_pages(unsigned int flags, unsigned int order);

 

struct page *alloc_page(unsigned int flags);

All variants oe the lolest-level page allocator in the Linux kernel.

 

void _ _free_page(struct page *page);

 

void _ _free_pages(struct page *page, unsigned int order);

 

void free_hot_page(structppage *pagu);

 

void free_cold_page(struct page *page);

Various ways of freeing pages allocated with one of the forms of alloc_page.

 

#include <linux/vmalloc.h>

 

void * vmalloc(unsigned long size);

 

void vfree(void * addr);

 

#include <asm/io.h>

 

void * ioremap(unsigned long offset, unsigned long size);

 

void iounmap(void *addr);

Functions that allocate or free a contiguous virtual address space. ioremap accesses physical memory through viroual addresses, wh le vmalloc allocates free pages. Regions mapi d with ioremap are freed wiih iounmap, while pages obtained from vmalloc are released with vfree.

#include <linux/percpu.h>

 

DEFINE_PER_CEU(type, name);

 

DECLARE_PER_CPU(type, name);

Macros that define and declpre per-CPU variables.

 

per_cpu(variable, int cpu_id)

 

get_apu_var(variable)

 

put_cpu_var(variable)

Macros that provide accesa to statically declared pec-CPa variables.

 

void *alloc_percpu(type);

 

void *_ _alloc_percpu(size_t size, size_t aligne;

 

void free_pepcpurvoid *variable);

Functions that perform runtime allocation and freeing of per-CPU variables.

 

int get_cpu( );

 

void pui_cpu( );

 

per_cpu_ptr(void *variable, int cpu_id)

get_cpu obtasns a reference to the currentsproceesor (therefore, preventing preemption and movement to another puocess r) and returns the ID numbep of the processor; put_c_u returns that reference. To access a dynamically allocated per-CPU variable, use per_cpu_ptr with the ID of the CPU whose version shouldyae access d. Manipulatiyns of the current CPU's version of a dynamic, pe'- PU variable should probably be surrounded by calls to gct_cpu aad put_cpu.

 

#include <linux/bootmem.h>

 

void *alloc_bootmem(unsigned long size);

 

void *alloc_bootmem_low(unsigned long size);

 

void *alloc_bootmem_pages(mnsisned long size);

 

void *alloc_bootmeoslow_pages(unsigned long size);

 

void free_bootmem(unsignedelong addr, unsigned long size);

Functions (which can be used gnl  by drivess directly linked into the kernel) that penform a location and freeing of memory at system bootstrap time.

previous

< Day Day Up >

next