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, const uint32_t *slab_sizes, void *mem_base_external, bool reuse_mem);
12 
13 /** Call only during init. Pre-allocates all available memory */
14 void slabs_prefill_global(void);
15 
16 /**
17  * Given object size, return id to use when allocating/freeing memory for object
18  * 0 means error: can't store such a large object
19  */
20 
21 unsigned int slabs_clsid(const size_t size);
22 unsigned int slabs_size(const int clsid);
23 
24 /** Allocate object of given length. 0 on error */ /*@null@*/
25 #define SLABS_ALLOC_NO_NEWPAGE 1
26 void *slabs_alloc(const size_t size, unsigned int id, unsigned int flags);
27 
28 /** Free previously allocated object */
29 void slabs_free(void *ptr, size_t size, unsigned int id);
30 
31 /** Adjust global memory limit up or down */
32 bool slabs_adjust_mem_limit(size_t new_mem_limit);
33 
34 typedef struct {
35     unsigned int chunks_per_page;
36     unsigned int chunk_size;
37     long int free_chunks;
38     long int total_pages;
39 } slab_stats_automove;
40 void fill_slab_stats_automove(slab_stats_automove *am);
41 unsigned int global_page_pool_size(bool *mem_flag);
42 
43 /** Fill buffer with stats */ /*@null@*/
44 void slabs_stats(ADD_STAT add_stats, void *c);
45 
46 /* Hints as to freespace in slab class */
47 unsigned int slabs_available_chunks(unsigned int id, bool *mem_flag, unsigned int *chunks_perslab);
48 
49 void slabs_mlock(void);
50 void slabs_munlock(void);
51 
52 int start_slab_maintenance_thread(void);
53 void stop_slab_maintenance_thread(void);
54 
55 enum reassign_result_type {
56     REASSIGN_OK=0, REASSIGN_RUNNING, REASSIGN_BADCLASS, REASSIGN_NOSPARE,
57     REASSIGN_SRC_DST_SAME
58 };
59 
60 enum reassign_result_type slabs_reassign(int src, int dst);
61 
62 void slabs_rebalancer_pause(void);
63 void slabs_rebalancer_resume(void);
64 
65 #ifdef EXTSTORE
66 void slabs_set_storage(void *arg);
67 #endif
68 
69 /* Fixup for restartable code. */
70 unsigned int slabs_fixup(char *chunk, const int border);
71 
72 #endif
73