CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sqlitemem.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SQLITEMEM_H_
6 #define CVMFS_SQLITEMEM_H_
7 
8 #include <inttypes.h>
9 #include <pthread.h>
10 #include <stdint.h>
11 
12 #include <cassert>
13 #include <cstdlib>
14 #include <vector>
15 
16 #include "duplex_sqlite3.h"
17 #include "gtest/gtest_prod.h"
18 
19 class MallocArena;
20 
21 
39  FRIEND_TEST(T_Sqlitemem, LookasideBuffer);
40  FRIEND_TEST(T_Sqlitemem, Malloc);
41  FRIEND_TEST(T_Sqlitemem, Realloc);
42  FRIEND_TEST(T_Sqlitemem, ReallocStress);
43 
44  public:
51  static const unsigned kScratchSlotSize = 8192;
56  static const unsigned kScratchNoSlots = 8;
60  static const unsigned kScratchSize = kScratchSlotSize * kScratchNoSlots;
61 
65  static const unsigned kPageCacheSlotSize = 1300;
69  static const unsigned kPageCacheNoSlots = 4000;
74 
79  static const unsigned kLookasideSlotSize = 32;
83  static const unsigned kLookasideSlotsPerDb = 128;
84 
85 
94  public:
98  static const unsigned kBufferSize =
100 
105  static const unsigned kBuffersPerArena = 128;
109  static const unsigned kArenaSize = kBuffersPerArena * kBufferSize;
113  static const unsigned kNoBitmaps = kBuffersPerArena / (sizeof(int) * 8);
114 
117 
118  void *GetBuffer();
119  void PutBuffer(void *buffer);
120  bool IsEmpty();
121  bool Contains(void *buffer);
122 
123  private:
127  void *arena_;
128 
134  };
135 
136 
138  if (instance_ == NULL)
140  return instance_;
141  }
142  static void CleanupInstance();
143  static bool HasInstance() { return instance_ != NULL; }
145 
146  void AssignGlobalArenas();
147  void *AssignLookasideBuffer(sqlite3 *db);
148  void ReleaseLookasideBuffer(void *buffer);
149 
150  private:
157  static const unsigned kArenaSize = 8 * 1024 * 1024;
159 
164  static void *xMalloc(int size);
165  static void xFree(void *ptr);
166  static void *xRealloc(void *ptr, int new_size);
167  static int xSize(void *ptr);
168  static int xRoundup(int size);
169  static int xInit(void *app_data);
170  static void xShutdown(void *app_data);
171 
172 
174 
175  void *GetLookasideBuffer();
176  void PutLookasideBuffer(void *buffer);
177 
178  void *GetMemory(int size);
179  void PutMemory(void *ptr);
180  int GetMemorySize(void *ptr);
181 
182  pthread_mutex_t lock_;
183 
188  bool assigned_;
189 
194  struct sqlite3_mem_methods sqlite3_mem_vanilla_;
195 
196  struct sqlite3_mem_methods mem_methods_;
198  std::vector<LookasideBufferArena *> lookaside_buffer_arenas_;
199  std::vector<MallocArena *> malloc_arenas_;
203  unsigned idx_last_arena_;
204 }; // class SqliteMemoryManager
205 
206 #endif // CVMFS_SQLITEMEM_H_
struct sqlite3_mem_methods sqlite3_mem_vanilla_
Definition: sqlitemem.h:194
static const unsigned kScratchSize
Definition: sqlitemem.h:60
static const unsigned kScratchNoSlots
Definition: sqlitemem.h:56
static const unsigned kPageCacheSlotSize
Definition: sqlitemem.h:65
static const unsigned kPageCacheNoSlots
Definition: sqlitemem.h:69
struct sqlite3_mem_methods mem_methods_
Definition: sqlitemem.h:196
static int xInit(void *app_data)
Definition: sqlitemem.cc:128
static int xSize(void *ptr)
Definition: sqlitemem.cc:118
static const unsigned kArenaSize
Definition: sqlitemem.h:157
void * GetLookasideBuffer()
Definition: sqlitemem.cc:179
static void xShutdown(void *app_data)
Definition: sqlitemem.cc:133
static const unsigned kBuffersPerArena
Definition: sqlitemem.h:105
void PutMemory(void *ptr)
Definition: sqlitemem.cc:296
static void CleanupInstance()
Definition: sqlitemem.cc:170
void AssignGlobalArenas()
Definition: sqlitemem.cc:137
int GetMemorySize(void *ptr)
Definition: sqlitemem.cc:197
static bool HasInstance()
Definition: sqlitemem.h:143
static const unsigned kLookasideSlotsPerDb
Definition: sqlitemem.h:83
void * GetMemory(int size)
Definition: sqlitemem.cc:205
static const unsigned kPageCacheSize
Definition: sqlitemem.h:73
static SqliteMemoryManager * instance_
Definition: sqlitemem.h:158
static void * xRealloc(void *ptr, int new_size)
Definition: sqlitemem.cc:103
static SqliteMemoryManager * GetInstance()
Definition: sqlitemem.h:137
unsigned idx_last_arena_
Definition: sqlitemem.h:203
static void xFree(void *ptr)
Definition: sqlitemem.cc:95
pthread_mutex_t lock_
Definition: sqlitemem.h:182
void * page_cache_memory_
Definition: sqlitemem.h:197
static const unsigned kLookasideSlotSize
Definition: sqlitemem.h:79
FRIEND_TEST(T_Sqlitemem, LookasideBuffer)
static int xRoundup(int size)
Definition: sqlitemem.cc:123
static const unsigned kScratchSlotSize
Definition: sqlitemem.h:51
void PutLookasideBuffer(void *buffer)
Definition: sqlitemem.cc:277
std::vector< LookasideBufferArena * > lookaside_buffer_arenas_
Definition: sqlitemem.h:198
static void size_t size
Definition: smalloc.h:47
static void * xMalloc(int size)
Definition: sqlitemem.cc:87
void ReleaseLookasideBuffer(void *buffer)
Definition: sqlitemem.cc:317
void * AssignLookasideBuffer(sqlite3 *db)
Definition: sqlitemem.cc:158
std::vector< MallocArena * > malloc_arenas_
Definition: sqlitemem.h:199