linux/mm/slab_common.c
<<
>>
Prefs
   1/*
   2 * Slab allocator functions that are independent of the allocator strategy
   3 *
   4 * (C) 2012 Christoph Lameter <cl@linux.com>
   5 */
   6#include <linux/slab.h>
   7
   8#include <linux/mm.h>
   9#include <linux/poison.h>
  10#include <linux/interrupt.h>
  11#include <linux/memory.h>
  12#include <linux/compiler.h>
  13#include <linux/module.h>
  14#include <linux/cpu.h>
  15#include <linux/uaccess.h>
  16#include <asm/cacheflush.h>
  17#include <asm/tlbflush.h>
  18#include <asm/page.h>
  19
  20#include "slab.h"
  21
  22enum slab_state slab_state;
  23LIST_HEAD(slab_caches);
  24DEFINE_MUTEX(slab_mutex);
  25
  26/*
  27 * kmem_cache_create - Create a cache.
  28 * @name: A string which is used in /proc/slabinfo to identify this cache.
  29 * @size: The size of objects to be created in this cache.
  30 * @align: The required alignment for the objects.
  31 * @flags: SLAB flags
  32 * @ctor: A constructor for the objects.
  33 *
  34 * Returns a ptr to the cache on success, NULL on failure.
  35 * Cannot be called within a interrupt, but can be interrupted.
  36 * The @ctor is run when new pages are allocated by the cache.
  37 *
  38 * The flags are
  39 *
  40 * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5)
  41 * to catch references to uninitialised memory.
  42 *
  43 * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check
  44 * for buffer overruns.
  45 *
  46 * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware
  47 * cacheline.  This can be beneficial if you're counting cycles as closely
  48 * as davem.
  49 */
  50
  51struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align,
  52                unsigned long flags, void (*ctor)(void *))
  53{
  54        struct kmem_cache *s = NULL;
  55
  56#ifdef CONFIG_DEBUG_VM
  57        if (!name || in_interrupt() || size < sizeof(void *) ||
  58                size > KMALLOC_MAX_SIZE) {
  59                printk(KERN_ERR "kmem_cache_create(%s) integrity check"
  60                        " failed\n", name);
  61                goto out;
  62        }
  63#endif
  64
  65        get_online_cpus();
  66        mutex_lock(&slab_mutex);
  67
  68#ifdef CONFIG_DEBUG_VM
  69        list_for_each_entry(s, &slab_caches, list) {
  70                char tmp;
  71                int res;
  72
  73                /*
  74                 * This happens when the module gets unloaded and doesn't
  75                 * destroy its slab cache and no-one else reuses the vmalloc
  76                 * area of the module.  Print a warning.
  77                 */
  78                res = probe_kernel_address(s->name, tmp);
  79                if (res) {
  80                        printk(KERN_ERR
  81                               "Slab cache with size %d has lost its name\n",
  82                               s->object_size);
  83                        continue;
  84                }
  85
  86                if (!strcmp(s->name, name)) {
  87                        printk(KERN_ERR "kmem_cache_create(%s): Cache name"
  88                                " already exists.\n",
  89                                name);
  90                        dump_stack();
  91                        s = NULL;
  92                        goto oops;
  93                }
  94        }
  95
  96        WARN_ON(strchr(name, ' '));     /* It confuses parsers */
  97#endif
  98
  99        s = __kmem_cache_create(name, size, align, flags, ctor);
 100
 101#ifdef CONFIG_DEBUG_VM
  93       1          93       1  [ue="v2.6.16.30"
	lass="lin0e" name="L13">  13#i03     a href="mm/slab_common.c#L64" id="L64" 10lass="lin0e" name="L14">  14#i04     4a href="+code=s" class="sre>(&doesef">mutex_lock(&doesefhref="+code=slab_mutex" class="sref">slab_mutex);
  95
n0e"    get_online_cppu" class="srefef="mm/slab_common.c#L91" id="L91" 10lass="lin0e" name="L16">  16#i06"    6"mm/slab_common.c#L102" id="L102" lass="lin0e" name="L17">  17#i07"    7 href="+code=CONFIG_DEBUG_VM" class="sref">CONFIG_DEBUG_VM
  18#i08"    8        out;
  19
<09"    9 href="mm/slab_common.c#L64" id="L64" 1class="linne" name="L10">  10#iinclu11             "+code=strcmp" class=">s = flags, flags,   11#infdef 1                get_online_cppanic"+codetring">"kmem_cache_create(%s): Cac: F
<., name);
  12#iinclu11="mm/slab_common.c#L73" id="L73" 1class="linne" name="L13">  13#iinclu11        }

	  14#iinclu1e </slab_common.c#L95" id="L95" 1class="linne" name="L15">  15#iinclu1e <e=strcmp" classEXPORT_SYMBOf">NULL;
kmem_cache_create(const char *m/slab_common.c#L61" id="L61" 1class="linne" name="L16">  16#iinclu116"mm/slab_common.c#L102" id="L102"class="linne" name="L17">  17#iinclu1e <+code=res" class="s#L102is_avsize,   18#iinclu1e </slab_common.c#L87" id="L87" 1class="linne" name="L19">  19
<
	slab_state slab_state  20#1inclu1e &quo/slab_common.c#L95" id="L95" 1class="li1ne" name="L21">  21
1name="Lfooter">
lab_commohttp://sourceforge.neto to cach/lxr">LXR  id=unity="+cod a haexperionfual v
lxr;name="Lsubfooter">
lxr.Redpill L/s to AS="+cod tovid/spaf L/suxfor tuls close roperae inde>