Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
slab.c File Reference
#include <linux/slab.h>
#include "slab.h"
#include <linux/mm.h>
#include <linux/poison.h>
#include <linux/swap.h>
#include <linux/cache.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/compiler.h>
#include <linux/cpuset.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/notifier.h>
#include <linux/kallsyms.h>
#include <linux/cpu.h>
#include <linux/sysctl.h>
#include <linux/module.h>
#include <linux/rcupdate.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/nodemask.h>
#include <linux/kmemleak.h>
#include <linux/mempolicy.h>
#include <linux/mutex.h>
#include <linux/fault-inject.h>
#include <linux/rtmutex.h>
#include <linux/reciprocal_div.h>
#include <linux/debugobjects.h>
#include <linux/kmemcheck.h>
#include <linux/memory.h>
#include <linux/prefetch.h>
#include <net/sock.h>
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
#include <asm/page.h>
#include <trace/events/kmem.h>
#include "internal.h"
#include <linux/kmalloc_sizes.h>

Go to the source code of this file.

Data Structures

struct  slab_rcu
 
struct  slab
 
struct  array_cache
 
struct  arraycache_init
 
struct  kmem_list3
 
struct  cache_names
 
struct  ccupdate_struct
 

Macros

#define DEBUG   0
 
#define STATS   0
 
#define FORCED_DEBUG   0
 
#define BYTES_PER_WORD   sizeof(void *)
 
#define REDZONE_ALIGN   max(BYTES_PER_WORD, __alignof__(unsigned long long))
 
#define ARCH_KMALLOC_FLAGS   SLAB_HWCACHE_ALIGN
 
#define CREATE_MASK
 
#define BUFCTL_END   (((kmem_bufctl_t)(~0U))-0)
 
#define BUFCTL_FREE   (((kmem_bufctl_t)(~0U))-1)
 
#define BUFCTL_ACTIVE   (((kmem_bufctl_t)(~0U))-2)
 
#define SLAB_LIMIT   (((kmem_bufctl_t)(~0U))-3)
 
#define SLAB_OBJ_PFMEMALLOC   1
 
#define BOOT_CPUCACHE_ENTRIES   1
 
#define NUM_INIT_LISTS   (3 * MAX_NUMNODES)
 
#define CACHE_CACHE   0
 
#define SIZE_AC   MAX_NUMNODES
 
#define SIZE_L3   (2 * MAX_NUMNODES)
 
#define CACHE(x)
 
#define INDEX_AC   index_of(sizeof(struct arraycache_init))
 
#define INDEX_L3   index_of(sizeof(struct kmem_list3))
 
#define MAKE_LIST(cachep, listp, slab, nodeid)
 
#define MAKE_ALL_LISTS(cachep, ptr, nodeid)
 
#define CFLGS_OFF_SLAB   (0x80000000UL)
 
#define OFF_SLAB(x)   ((x)->flags & CFLGS_OFF_SLAB)
 
#define BATCHREFILL_LIMIT   16
 
#define REAPTIMEOUT_CPUC   (2*HZ)
 
#define REAPTIMEOUT_LIST3   (4*HZ)
 
#define STATS_INC_ACTIVE(x)   do { } while (0)
 
#define STATS_DEC_ACTIVE(x)   do { } while (0)
 
#define STATS_INC_ALLOCED(x)   do { } while (0)
 
#define STATS_INC_GROWN(x)   do { } while (0)
 
#define STATS_ADD_REAPED(x, y)   do { (void)(y); } while (0)
 
#define STATS_SET_HIGH(x)   do { } while (0)
 
#define STATS_INC_ERR(x)   do { } while (0)
 
#define STATS_INC_NODEALLOCS(x)   do { } while (0)
 
#define STATS_INC_NODEFREES(x)   do { } while (0)
 
#define STATS_INC_ACOVERFLOW(x)   do { } while (0)
 
#define STATS_SET_FREEABLE(x, i)   do { } while (0)
 
#define STATS_INC_ALLOCHIT(x)   do { } while (0)
 
#define STATS_INC_ALLOCMISS(x)   do { } while (0)
 
#define STATS_INC_FREEHIT(x)   do { } while (0)
 
#define STATS_INC_FREEMISS(x)   do { } while (0)
 
#define obj_offset(x)   0
 
#define dbg_redzone1(cachep, objp)   ({BUG(); (unsigned long long *)NULL;})
 
#define dbg_redzone2(cachep, objp)   ({BUG(); (unsigned long long *)NULL;})
 
