90e2bd820fd601876887dfd35df08571597c7289
[awesomized/libmemcached] / memcached / slabs.h
1 /* slabs memory allocation */
2 #ifndef SLABS_H
3 #define SLABS_H
4
5 /** Init the subsystem. 1st argument is the limit on no. of bytes to allocate,
6 0 if no limit. 2nd argument is the growth factor; each slab will use a chunk
7 size equal to the previous slab's chunk size times this factor.
8 3rd argument specifies if the slab allocator should allocate all memory
9 up front (if true), or allocate memory in chunks as it is needed (if false)
10 */
11 void slabs_init(const size_t limit, const double factor, const bool prealloc);
12
13
14 /**
15 * Given object size, return id to use when allocating/freeing memory for object
16 * 0 means error: can't store such a large object
17 */
18
19 #ifndef __INTEL_COMPILER
20 #pragma GCC diagnostic ignored "-Wshadow"
21 #endif
22 unsigned int slabs_clsid(const size_t size);
23
24 /** Allocate object of given length. 0 on error */ /*@null@*/
25 void *slabs_alloc(const size_t size, unsigned int id);
26
27 /** Free previously allocated object */
28 void slabs_free(void *ptr, size_t size, unsigned int id);
29
30 /** Adjust the stats for memory requested */
31 void slabs_adjust_mem_requested(unsigned int id, size_t old, size_t ntotal);
32
33 /** Return a datum for stats in binary protocol */
34 bool get_stats(const char *stat_type, int nkey, ADD_STAT add_stats, void *c);
35
36 /** Fill buffer with stats */ /*@null@*/
37 void slabs_stats(ADD_STAT add_stats, void *c);
38
39 int start_slab_maintenance_thread(void);
40 void stop_slab_maintenance_thread(void);
41
42 enum reassign_result_type {
43 REASSIGN_OK=0, REASSIGN_RUNNING, REASSIGN_BADCLASS, REASSIGN_NOSPARE,
44 REASSIGN_DEST_NOT_FULL, REASSIGN_SRC_NOT_SAFE, REASSIGN_SRC_DST_SAME
45 };
46
47 enum reassign_result_type slabs_reassign(int src, int dst);
48
49 #endif