#include <ncbi_pch.hpp>
#include <db/sqlite/sqlitewrapp.hpp>
#include "nc_memory.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
Include dependency graph for nc_memory.cpp:

Go to the source code of this file.
Functions | |
| DEFINE_CLASS_STATIC_FAST_MUTEX (CNCMMCentral::sm_CentralLock) | |
| static unsigned int | s_GetCntPerGrade (unsigned int total, unsigned int grades) |
| Get number of blocks (or something else) per each emptiness grade when given total number of blocks and number of grades. | |
| static unsigned int | s_GetGradeValue (unsigned int cur_cnt, unsigned int cnt_per_grade) |
| Get emptiness grade value when given current number of blocks (or something else) and number of blocks per each grade. | |
| static int | s_SQLITE_PCache_Init (void *) |
| Initialize database cache. | |
| static void | s_SQLITE_PCache_Shutdown (void *) |
| Deinitialize database cache. | |
| static sqlite3_pcache * | s_SQLITE_PCache_Create (int szPage, int bPurgeable) |
| Create new cache instance. | |
| static void | s_SQLITE_PCache_SetSize (sqlite3_pcache *pcache, int nCachesize) |
| Set size of database cache (number of pages). | |
| static int | s_SQLITE_PCache_GetSize (sqlite3_pcache *pcache) |
| Get number of pages stored in cache. | |
| static void * | s_SQLITE_PCache_GetPage (sqlite3_pcache *pcache, unsigned int key, int createFlag) |
| Get page from cache. | |
| static void | s_SQLITE_PCache_UnpinPage (sqlite3_pcache *pcache, void *page, int discard) |
| Release page (make it reusable by others). | |
| static void | s_SQLITE_PCache_Truncate (sqlite3_pcache *pcache, unsigned int iLimit) |
| Truncate cache, delete all pages with keys greater or equal to given limit. | |
| static void | s_SQLITE_PCache_Destroy (sqlite3_pcache *pcache) |
| Destroy cache instance. | |
| static void * | s_SQLITE_Mem_Malloc (int size) |
| Allocate memory for SQLite. | |
| static void | s_SQLITE_Mem_Free (void *ptr) |
| Free memory allocated for SQLite. | |
| static void * | s_SQLITE_Mem_Realloc (void *ptr, int new_size) |
| Resize memory allocated for SQLite. | |
| static int | s_SQLITE_Mem_Size (void *ptr) |
| Get size of memory allocated for SQLite. | |
| static int | s_SQLITE_Mem_Roundup (int size) |
| Get size of memory that will be allocated if given size is requested. | |
| static int | s_SQLITE_Mem_Init (void *) |
| Initialize memory managing module for SQLite. | |
| static void | s_SQLITE_Mem_Shutdown (void *) |
| Deinitialize memory managing module for SQLite. | |
| END_NCBI_SCOPE void * | operator new (size_t size) throw (std::bad_alloc) |
| void | operator delete (void *ptr) throw () |
| void * | operator new[] (size_t size) throw (std::bad_alloc) |
| void | operator delete[] (void *ptr) throw () |
| void * | malloc (size_t size) |
| void | free (void *ptr) |
| void * | realloc (void *mem_ptr, size_t new_size) |
| void * | calloc (size_t num, size_t size) |
Variables | |
| static const size_t | kNCMMDefMemoryLimit = 1024 * 1024 * 1024 |
| Default global limit on memory consumption. | |
| static const unsigned int | kNCMMMaxSmallSize |
| Maximum size of small block (which is less than size of memory chunk) manager can allocate. | |
| static const unsigned int | kNCMMSmallSize [kNCMMCntSmallSizes] |
| List of all distinct sizes of small blocks memory manager can allocate. | |
| static unsigned int | kNCMMSmallSizeIndex [kNCMMMaxSmallSize/8+1] = {0} |
| List of indexes inside kNCMMSmallSize for each block size that can be requested. | |
| static unsigned int | kNCMMBlocksPerSet [kNCMMCntSmallSizes] = {0} |
| Number of blocks that fits into one blocks set for each block size. | |
| static unsigned int | kNCMMBlocksPerGrade [kNCMMCntSmallSizes] = {0} |
| Number of blocks that fits into one emptiness grade of blocks set. | |
| static unsigned int | kNCMMLostPerSet [kNCMMCntSmallSizes] = {0} |
| Number of bytes lost at the end of blocks set for each block size. | |
| static unsigned int | kNCMMOverheadPerSet [kNCMMCntSmallSizes] = {0} |
| Number of bytes used by manager in each blocks set (different for each block size). | |
| static const unsigned int | kNCMMChunksPerSlabGrade = kNCMMCntChunksInSlab / (kNCMMSlabEmptyGrades - 1) + 1 |
| Number of chunks in each slab's emptiness grade. | |
| static const size_t | kNCMMSizePoolArraySize = sizeof(CNCMMSizePool) * kNCMMCntSmallSizes |
| Size of CNCMMSizePool[] array containing pools for each block size that memory manager can allocate. | |
| static const int | kNCMMSQLiteBigBlockMin = 2 * kNCMMChunkSize - kNCMMSetBaseSize |
| "Magic" minimum size of block requested by SQLite that should be converted to allocation of maximum size - kNCMMSQLiteBigBlockReal. | |
| static const int | kNCMMSQLiteBigBlockReal = 2010000 |
| The real size of big block that will be allocated for SQLite if it requests for something greater than kNCMMSQLiteBigBlockMin. | |
| static const int | kNCMMDBHashSizeFactor = 8 |
| "The goal" for hash-table in database cache on the number of pages to have for each hash value. | |
| static const int | kNCMMBGThreadWaitSecs = 5 |
| Frequency of background thread iterations in seconds between them. | |
| static const size_t | kNCMMLimitToleranceChunks = 25 |
| Number of chunks that manager allows to be used on top of global limit for memory consumption. | |
| static const size_t | kNCMMMemPageSize = 4 * 1024 |
| Size of memory page that is a granularity of all allocations from OS. | |
| static const size_t | kNCMMMemPageAlignMask = ~(kNCMMMemPageSize - 1) |
| Mask that can move pointer address or memory size to the memory page boundary. | |
| static const int | kNCMmapProtection = PROT_READ | PROT_WRITE |
| Combination of flags used as "protection" parameter to mmap(). | |
| static sqlite3_pcache_methods | s_NCDBCacheMethods |
| All methods of database cache exposed to SQLite. | |
| static sqlite3_mem_methods | s_NCMallocMethods |
| All methods of memory management exposed to SQLite. | |
|
||||||||||||
|
|
|
|
|
|
|
Definition at line 3280 of file nc_memory.cpp. |
|
|
Definition at line 3297 of file nc_memory.cpp. |
|
|
Definition at line 3269 of file nc_memory.cpp. Referenced by CNCMMDBCache::operator new(). |
|
|
Definition at line 3286 of file nc_memory.cpp. |
|
||||||||||||
|
||||||||||||
|
Get number of blocks (or something else) per each emptiness grade when given total number of blocks and number of grades.
Definition at line 232 of file nc_memory.cpp. Referenced by CNCMMCentral::x_Initialize(). |
|
||||||||||||
|
Get emptiness grade value when given current number of blocks (or something else) and number of blocks per each grade.
Definition at line 240 of file nc_memory.cpp. Referenced by CNCMMSlab::x_CalcEmptyGrade(), and CNCMMBlocksSet::x_CalcEmptyGrade(). |
|
|
Free memory allocated for SQLite.
Definition at line 3144 of file nc_memory.cpp. References CNCMMCentral::DeallocMemory(). |
|
|
Initialize memory managing module for SQLite.
Definition at line 3172 of file nc_memory.cpp. |
|
|
Allocate memory for SQLite.
Definition at line 3129 of file nc_memory.cpp. References _ASSERT, CNCMMCentral::AllocMemory(), kNCMMSQLiteBigBlockMin, and kNCMMSQLiteBigBlockReal. |
|
||||||||||||
|
Resize memory allocated for SQLite.
Definition at line 3151 of file nc_memory.cpp. References CNCMMCentral::ReallocMemory(). |
|
|
Get size of memory that will be allocated if given size is requested.
Definition at line 3165 of file nc_memory.cpp. |
|
|
Deinitialize memory managing module for SQLite.
Definition at line 3179 of file nc_memory.cpp. |
|
|
Get size of memory allocated for SQLite.
Definition at line 3158 of file nc_memory.cpp. References CNCMMCentral::GetMemorySize(). |
|
||||||||||||
|
Create new cache instance.
Definition at line 3076 of file nc_memory.cpp. |
|
|
Destroy cache instance.
Definition at line 3122 of file nc_memory.cpp. |
|
||||||||||||||||
|
Get page from cache.
Definition at line 3098 of file nc_memory.cpp. |
|
|
Get number of pages stored in cache.
Definition at line 3091 of file nc_memory.cpp. |
|
|
Initialize database cache.
Definition at line 3064 of file nc_memory.cpp. |
|
||||||||||||
|
Set size of database cache (number of pages).
Definition at line 3084 of file nc_memory.cpp. |
|
|
Deinitialize database cache.
Definition at line 3071 of file nc_memory.cpp. |
|
||||||||||||
|
Truncate cache, delete all pages with keys greater or equal to given limit.
Definition at line 3115 of file nc_memory.cpp. |
|
||||||||||||||||
|
Release page (make it reusable by others).
Definition at line 3108 of file nc_memory.cpp. |
|
|
Combination of flags used as "protection" parameter to mmap().
Definition at line 177 of file nc_memory.cpp. Referenced by CNCMMCentral::x_DoCallMmap(). |
|
|
Frequency of background thread iterations in seconds between them.
Definition at line 153 of file nc_memory.cpp. Referenced by CNCMMCentral::x_DoBackgroundWork(). |
|
|
Number of blocks that fits into one emptiness grade of blocks set. Array is initialized during manager initialization. Definition at line 113 of file nc_memory.cpp. Referenced by CNCMMBlocksSet::x_CalcEmptyGrade(), and CNCMMCentral::x_Initialize(). |
|
|
Number of blocks that fits into one blocks set for each block size. Array is initialized during manager initialization. Definition at line 110 of file nc_memory.cpp. Referenced by CNCMMBlocksSet::CNCMMBlocksSet(), CNCMMSizePool::x_DeallocateBlock(), CNCMMCentral::x_Initialize(), and CNCMMBlocksSet::~CNCMMBlocksSet(). |
|
|
Number of chunks in each slab's emptiness grade. The formula is taken from s_GetCntPerGrade() and should be exact copy of it. It's repeated here just to make this a compile-time constant. Definition at line 126 of file nc_memory.cpp. Referenced by CNCMMSlab::x_CalcEmptyGrade(). |
|
|
"The goal" for hash-table in database cache on the number of pages to have for each hash value.
Definition at line 151 of file nc_memory.cpp. Referenced by CNCMMDBPagesHash::SetOptimalSize(). |
|
|
Default global limit on memory consumption.
Definition at line 85 of file nc_memory.cpp. Referenced by CNCMMCentral::SetMemLimits(). |
|
|
Number of chunks that manager allows to be used on top of global limit for memory consumption.
Definition at line 156 of file nc_memory.cpp. Referenced by CNCMMCentral::x_CalcMemoryMode(). |
|
|
Number of bytes lost at the end of blocks set for each block size. Array is initialized during manager initialization. Definition at line 116 of file nc_memory.cpp. Referenced by CNCMMStats::BlocksSetCreated(), CNCMMStats::BlocksSetDeleted(), and CNCMMCentral::x_Initialize(). |
|
|
Initial value:
(kNCMMSetDataSize / 2 - kNCMMBlockExtraSize) & ~7
Definition at line 88 of file nc_memory.cpp. Referenced by CNCMMSizePool::AllocateBlock(), CNCMMCentral::AllocMemory(), and CNCMMCentral::DeallocMemory(). |
|
|
Mask that can move pointer address or memory size to the memory page boundary.
Definition at line 163 of file nc_memory.cpp. Referenced by CNCMMCentral::x_AlignSizeToPage(). |
|
|
Size of memory page that is a granularity of all allocations from OS.
Definition at line 160 of file nc_memory.cpp. Referenced by CNCMMCentral::x_AlignSizeToPage(). |
|
|
Number of bytes used by manager in each blocks set (different for each block size). Memory mentioned is used by manager as opposed to the one used by real data requested by outside user. Array is initialized during manager initialization. Definition at line 121 of file nc_memory.cpp. Referenced by CNCMMStats::BlocksSetCreated(), CNCMMStats::BlocksSetDeleted(), and CNCMMCentral::x_Initialize(). |
|
|
Size of CNCMMSizePool[] array containing pools for each block size that memory manager can allocate. This array is allocated for each thread (up to kNCMMMaxThreadsCnt instances). Definition at line 132 of file nc_memory.cpp. Referenced by CNCMMSizePool_Getter::CreateTlsObject(), and CNCMMSizePool_Getter::DeleteTlsObject(). |
|
|
Initial value:
{ 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 96, 112, 128, 152, 176, 208, 248,
296, 352, 416, 496, 592, 704, 840, 1008, 1208, 1448, 1736, 2080, 2496,
(kNCMMSetDataSize / 11 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 9 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 8 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 7 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 6 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 5 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 4 - kNCMMBlockExtraSize) & ~7,
(kNCMMSetDataSize / 3 - kNCMMBlockExtraSize) & ~7,
kNCMMMaxSmallSize }
Definition at line 91 of file nc_memory.cpp. Referenced by CNCMMBlocksSet::CNCMMBlocksSet(), CNCMMBlocksSetBase::GetBlockSize(), CNCMMStats::MemBlockAlloced(), CNCMMStats::MemBlockFreed(), CNCMMStats::Print(), CNCMMSizePool::x_DeallocateBlock(), and CNCMMCentral::x_Initialize(). |
|
|
List of indexes inside kNCMMSmallSize for each block size that can be requested. Indexes are stored for each size divided by 8 because non-divisible sizes will not be allocated anyway. Array is initialized during manager initialization. Definition at line 107 of file nc_memory.cpp. Referenced by CNCMMSizePool::AllocateBlock(). |
|
|
"Magic" minimum size of block requested by SQLite that should be converted to allocation of maximum size - kNCMMSQLiteBigBlockReal. This constant basically means that on any request from SQLite for allocation of chunks chain with more than 2 chunks the actual allocation will contain at least kNCMMSQLiteBigBlockReal bytes.
Definition at line 142 of file nc_memory.cpp. Referenced by s_SQLITE_Mem_Malloc(). |
|
|
The real size of big block that will be allocated for SQLite if it requests for something greater than kNCMMSQLiteBigBlockMin.
Definition at line 147 of file nc_memory.cpp. Referenced by s_SQLITE_Mem_Malloc(). |
|
|
Initial value: {
NULL,
s_SQLITE_PCache_Init,
s_SQLITE_PCache_Shutdown,
s_SQLITE_PCache_Create,
s_SQLITE_PCache_SetSize,
s_SQLITE_PCache_GetSize,
s_SQLITE_PCache_GetPage,
s_SQLITE_PCache_UnpinPage,
NULL,
s_SQLITE_PCache_Truncate,
s_SQLITE_PCache_Destroy
}
Definition at line 3184 of file nc_memory.cpp. |
|
|
Initial value: {
s_SQLITE_Mem_Malloc,
s_SQLITE_Mem_Free,
s_SQLITE_Mem_Realloc,
s_SQLITE_Mem_Size,
s_SQLITE_Mem_Roundup,
s_SQLITE_Mem_Init,
s_SQLITE_Mem_Shutdown,
NULL
}
Definition at line 3199 of file nc_memory.cpp. |
1.4.6
Modified on Mon Dec 07 16:21:42 2009 by modify_doxy.py rev. 173732