#define dbg_userword(cachep, objp)   ({BUG(); (void **)NULL;})
 
#define SLAB_MAX_ORDER_HI   1
 
#define SLAB_MAX_ORDER_LO   0
 
#define CACHE(x)   { .cs_size = (x) },
 
#define CACHE(x)   { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
 
#define BAD_ALIEN_MAGIC   0x01020304ul
 
#define init_reap_node(cpu)   do { } while (0)
 
#define next_reap_node(void)   do { } while (0)
 
#define drain_alien_cache(cachep, alien)   do { } while (0)
 
#define reap_alien(cachep, l3)   do { } while (0)
 

Typedefs

typedef unsigned int kmem_bufctl_t
 

Functions

 EXPORT_SYMBOL (malloc_sizes)
 
 __setup ("noaliencache", noaliencache_setup)
 
 __setup ("slab_max_order=", slab_max_order_setup)
 
void __init kmem_cache_init (void)
 
void __init kmem_cache_init_late (void)
 
 __initcall (cpucache_init)
 

Variables

struct cache_sizes malloc_sizes []
 

: A string which is used in /proc/slabinfo to identify this cache.

__kmem_cache_create - Create a cache.

: The size of objects to be created in this cache. : The required alignment for the objects. : SLAB flags : A constructor for the objects.

Returns a ptr to the cache on success, NULL on failure. Cannot be called within a int, but can be interrupted. The is run when new pages are allocated by the cache.

The flags are

SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) to catch references to uninitialised memory.

SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check for buffer overruns.

SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware cacheline. This can be beneficial if you're counting cycles as closely as davem.

#define check_irq_off()   do { } while(0)
 
#define check_irq_on()   do { } while(0)
 
#define check_spinlock_acquired(x)   do { } while(0)
 
#define check_spinlock_acquired_node(x, y)   do { } while(0)
 
#define kfree_debugcheck(x)   do { } while(0)
 
#define cache_free_debugcheck(x, objp, z)   (objp)
 
#define check_slabp(x, y)   do { } while(0)
 
#define cache_alloc_debugcheck_after(a, b, objp, d)   (objp)
 
int __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
 
int kmem_cache_shrink (struct kmem_cache *cachep)
 
 EXPORT_SYMBOL (kmem_cache_shrink)
 
int __kmem_cache_shutdown (struct kmem_cache *cachep)
 
voidkmem_cache_alloc (struct kmem_cache *cachep, gfp_t flags)
 
 EXPORT_SYMBOL (kmem_cache_alloc)
 
void__kmalloc (size_t size, gfp_t flags)
 
 EXPORT_SYMBOL (__kmalloc)
 
void kmem_cache_free (struct kmem_cache *cachep, void *objp)
 
 EXPORT_SYMBOL (kmem_cache_free)
 
void kfree (const void *objp)
 
 EXPORT_SYMBOL (kfree)
 
unsigned int kmem_cache_size (struct kmem_cache *cachep)
 
 EXPORT_SYMBOL (kmem_cache_size)
 
size_t ksize (const void *objp)
 
 EXPORT_SYMBOL (ksize)
 

Macro Definition Documentation

#define ARCH_KMALLOC_FLAGS   SLAB_HWCACHE_ALIGN

Definition at line 156 of file slab.c.

#define BAD_ALIEN_MAGIC   0x01020304ul

Definition at line 583 of file slab.c.

#define BATCHREFILL_LIMIT   16

Definition at line 395 of file slab.c.

#define BOOT_CPUCACHE_ENTRIES   1

Definition at line 298 of file slab.c.

#define BUFCTL_ACTIVE   (((kmem_bufctl_t)(~0U))-2)

Definition at line 204 of file slab.c.

#define BUFCTL_END   (((kmem_bufctl_t)(~0U))-0)

Definition at line 202 of file slab.c.

#define BUFCTL_FREE   (((kmem_bufctl_t)(~0U))-1)

Definition at line 203 of file slab.c.

#define BYTES_PER_WORD   sizeof(void *)

Definition at line 152 of file slab.c.

#define CACHE (   x)
Value:
if (size <=x) \
return i; \
else \
i++;
#define CACHE (   x)    { .cs_size = (x) },
#define CACHE (   x)    { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
#define cache_alloc_debugcheck_after (   a,
  b,
  objp,
  d 
)    (objp)

Definition at line 3281 of file slab.c.

#define CACHE_CACHE   0

Definition at line 326 of file slab.c.

#define cache_free_debugcheck (   x,
  objp,
 
)    (objp)

