Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions
zsmalloc-main.c File Reference
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/highmem.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <asm/tlbflush.h>
#include <asm/pgtable.h>
#include <linux/cpumask.h>
#include <linux/cpu.h>
#include <linux/vmalloc.h>
#include <linux/hardirq.h>
#include <linux/spinlock.h>
#include <linux/types.h>
#include "zsmalloc.h"

Go to the source code of this file.

Data Structures

struct  size_class
 
struct  link_free
 
struct  zs_pool
 
struct  mapping_area
 

Macros

#define ZS_ALIGN   8
 
#define ZS_MAX_ZSPAGE_ORDER   2
 
#define ZS_MAX_PAGES_PER_ZSPAGE   (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
 
#define MAX_PHYSMEM_BITS   BITS_PER_LONG
 
#define _PFN_BITS   (MAX_PHYSMEM_BITS - PAGE_SHIFT)
 
#define OBJ_INDEX_BITS   (BITS_PER_LONG - _PFN_BITS)
 
#define OBJ_INDEX_MASK   ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
 
#define MAX(a, b)   ((a) >= (b) ? (a) : (b))
 
#define ZS_MIN_ALLOC_SIZE   MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))
 
#define ZS_MAX_ALLOC_SIZE   PAGE_SIZE
 
#define ZS_SIZE_CLASS_DELTA   16
 
#define ZS_SIZE_CLASSES
 
#define CLASS_IDX_BITS   28
 
#define FULLNESS_BITS   4
 
#define CLASS_IDX_MASK   ((1 << CLASS_IDX_BITS) - 1)
 
#define FULLNESS_MASK   ((1 << FULLNESS_BITS) - 1)
 

Enumerations

enum  fullness_group {
  ZS_ALMOST_FULL, ZS_ALMOST_EMPTY, _ZS_NR_FULLNESS_GROUPS, ZS_EMPTY,
  ZS_FULL
}
 

Functions

struct zs_poolzs_create_pool (const char *name, gfp_t flags)
 
 EXPORT_SYMBOL_GPL (zs_create_pool)
 
void zs_destroy_pool (struct zs_pool *pool)
 
 EXPORT_SYMBOL_GPL (zs_destroy_pool)
 
unsigned long zs_malloc (struct zs_pool *pool, size_t size)
 
 EXPORT_SYMBOL_GPL (zs_malloc)
 
void zs_free (struct zs_pool *pool, unsigned long obj)
 
 EXPORT_SYMBOL_GPL (zs_free)
 
voidzs_map_object (struct zs_pool *pool, unsigned long handle, enum zs_mapmode mm)
 
 EXPORT_SYMBOL_GPL (zs_map_object)
 
void zs_unmap_object (struct zs_pool *pool, unsigned long handle)
 
 EXPORT_SYMBOL_GPL (zs_unmap_object)
 
u64 zs_get_total_size_bytes (struct zs_pool *pool)
 
 EXPORT_SYMBOL_GPL (zs_get_total_size_bytes)
 
 module_init (zs_init)
 
 module_exit (zs_exit)
 
 MODULE_LICENSE ("Dual BSD/GPL")
 
 MODULE_AUTHOR ("Nitin Gupta <[email protected]>")
 

Macro Definition Documentation

#define _PFN_BITS   (MAX_PHYSMEM_BITS - PAGE_SHIFT)

Definition at line 121 of file zsmalloc-main.c.

#define CLASS_IDX_BITS   28

Definition at line 217 of file zsmalloc-main.c.

#define CLASS_IDX_MASK   ((1 << CLASS_IDX_BITS) - 1)

Definition at line 219 of file zsmalloc-main.c.

#define FULLNESS_BITS   4

Definition at line 218 of file zsmalloc-main.c.

#define FULLNESS_MASK   ((1 << FULLNESS_BITS) - 1)

Definition at line 220 of file zsmalloc-main.c.

#define MAX (   a,
  b 
)    ((a) >= (b) ? (a) : (b))

Definition at line 125 of file zsmalloc-main.c.

#define MAX_PHYSMEM_BITS   BITS_PER_LONG

Definition at line 118 of file zsmalloc-main.c.

#define OBJ_INDEX_BITS   (BITS_PER_LONG - _PFN_BITS)

Definition at line 122 of file zsmalloc-main.c.

#define OBJ_INDEX_MASK   ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)

Definition at line 123 of file zsmalloc-main.c.

#define ZS_ALIGN   8

Definition at line 90 of file zsmalloc-main.c.

#define ZS_MAX_ALLOC_SIZE   PAGE_SIZE

Definition at line 129 of file zsmalloc-main.c.

#define ZS_MAX_PAGES_PER_ZSPAGE   (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)

Definition at line 97 of file zsmalloc-main.c.

#define ZS_MAX_ZSPAGE_ORDER   2

Definition at line 96 of file zsmalloc-main.c.

#define ZS_MIN_ALLOC_SIZE   MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))

Definition at line 127 of file zsmalloc-main.c.

#define ZS_SIZE_CLASS_DELTA   16

Definition at line 144 of file zsmalloc-main.c.

#define ZS_SIZE_CLASSES
Value:

Definition at line 145 of file zsmalloc-main.c.

Enumeration Type Documentation

Enumerator:
ZS_ALMOST_FULL 
ZS_ALMOST_EMPTY 
_ZS_NR_FULLNESS_GROUPS 
ZS_EMPTY 
ZS_FULL 

Definition at line 151 of file zsmalloc-main.c.

Function Documentation

EXPORT_SYMBOL_GPL ( zs_create_pool  )
EXPORT_SYMBOL_GPL ( zs_destroy_pool  )
EXPORT_SYMBOL_GPL ( zs_malloc  )
EXPORT_SYMBOL_GPL ( zs_free  )
EXPORT_SYMBOL_GPL ( zs_map_object  )
EXPORT_SYMBOL_GPL ( zs_unmap_object  )
EXPORT_SYMBOL_GPL ( zs_get_total_size_bytes  )
MODULE_AUTHOR ( "Nitin Gupta <[email protected]>"  )
module_exit ( zs_exit  )
module_init ( zs_init  )
MODULE_LICENSE ( "Dual BSD/GPL"  )
struct zs_pool* zs_create_pool ( const char name,
gfp_t  flags 
)
read

Definition at line 801 of file zsmalloc-main.c.

void zs_destroy_pool ( struct zs_pool pool)

Definition at line 837 of file zsmalloc-main.c.

void zs_free ( struct zs_pool pool,
unsigned long  obj 
)

Definition at line 916 of file zsmalloc-main.c.

u64 zs_get_total_size_bytes ( struct zs_pool pool)

Definition at line 1048 of file zsmalloc-main.c.

unsigned long zs_malloc ( struct zs_pool pool,
size_t  size 
)

zs_malloc - Allocate block of given size from pool. : pool to allocate from : size of block to allocate

On success, handle to the allocated object is returned, otherwise 0. Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.

Definition at line 866 of file zsmalloc-main.c.

void* zs_map_object ( struct zs_pool pool,
unsigned long  handle,
enum zs_mapmode  mm 
)

zs_map_object - get address of allocated object from handle. : pool from which the object was allocated : handle returned from zs_malloc

Before using an object allocated from zs_malloc, it must be mapped using this function. When done with the object, it must be unmapped using zs_unmap_object.

Only one object can be mapped per cpu at a time. There is no protection against nested mappings.

This function returns with preemption and page faults disabled.

Definition at line 972 of file zsmalloc-main.c.

void zs_unmap_object ( struct zs_pool pool,
unsigned long  handle 
)

Definition at line 1015 of file zsmalloc-main.c.