xref: /memcached-1.4.29/slabs.h (revision ee461d11)
177dde9f9SPaul Lindner /* slabs memory allocation */
2d9220d64STrond Norbye #ifndef SLABS_H
3d9220d64STrond Norbye #define SLABS_H
477dde9f9SPaul Lindner 
5516e7dc2SPaul Lindner /** Init the subsystem. 1st argument is the limit on no. of bytes to allocate,
677dde9f9SPaul Lindner     0 if no limit. 2nd argument is the growth factor; each slab will use a chunk
7a6b35b44STrond Norbye     size equal to the previous slab's chunk size times this factor.
8a6b35b44STrond Norbye     3rd argument specifies if the slab allocator should allocate all memory
9a6b35b44STrond Norbye     up front (if true), or allocate memory in chunks as it is needed (if false)
10a6b35b44STrond Norbye */
11d7fb022dSdormando void slabs_init(const size_t limit, const double factor, const bool prealloc, const uint32_t *slab_sizes);
1277dde9f9SPaul Lindner 
1377dde9f9SPaul Lindner 
14516e7dc2SPaul Lindner /**
1577dde9f9SPaul Lindner  * Given object size, return id to use when allocating/freeing memory for object
1677dde9f9SPaul Lindner  * 0 means error: can't store such a large object
1777dde9f9SPaul Lindner  */
1877dde9f9SPaul Lindner 
1977dde9f9SPaul Lindner unsigned int slabs_clsid(const size_t size);
2077dde9f9SPaul Lindner 
21516e7dc2SPaul Lindner /** Allocate object of given length. 0 on error */ /*@null@*/
22b1debc4cSdormando #define SLABS_ALLOC_NO_NEWPAGE 1
23*ee461d11Sdormando void *slabs_alloc(const size_t size, unsigned int id, uint64_t *total_bytes, unsigned int flags);
2477dde9f9SPaul Lindner 
25516e7dc2SPaul Lindner /** Free previously allocated object */
26d9220d64STrond Norbye void slabs_free(void *ptr, size_t size, unsigned int id);
2777dde9f9SPaul Lindner 
28efad616dSTrond Norbye /** Adjust the stats for memory requested */
29efad616dSTrond Norbye void slabs_adjust_mem_requested(unsigned int id, size_t old, size_t ntotal);
30efad616dSTrond Norbye 
3131541b37Sdormando /** Adjust global memory limit up or down */
3231541b37Sdormando bool slabs_adjust_mem_limit(size_t new_mem_limit);
3331541b37Sdormando 
34f4a8e7ffSToru Maesaka /** Return a datum for stats in binary protocol */
3517df5c0eSTrond Norbye bool get_stats(const char *stat_type, int nkey, ADD_STAT add_stats, void *c);
364c77f591SToru Maesaka 
37516e7dc2SPaul Lindner /** Fill buffer with stats */ /*@null@*/
3817df5c0eSTrond Norbye void slabs_stats(ADD_STAT add_stats, void *c);
3977dde9f9SPaul Lindner 
40fb269897Sdormando /* Hints as to freespace in slab class */
41*ee461d11Sdormando unsigned int slabs_available_chunks(unsigned int id, bool *mem_flag, uint64_t *total_bytes, unsigned int *chunks_perslab);
42fb269897Sdormando 
4310698baeSdormando int start_slab_maintenance_thread(void);
4410698baeSdormando void stop_slab_maintenance_thread(void);
4510698baeSdormando 
4610698baeSdormando enum reassign_result_type {
4710698baeSdormando     REASSIGN_OK=0, REASSIGN_RUNNING, REASSIGN_BADCLASS, REASSIGN_NOSPARE,
48423b9fd4Sdormando     REASSIGN_SRC_DST_SAME
4910698baeSdormando };
5010698baeSdormando 
5110698baeSdormando enum reassign_result_type slabs_reassign(int src, int dst);
5210698baeSdormando 
531c94e12cSdormando void slabs_rebalancer_pause(void);
541c94e12cSdormando void slabs_rebalancer_resume(void);
551c94e12cSdormando 
56d9220d64STrond Norbye #endif
57