Definition at line 3112 of file slab.c.

#define CFLGS_OFF_SLAB   (0x80000000UL)

Definition at line 392 of file slab.c.

#define check_irq_off ( )    do { } while(0)

Definition at line 2602 of file slab.c.

#define check_irq_on ( )    do { } while(0)

Definition at line 2603 of file slab.c.

#define check_slabp (   x,
  y 
)    do { } while(0)

Definition at line 3113 of file slab.c.

#define check_spinlock_acquired (   x)    do { } while(0)

Definition at line 2604 of file slab.c.

#define check_spinlock_acquired_node (   x,
  y 
)    do { } while(0)

Definition at line 2605 of file slab.c.

#define CREATE_MASK
Value:
SLAB_CACHE_DMA | \
SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)

Definition at line 175 of file slab.c.

#define dbg_redzone1 (   cachep,
  objp 
)    ({BUG(); (unsigned long long *)NULL;})

Definition at line 495 of file slab.c.

#define dbg_redzone2 (   cachep,
  objp 
)    ({BUG(); (unsigned long long *)NULL;})

Definition at line 496 of file slab.c.

#define dbg_userword (   cachep,
  objp 
)    ({BUG(); (void **)NULL;})

Definition at line 497 of file slab.c.

#define DEBUG   0

Definition at line 146 of file slab.c.

#define drain_alien_cache (   cachep,
  alien 
)    do { } while (0)

Definition at line 1065 of file slab.c.

#define FORCED_DEBUG   0

Definition at line 148 of file slab.c.

#define INDEX_AC   index_of(sizeof(struct arraycache_init))

Definition at line 363 of file slab.c.

#define INDEX_L3   index_of(sizeof(struct kmem_list3))

Definition at line 364 of file slab.c.

#define init_reap_node (   cpu)    do { } while (0)

Definition at line 869 of file slab.c.

#define kfree_debugcheck (   x)    do { } while(0)

Definition at line 3111 of file slab.c.

#define MAKE_ALL_LISTS (   cachep,
  ptr,
  nodeid 
)
Value:
do { \
MAKE_LIST((cachep), (&(ptr)->slabs_full), slabs_full, nodeid); \
MAKE_LIST((cachep), (&(ptr)->slabs_partial), slabs_partial, nodeid); \
MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \
} while (0)

Definition at line 385 of file slab.c.

#define MAKE_LIST (   cachep,
  listp,
  slab,
  nodeid 
)
Value:
do { \
INIT_LIST_HEAD(listp); \
list_splice(&(cachep->nodelists[nodeid]->slab), listp); \
} while (0)

Definition at line 379 of file slab.c.

#define next_reap_node (   void)    do { } while (0)

Definition at line 870 of file slab.c.

#define NUM_INIT_LISTS   (3 * MAX_NUMNODES)

Definition at line 324 of file slab.c.

#define obj_offset (   x)    0

Definition at line 494 of file slab.c.

#define OFF_SLAB (   x)    ((x)->flags & CFLGS_OFF_SLAB)

Definition at line 393 of file slab.c.

#define reap_alien (   cachep,
  l3 
)    do { } while (0)

Definition at line 1066 of file slab.c.

#define REAPTIMEOUT_CPUC   (2*HZ)

Definition at line 403 of file slab.c.

#define REAPTIMEOUT_LIST3   (4*HZ)

Definition at line 404 of file slab.c.

#define REDZONE_ALIGN   max(BYTES_PER_WORD, __alignof__(unsigned long long))

Definition at line 153 of file slab.c.

#define SIZE_AC   MAX_NUMNODES

Definition at line 327 of file slab.c.

#define SIZE_L3   (2 * MAX_NUMNODES)

Definition at line 328 of file slab.c.

#define SLAB_LIMIT   (((kmem_bufctl_t)(~0U))-3)

Definition at line 205 of file slab.c.

#define SLAB_MAX_ORDER_HI   1

Definition at line 505 of file slab.c.

#define SLAB_MAX_ORDER_LO   0

Definition at line 506 of file slab.c.

#define SLAB_OBJ_PFMEMALLOC   1

Definition at line 277 of file slab.c.

#define STATS   0

Definition at line 147 of file slab.c.

#define STATS_ADD_REAPED (   x,
  y 
)    do { (void)(y); } while (0)

Definition at line 435 of file slab.c.

#define STATS_DEC_ACTIVE (   x)    do { } while (0)

Definition at line 432 of file slab.c.

#define STATS_INC_ACOVERFLOW (   x)    do { } while (0)

