5 #define __STDC_FORMAT_MACROS
7 #include "cvmfs_config.h"
24 for (
unsigned i = 0; i < kNoBitmaps; ++i) {
25 int bit_set = ffs(freemap_[i]);
27 freemap_[i] &= ~(1 << (bit_set - 1));
28 const int nbuffer = i *
sizeof(int) * 8 + bit_set - 1;
29 return reinterpret_cast<char *
>(arena_) + nbuffer *
kBufferSize;
37 for (
unsigned i = 0; i < kNoBitmaps; ++i) {
38 if (~freemap_[i] != 0)
46 if ((buffer == NULL) || (buffer < arena_))
48 return (static_cast<uint64_t>(
49 (reinterpret_cast<char *>(buffer) - reinterpret_cast<char *>(arena_))) <
55 : arena_(sxmmap(kArenaSize))
70 (
reinterpret_cast<char *
>(buffer) - reinterpret_cast<char *>(arena_))
72 assert(static_cast<uint64_t>(nbuffer) < kBuffersPerArena);
73 const int nfreemap = nbuffer / (
sizeof(int) * 8);
74 freemap_[nfreemap] |= 1 << (nbuffer % (
sizeof(int) * 8));
104 int old_size =
xSize(ptr);
105 if (old_size >= new_size)
108 void *new_ptr =
xMalloc(new_size);
109 memcpy(new_ptr, ptr, old_size);
143 assert(retval == SQLITE_OK);
146 assert(retval == SQLITE_OK);
147 retval = sqlite3_config(SQLITE_CONFIG_MALLOC, &
mem_methods_);
148 assert(retval == SQLITE_OK);
163 int retval = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE,
165 assert(retval == SQLITE_OK);
181 vector<LookasideBufferArena *>::reverse_iterator reverse_iter =
183 vector<LookasideBufferArena *>::reverse_iterator i_rend =
185 for (; reverse_iter != i_rend; ++reverse_iter) {
186 result = (*reverse_iter)->GetBuffer();
210 for (
unsigned i = 0; i < N; ++i) {
232 int retval = pthread_mutex_init(&
lock_, NULL);
257 retval = sqlite3_config(SQLITE_CONFIG_PAGECACHE, NULL, 0, 0);
258 assert(retval == SQLITE_OK);
260 assert(retval == SQLITE_OK);
268 pthread_mutex_destroy(&
lock_);
279 for (
unsigned i = 0; i < N; ++i) {
301 for (
unsigned i = 0; i < N; ++i) {
struct sqlite3_mem_methods sqlite3_mem_vanilla_
static const unsigned kPageCacheSlotSize
static MallocArena * GetMallocArena(void *ptr, unsigned arena_size)
static const unsigned kPageCacheNoSlots
static const unsigned kNoBitmaps
struct sqlite3_mem_methods mem_methods_
const unsigned kBufferSize
static int xInit(void *app_data)
static int xSize(void *ptr)
static const unsigned kArenaSize
void * GetLookasideBuffer()
static void xShutdown(void *app_data)
assert((mem||(size==0))&&"Out Of Memory")
void PutMemory(void *ptr)
static void CleanupInstance()
bool Contains(void *buffer)
void AssignGlobalArenas()
struct cvmcache_object_info __attribute__
int GetMemorySize(void *ptr)
static const unsigned kLookasideSlotsPerDb
void * GetMemory(int size)
static const unsigned kPageCacheSize
static SqliteMemoryManager * instance_
static void * xRealloc(void *ptr, int new_size)
static uint64_t RoundUp8(const uint64_t size)
static void xFree(void *ptr)
void * page_cache_memory_
static const unsigned kLookasideSlotSize
static int xRoundup(int size)
void * Malloc(const uint32_t size)
void PutLookasideBuffer(void *buffer)
uint32_t GetSize(void *ptr) const
std::vector< LookasideBufferArena * > lookaside_buffer_arenas_
void PutBuffer(void *buffer)
static void * xMalloc(int size)
void ReleaseLookasideBuffer(void *buffer)
void * AssignLookasideBuffer(sqlite3 *db)
std::vector< MallocArena * > malloc_arenas_