MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
slabs.h
1 /* slabs memory allocation */
2 #ifndef SLABS_H
3 #define SLABS_H
4 
5 #include "default_engine.h"
6 
7 
8 
9 /* powers-of-N allocation structures */
10 
11 typedef struct {
12  unsigned int size; /* sizes of items */
13  unsigned int perslab; /* how many items per slab */
14 
15  void **slots; /* list of item ptrs */
16  unsigned int sl_total; /* size of previous array */
17  unsigned int sl_curr; /* first free slot */
18 
19  void *end_page_ptr; /* pointer to next free item at end of page, or 0 */
20  unsigned int end_page_free; /* number of items remaining at end of last alloced page */
21 
22  unsigned int slabs; /* how many slabs were allocated for this class */
23 
24  void **slab_list; /* array of slab pointers */
25  unsigned int list_size; /* size of prev array */
26 
27  unsigned int killing; /* index+1 of dying slab, or zero if none */
28  size_t requested; /* The number of requested bytes */
29 } slabclass_t;
30 
31 struct slabs {
32  slabclass_t slabclass[MAX_NUMBER_OF_SLAB_CLASSES];
33  size_t mem_limit;
34  size_t mem_malloced;
35  int power_largest;
36 
37  void *mem_base;
38  void *mem_current;
39  size_t mem_avail;
40 
44  pthread_mutex_t lock;
45 };
46 
47 
48 
49 
56 ENGINE_ERROR_CODE slabs_init(struct default_engine *engine,
57  const size_t limit,
58  const double factor,
59  const bool prealloc);
60 
61 
67 unsigned int slabs_clsid(struct default_engine *engine, const size_t size);
68  /*@null@*/
70 void *slabs_alloc(struct default_engine *engine, const size_t size, unsigned int id);
71 
73 void slabs_free(struct default_engine *engine, void *ptr, size_t size, unsigned int id);
74  /*@null@*/
76 void slabs_stats(struct default_engine *engine, ADD_STAT add_stats, const void *c);
77 
78 void add_statistics(const void *cookie, ADD_STAT add_stats,
79  const char *prefix, int num, const char *key,
80  const char *fmt, ...);
81 
82 #endif