public
Fork of dustin/memcached
Description: This is where my memcached work lives before svn munges the changes.
Homepage: http://www.danga.com/memcached/
Clone URL: git://github.com/tmaesaka/memcached.git
memcached / slabs.h
100644 83 lines (72 sloc) 2.551 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* slabs memory allocation */
 
/**
* Initialize the slab subsystem.
*
* @param limit The number of bytes to allocate.
* @param factor The growth factor. Each slab will use a chunk size equal
* to the previous slab's chunk size times this factor.
* @param prealloc specifies if the slab allocator should allocate all memory
* up front (if true), or allocate memory in chunks as it is
* needed (if false).
*/
void slabs_init(const size_t limit, const double factor, const bool prealloc);
 
 
/**
* Given object size, return id to use when allocating/freeing memory for
* object.
*
* 0 means error: can't store such a large object
*/
unsigned int slabs_clsid(const size_t size);
 
/**
* Allocate a memory area of a given size in the specified class.
* You should call this function if you don't hold the slab mutex
*
* @param engine handle to the slabber engine
* @param size the size to allocate
* @param id the slab class to allocate in
* @return pointer to allocated area or NULL when there is no more space
*/
void *slabs_alloc(struct slabber_engine *engine, size_t size, unsigned int id);
 
/**
* Allocate a memory area of a given size in the specified class.
*
* @param size the size to allocate
* @param id the slab class to allocate in
* @return pointer to allocated area or NULL when there is no more space
*/
void *do_slabs_alloc(const size_t size, unsigned int id);
 
/**
* Free previously allocated object.
* You should call this function if you don't hold the slab mutex
*
* @param engine handle to the slabber engine.
* @param ptr pointer to the object
* @param size size of the object
* @param id slab class for the object
*/
void slabs_free(struct slabber_engine *engine, void *ptr, size_t size, unsigned int id);
 
/**
* Free previously allocated object.
*
* @param ptr pointer to the object
* @param size size of the object
* @param id slab class for the object
*/
void do_slabs_free(void *ptr, size_t size, unsigned int id);
 
/**
* Get statistics from the slab subsystem
*
* @return a null-terminated string containing statistics information. Caller
* must free this string to avoid memory leakage.
*/
char* do_slabs_stats(void);
 
 
#ifdef ALLOW_SLABS_REASSIGN
/**
* Request some slab be moved between classes.
*
* @param srcid slab class to move from
* @param dstid slab class to move to
* @return 1 success, 0 fail, -1 tried, but busy (you should try again)
*/
int do_slabs_reassign(unsigned char srcid, unsigned char dstid);
#endif