Definition at line 440 of file slab.c.

#define STATS_INC_ACTIVE (   x)    do { } while (0)

Definition at line 431 of file slab.c.

#define STATS_INC_ALLOCED (   x)    do { } while (0)

Definition at line 433 of file slab.c.

#define STATS_INC_ALLOCHIT (   x)    do { } while (0)

Definition at line 442 of file slab.c.

#define STATS_INC_ALLOCMISS (   x)    do { } while (0)

Definition at line 443 of file slab.c.

#define STATS_INC_ERR (   x)    do { } while (0)

Definition at line 437 of file slab.c.

#define STATS_INC_FREEHIT (   x)    do { } while (0)

Definition at line 444 of file slab.c.

#define STATS_INC_FREEMISS (   x)    do { } while (0)

Definition at line 445 of file slab.c.

#define STATS_INC_GROWN (   x)    do { } while (0)

Definition at line 434 of file slab.c.

#define STATS_INC_NODEALLOCS (   x)    do { } while (0)

Definition at line 438 of file slab.c.

#define STATS_INC_NODEFREES (   x)    do { } while (0)

Definition at line 439 of file slab.c.

#define STATS_SET_FREEABLE (   x,
  i 
)    do { } while (0)

Definition at line 441 of file slab.c.

#define STATS_SET_HIGH (   x)    do { } while (0)

Definition at line 436 of file slab.c.

Typedef Documentation

typedef unsigned int kmem_bufctl_t

Definition at line 201 of file slab.c.

Function Documentation

__initcall ( cpucache_init  )
void* __kmalloc ( size_t  size,
gfp_t  flags 
)

Definition at line 3913 of file slab.c.

int __kmem_cache_create ( struct kmem_cache cachep,
unsigned long  flags 
)

Definition at line 2357 of file slab.c.

int __kmem_cache_shutdown ( struct kmem_cache cachep)

Definition at line 2730 of file slab.c.

__setup ( "noaliencache"  ,
noaliencache_setup   
)
__setup ( )
EXPORT_SYMBOL ( malloc_sizes  )
EXPORT_SYMBOL ( kmem_cache_shrink  )
EXPORT_SYMBOL ( kmem_cache_alloc  )
EXPORT_SYMBOL ( __kmalloc  )
EXPORT_SYMBOL ( kmem_cache_free  )
EXPORT_SYMBOL ( kfree  )
EXPORT_SYMBOL ( kmem_cache_size  )
EXPORT_SYMBOL ( ksize  )
void kfree ( const void objp)

kfree - free previously allocated memory : pointer returned by kmalloc.

If is NULL, no operation is performed.

Don't free memory not originally allocated by kmalloc() or you will run into trouble.

Definition at line 3952 of file slab.c.

void* kmem_cache_alloc ( struct kmem_cache cachep,
gfp_t  flags 
)

kmem_cache_alloc - Allocate an object : The cache to allocate from. : See kmalloc().

Allocate an object from this cache. The flags are only relevant if the cache has no available objects.

Definition at line 3780 of file slab.c.

void kmem_cache_free ( struct kmem_cache cachep,
void objp 
)

kmem_cache_free - Deallocate an object : The cache the allocation was from. : The previously allocated object.

Free an object which was previously allocated from this cache.

Definition at line 3928 of file slab.c.

void __init kmem_cache_init ( void  )

Definition at line 1583 of file slab.c.

void __init kmem_cache_init_late ( void  )

Definition at line 1774 of file slab.c.

int kmem_cache_shrink ( struct kmem_cache cachep)

kmem_cache_shrink - Shrink a cache. : The cache to shrink.

Releases as many slabs as possible for a cache. To help debugging, a zero exit status indicates all slabs were released.

Definition at line 2716 of file slab.c.

unsigned int kmem_cache_size ( struct kmem_cache cachep)

Definition at line 3972 of file slab.c.

size_t ksize ( const void objp)

ksize - get the actual amount of memory allocated for a given object : Pointer to the object

kmalloc may internally round up allocations and return more memory than requested. ksize() can be used to determine the actual amount of memory allocated. The caller may use this additional memory, even though a smaller amount of memory was initially specified with the kmalloc call. The caller must guarantee that objp points to a valid object previously allocated with either kmalloc() or kmem_cache_alloc(). The object must not be freed during the duration of the call.

Definition at line 4689 of file slab.c.

Variable Documentation

struct cache_sizes malloc_sizes[]
Initial value:
= {
#define CACHE(x)
}

Definition at line 546 of file slab.c.