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); 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 unsigned int slabs_clsid(const size_t size); 20 21 /** Allocate object of given length. 0 on error */ /*@null@*/ 22 #define SLABS_ALLOC_NO_NEWPAGE 1 23 void *slabs_alloc(const size_t size, unsigned int id, uint64_t *total_bytes, unsigned int flags); 24 25 /** Free previously allocated object */ 26 void slabs_free(void *ptr, size_t size, unsigned int id); 27 28 /** Adjust the stats for memory requested */ 29 void slabs_adjust_mem_requested(unsigned int id, size_t old, size_t ntotal); 30 31 /** Adjust global memory limit up or down */ 32 bool slabs_adjust_mem_limit(size_t new_mem_limit); 33 34 /** Return a datum for stats in binary protocol */ 35 bool get_stats(const char *stat_type, int nkey, ADD_STAT add_stats, void *c); 36 37 /** Fill buffer with stats */ /*@null@*/ 38 void slabs_stats(ADD_STAT add_stats, void *c); 39 40 /* Hints as to freespace in slab class */ 41 unsigned int slabs_available_chunks(unsigned int id, bool *mem_flag, uint64_t *total_bytes, unsigned int *chunks_perslab); 42 43 int start_slab_maintenance_thread(void); 44 void stop_slab_maintenance_thread(void); 45 46 enum reassign_result_type { 47 REASSIGN_OK=0, REASSIGN_RUNNING, REASSIGN_BADCLASS, REASSIGN_NOSPARE, 48 REASSIGN_SRC_DST_SAME 49 }; 50 51 enum reassign_result_type slabs_reassign(int src, int dst); 52 53 void slabs_rebalancer_pause(void); 54 void slabs_rebalancer_resume(void); 55 56 #endif 57