A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/nc__memory_8cpp_source.html below:

NCBI C++ ToolKit: src/app/netcache/nc_memory.cpp Source File

38 # include <sys/types.h> 39 # include <sys/stat.h> 40 # include <sys/mman.h> 92

{ 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 96, 112, 128, 152, 176, 208, 248,

93

296, 352, 416, 496, 592, 704, 840, 1008, 1208, 1448, 1736, 2080, 2496,

174 static const int

kNCMmapProtection = PROT_READ | PROT_WRITE;

227 static inline unsigned int 230  return

total / (grades - 1) + 1;

235 static inline unsigned int 238  return

(cur_cnt + cnt_per_grade - 1) / cnt_per_grade;

247  if

(alert_level / 2 < limit) {

251

alert_level = 2 * limit;

279

memset(

this

, 0,

sizeof

(*

this

));

513  unsigned int

chain_size)

527  unsigned int

chain_size)

608  stats

->InitInstance();

636

proxy <<

"System - "

<<

m_SysAllocs

<<

" (allocs), " 649

<<

"By size:"

<< endl;

668

<<

" (total)"

<< endl;

721  return reinterpret_cast<void

*

>

(

737 #ifndef NCBI_OS_MSWIN 740

CNCMMCentral::x_DoCallMmap(

size_t size

)

744

ptr = mmap(

NULL

,

size

, kNCMmapProtection,

745

MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

747  static int

fd = ::open(

"/dev/zero"

, O_RDWR);

748

ptr = mmap(

NULL

,

size

, kNCMmapProtection,

751  if

(ptr == MAP_FAILED)

774

mem_ptr = VirtualAlloc(aligned_ptr,

size

,

779  _ASSERT

(mem_ptr == aligned_ptr);

786

munmap(

static_cast<char

*

>

(mem_ptr),

size

);

793  size_t

before_size =

static_cast<char

*

>

(aligned_ptr)

794

-

static_cast<char

*

>

(mem_ptr);

795  if

(before_size != 0)

796

munmap(

static_cast<char

*

>

(mem_ptr), before_size);

799  if

(after_size != 0) {

800  void

* after_ptr =

static_cast<char

*

>

(aligned_ptr) +

size

;

801

munmap(

static_cast<char

*

>

(after_ptr), after_size);

804

mem_ptr = aligned_ptr;

812  size_t

unaligned_size =

size

;

819

x_DoCallMmap(

size

);

840  if

(aligned_ptr != mem_ptr) {

857

munmap(

static_cast<char

*

>

(ptr), aligned_size);

932

CNCMMFreeChunk::operator

new

(size_t,

void

* mem_ptr)

938

CNCMMFreeChunk::operator

delete

(

void

*,

void

*)

944

CNCMMFreeChunk::operator

delete

(

void

*)

952  for

(

CNCMMFreeChunk

* chunk =

this

; chunk != chain_end; ++chunk) {

962  for

(

CNCMMFreeChunk

* chunk = chain_start + 1; chunk != chain_end; ++chunk)

1002

CNCMMSlab::operator

delete

(

void

* mem_ptr)

1034  unsigned int

ref_cnt =

static_cast<unsigned int>

(

m_RefCnt

.

Add

(1));

1043  unsigned int

ref_cnt =

static_cast<unsigned int>

(

m_RefCnt

.

Add

(-1));

1054

TBase::Initialize();

1066 #ifdef NCBI_OS_MSWIN 1092 #ifndef NCBI_OS_MSWIN 1153  unsigned int

cnt_got = 0;

1154  while

(cnt_got == 0) {

1186  unsigned int

cnt_chunks = 0;

1196  unsigned int

cnt_on_bottom

1199

cnt_chunks += cnt_on_bottom;

1211  return sm_Getter

.GetObjPtr()->x_GetChunk();

1217  sm_Getter

.GetObjPtr()->x_PutChunk(mem_ptr);

1250  return reinterpret_cast<void

**

>

(

m_Data

);

1268  char

* block_ptr =

reinterpret_cast<char

*

>

(

m_LastFree

);

1271

*free_ptr = block_ptr;

1272

block_ptr += block_size;

1299  if

(cnt_free == 0) {

1337

CNCMMBlocksSet::operator

delete

(

void

* mem_ptr)

1394  if

(chain_index != 0 &&

m_FreeMask

.IsBitSet(chain_index - 1)) {

1399  unsigned int

next_index = chain_index + chain->

size

;

1405

&& chain_right->

size

+ chain->

size 1422  unsigned int

ref_cnt =

static_cast<unsigned int>

(

m_RefCnt

.

Add

(1));

1431  unsigned int

ref_cnt =

static_cast<unsigned int>

(

m_RefCnt

.

Add

(-1));

1442

TBase::Initialize();

1454 #ifdef NCBI_OS_MSWIN 1480 #ifndef NCBI_OS_MSWIN 1502  void

* chain =

NULL

;

1539  size_t

all_size = 0;

1553  return sm_Getter

.GetObjPtr()->x_GetChain(chain_size);

1560  sm_Getter

.GetObjPtr()->x_PutChain(mem_ptr, chain_size);

1599

list_head = chain.

start

;

1626  while

(chain_in_pool && chain_in_pool != chain.

start

) {

1629  if

(chain_in_pool) {

1640  unsigned int

chain_size = min_size;

1642  int

new_size =

m_ExistMask

.GetClosestSet(chain_size);

1643  if

(new_size == -1) {

1646

chain_size =

static_cast<unsigned int>

(new_size);

1650

chain->

size

= chain_size;

1671

chain_slab->

MarkChainFree

(chain, chain_left, chain_right);

1694  unsigned int

occupy_size)

1698

occupied.

size

= occupy_size;

1701  if

(chain.

size

!= occupy_size) {

1703

next_chain.

start

= chain.

start

+ occupy_size;

1704

next_chain.

size

= chain.

size

- occupy_size;

1712  unsigned int

max_cnt,

1721  unsigned int

cnt_chains = 0, cnt_chunks = 0;

1722  while

(max_cnt > 0 && cur_chain.

start

!=

NULL

) {

1726

saved_chain.

size

= cur_chain.

size

;

1728  unsigned int

cnt_in_chain = 0;

1729  while

(cnt_in_chain < cur_chain.size && max_cnt > 0) {

1730

*chunk_ptrs = chunk;

1737

cur_chain.

start

= next_start;

1739  if

(cur_chain.

start

) {

1758  return

chain.

start

;

1769

chain_to.

size

+= chain_from.

size

;

1794

chain.

size

= chain_size;

1797  if

(chain_left.

start

) {

1800  if

(chain_right.

start

) {

1810

chain_info.

start

= chain;

1811

chain_info.

size

= chain_size;

1821

memset(got_chains, 0,

sizeof

(got_chains));

1823  unsigned int

cnt_got = 0;

1827

chunk_ptrs, max_cnt, got_chains);

1829  unsigned int

num = 0;

1830  unsigned int

cnt_left = cnt_got;

1831  while

(cnt_left != 0) {

1833  unsigned int

occupy_size =

min

(got_chains[num].

size

, cnt_left);

1835

cnt_left -= occupy_size;

1844  for

(

unsigned int i

= 0;

i

<

cnt

; ++

i

) {

1845  for

(

unsigned int

j =

i

+ 1; j <

cnt

; ++j) {

1846  if

(chunk_ptrs[

i

] > chunk_ptrs[j])

1847  swap

(chunk_ptrs[

i

], chunk_ptrs[j]);

1862

memset(merged, 0,

sizeof

(merged));

1864  for

(

unsigned int i

= 0;

i

<

cnt

; ++

i

) {

1865

chains[

i

].

start

= chunk_ptrs[

i

];

1866

chains[

i

].

size

= 1;

1870  for

(

unsigned int i

=

cnt

- 1;

i

>= 1; --

i

) {

1871  if

(rights[

i

].start)

1873  if

(lefts[

i

].start) {

1874  if

(rights[

i

- 1].start == lefts[

i

].start) {

1877

merged[

i

] =

true

;

1882  else if

(chains[

i

- 1].start == lefts[

i

].start) {

1886

merged[

i

] =

true

;

1893  if

(rights[0].start)

1898  for

(

unsigned int i

= 0;

i

<

cnt

; ++

i

) {

1904

>= chains[

i

].start + chains[

i

].

size

);

1938

CNCMMBigBlockSet::operator

new

(size_t,

size_t

combined_size)

1942  unsigned int

chain_size = x_GetChunksCnt(combined_size);

1950

CNCMMBigBlockSet::operator

delete

(

void

* mem_ptr,

size_t

combined_size)

1952  unsigned int

chain_size = x_GetChunksCnt(combined_size);

1960

CNCMMBigBlockSet::operator

delete

(

void

* mem_ptr)

1969

: m_BlockSet(big_block_size)

1991

CNCMMBigBlockSlab::operator

new

(size_t,

size_t

big_block_size)

1998

CNCMMBigBlockSlab::operator

delete

(

void

* mem_ptr,

size_t

big_block_size)

2005

CNCMMBigBlockSlab::operator

delete

(

void

* mem_ptr)

2022  unsigned int

list_grade)

2028  else if

(list_head == bl_set) {

2041  unsigned int

list_grade)

2064

: m_SizeIndex(size_index),

2095

CNCMMSizePool::operator

new

(size_t,

void

* ptr)

2101

CNCMMSizePool::operator

delete

(

void

*,

void

*)

2108

TBase::Initialize();

2121 #ifdef NCBI_OS_MSWIN 2133  unsigned int

* index_ptr =

static_cast<unsigned int

*

>

(mem_ptr);

2135  void

* tls_obj_ptr =

static_cast<char

*

>

(mem_ptr) + 8;

2149 #ifndef NCBI_OS_MSWIN 2154  void

* mem_ptr =

static_cast<char

*

>

(obj_ptr) - 8;

2155  unsigned int

* index_ptr =

static_cast<unsigned int

*

>

(mem_ptr);

2156  unsigned int

index = *index_ptr;

2173  unsigned int

old_grade)

2176  if

(old_grade != new_grade) {

2233  void

* block = bl_set->

GetBlock

();

2272  return sm_Getter

.GetObjPtr()[index].x_AllocateBlock();

2291  if

(!mem_ptr)

return

0;

2307

mem_ptr = bl_set->

GetData

();

2344  if

(new_ptr && mem_ptr) {

2346

memcpy(new_ptr, mem_ptr,

min

(old_size, new_size));

2362  unsigned int

cnt_blocks =

static_cast<unsigned int>

(

2364  size_t

useful_mem = cnt_blocks * block_mem;

2375  unsigned int

sz_ind = 0, sz = 0, lookup_ind = 0;

2383

g_InitNCThreadIndexes();

2427  size_t

free_mem =

stats

.GetFreeMem();

2429  size_t

used_mem = sys_mem - free_mem;

2551

g_InitNCThreadIndexes();

2663 #elif !defined(NCBI_OS_MSWIN) 2671  return

NCBI_NS_NCBI::CNCMMCentral::AllocMemory(

size

);

2677

NCBI_NS_NCBI::CNCMMCentral::DeallocMemory(ptr);

2681

realloc(

void

* mem_ptr,

size_t

new_size)

2683  return

NCBI_NS_NCBI::CNCMMCentral::ReallocMemory(mem_ptr, new_size);

2689  size_t

mem_size =

size

* num;

2690  void

* mem_ptr = NCBI_NS_NCBI::CNCMMCentral::AllocMemory(mem_size);

2691

memset(mem_ptr, 0, mem_size);

Special "set of equally-sized blocks" containing only one block which size is equal to size of memory...

CNCMMBigBlockSet(size_t block_size)

Create set for the block of given size.

static unsigned int x_GetChunksCnt(size_t combined_size)

Get number of chunks necessary to fit block of given size.

void * GetData(void)

Get pointer to data of the block represented by this set.

Special memory slab representing blocks bigger than kNCMMSlabSize (or actually kNCMMMaxCombinedSize).

void * GetData(void)

Get pointer to data of the block represented by this slab.

CNCMMBigBlockSet m_BlockSet

Set for big blocks containing meta information about block.

CNCMMBigBlockSlab(size_t block_size)

Create slab for block of the given size.

Base class for set of equally-sized blocks.

size_t GetBlockSize(void)

Get size of blocks inside of this set (even if set contains only one block).

CNCMMBlocksSet * m_NextInPool

Next set in the pool's list.

size_t m_BlocksSize

Size of blocks in this set.

CNCMMSizePool * m_Pool

Pool of equally-sized blocks which this set belongs to.

unsigned int m_EmptyGrade

Emptiness grade of the set: the more blocks is occupied the less this number with 0 meaning that all ...

CNCMMBlocksSetBase(void)

Class cannot be used as standalone one.

void ** m_LastFree

Pointer to last available free block.

CNCMMBlocksSet * m_PrevInPool

Previous set in the pool's list.

Set of equally-sized blocks with size less than size of the chunk (when subtracted size of meta-data ...

void ** x_GetFirstFreePtr(void)

Get pointer to the first element in the table of free blocks.

CNCMMSizePool * GetPool(void)

Get pool of equally-sized blocks which this set belongs to.

void ReleaseBlock(void *block)

Release memory block - it's not used anymore.

void * GetBlock(void)

Get memory block not used by anyone.

unsigned int CountFreeBlocks(void)

Get number of free blocks available in the set.

CNCMMBlocksSet(CNCMMSizePool *pool, unsigned int size_index)

Create set of blocks with given size index, make set belonging to given equally-sized blocks pool.

void x_CalcEmptyGrade(void)

Recalculate emptiness grade of the set.

void SetPool(CNCMMSizePool *pool)

Set the pool this set will belong to.

char m_Data[kNCMMSetDataSize]

Actual data of the set (must be last in the class).

unsigned int GetEmptyGrade(void)

Get emptiness grade of the set.

static size_t GetMemLimit(void)

Get global limit for memory consumption.

static CNCMMStats & GetStats(void)

Get statistics collected for centrally managed operations.

static size_t GetMemorySize(void *mem_ptr)

Get size of allocated memory block.

static void * x_AlignToBottom(void *ptr)

Align memory pointer to the nearest kNCMMAlignSize boundary which is located in lower address space t...

static void * SysAlloc(size_t size)

Allocate memory from OS.

static void SysFree(void *ptr, size_t size)

Release memory to OS.

static void SetMemLimits(size_t limit, size_t alert_level)

Set global limit and alert level for memory consumption.

static void x_AllocAlignedLongWay(void *&mem_ptr, size_t size)

Long way of aligned memory allocation when OS gives non-aligned memory and we must align it by oursel...

static void * ReallocMemory(void *mem_ptr, size_t new_size)

Change allocated size of memory block to the new one.

static ENCMMMode GetMemMode(void)

Get mode of memory manager operation.

static CFastMutex sm_WaitLock

static CConditionVariable sm_WaitForStop

Semaphore allowing quick finalization of the background thread.

static bool sm_OnAlert

Flag showing that memory consumption has grown above alert level and should be lowered by all means a...

static void x_DoBackgroundWork(void)

Running method for the work that needs to be done in background.

static void x_CalcMemoryMode(const CNCMMStats &stats)

Calculate mode of working with memory (sm_Mode) based on memory usage statistics given in statistics ...

static void DeallocMemory(void *mem_ptr)

Deallocate memory block.

static size_t sm_MemLimit

Global limit of memory consumption.

static void x_Initialize(void)

Initialize memory manager.

static void PrepareToStop(void)

Prepare memory manager to stop when application finished its work.

static size_t sm_MemAlertLevel

Amount of memory consumption that should be considered dangerous.

static bool sm_Initialized

Flag showing that memory manager was already initialized.

static CThread * sm_BGThread

Background thread of memory manager.

static size_t x_AlignSizeToPage(size_t size)

Change memory size so that it contains even number of memory pages used by OS to allocate all memory.

static void * SysAllocAligned(size_t size)

Allocate aligned memory from OS.

static bool IsOnAlert(void)

Check if memory consumption is over alert limit.

static bool RunLateInit(void)

Late initialization of memory manager.

static void * x_AlignToTop(void *ptr)

Align memory pointer to the nearest kNCMMAlignSize boundary which is located in higher address space ...

static CNCMMSlab * GetSlab(void *mem_ptr)

Get memory slab containing given memory block.

static CAtomicCounter sm_CntCanAlloc

Number of memory chunks that can be allocated for database pages with current memory consumption numb...

static CNCMMMutex sm_CentralLock

Mutex controlling access to central operations.

static void * x_DoAlloc(size_t &size)

Perform the OS-dependent allocation of memory.

static size_t GetMemAlertLevel(void)

Get alert level of memory consumption.

static CNCMMStats sm_Stats

Central operations statistics.

static void * AllocMemory(size_t size)

Allocate memory block of given size.

static ENCMMMode sm_Mode

Mode of memory manager operation.

Helper class to make CNCMMChainsPool available different for each thread.

static unsigned int sm_CntUsed

Number of already used pool instances.

static CNCMMChainsPool sm_Pools[kNCMMMaxThreadsCnt]

Array of all pool instances used in manager.

static void DeleteTlsObject(void *obj_ptr)

Delete CNCMMChainsPool instance from the current thread.

CNCMMChainsPool_Getter(void)

Empty constructor to avoid any problems with some compilers.

static CNCMMMutex sm_CreateLock

Global lock managing creation and deletion of pool instances.

CNCMMChainsPool * CreateTlsObject(void)

Create instance of CNCMMChainsPool for the current thread.

void Initialize(void)

Initialize static structures of the getter and parent object.

static CNCMMChainsPool * sm_PoolPtrs[kNCMMMaxThreadsCnt]

Array of pool instances that are to be yet used.

Per-thread pool of free chains of chunks for speeding up their allocation and deallocation.

static void PutChain(void *mem_ptr, unsigned int chain_size)

Put free chunks chain of given size to the pool for future re-use.

void x_PutChain(void *mem_ptr, unsigned int chain_size)

Put chain with given size to this pool instance.

CAtomicCounter m_RefCnt

Reference counter for this object.

void * x_GetChain(unsigned int chain_size)

Get chain with given size from this pool instance.

static void * GetChain(unsigned int chain_size)

Get chain with given size (number of chunks inside the chain).

unsigned int ReleaseRef(void)

Release reference from the pool.

CNCMMChainsPool(void)

Empty constructor to avoid any problems in some compilers.

static CNCMMChainsPool_Getter sm_Getter

Getter providing pools on thread-by-thread basis.

void InitInstance(void)

Initialize the pool instance.

void x_ReleaseAllChains(void)

Transfer all chains stored to the central reserve.

CNCMMMutex m_ObjLock

Mutex protecting object using.

static void Initialize(void)

Initialize chains pooling system.

void AddRef(void)

Add reference to the pool.

void * m_FreeChains[kNCMMCntChunksInSlab+1]

List of cached chains distributed by their size.

Helper class to make CNCMMChunksPool available different for each thread.

static CNCMMChunksPool sm_Pools[kNCMMMaxThreadsCnt]

Array of all pool instances used in manager.

static CNCMMChunksPool * sm_PoolPtrs[kNCMMMaxThreadsCnt]

Array of pool instances that are to be yet used.

static CNCMMMutex sm_CreateLock

Global lock managing creation and deletion of pool instances.

void Initialize(void)

Initialize static structures of the getter and parent object.

CNCMMChunksPool * CreateTlsObject(void)

Create instance of CNCMMChunksPool for the current thread.

static void DeleteTlsObject(void *obj_ptr)

Delete CNCMMChunksPool instance from the current thread.

CNCMMChunksPool_Getter(void)

Empty constructor to avoi any problems in some compilers.

static unsigned int sm_CntUsed

Number of already used pool instances.

Per-thread pool of free chunks for speeding up allocation and deallocation of individual chunks.

void * x_GetChunk(void)

Get chunk from this pool instance.

CNCMMFreeChunk * m_Chunks[kNCMMCntChunksInPool]

Free chunks storage.

void x_PutChunk(void *mem_ptr)

Put chunk to this pool instance for re-use.

CNCMMFreeChunk ** m_PutPtr

Pointer to the place where next x_PutChunk() will put free chunk.

static CNCMMChunksPool_Getter sm_Getter

Getter providing pools on thread-by-thread basis.

CNCMMMutex m_ObjLock

Mutex protecting object using.

unsigned int ReleaseRef(void)

Release reference from the pool.

static void * GetChunk(void)

Get free memory chunk from pool.

void x_ReleaseAllChunks(void)

Transfer all chunks stored to the central reserve.

void InitInstance(void)

Initialize the pool instance.

static void PutChunk(void *mem_ptr)

Put free memory chunk to the pool for future re-use.

CNCMMFreeChunk ** m_GetPtr

Pointer to the next chunk that will be returned by x_GetChunk()

void x_RefillPool(void)

Fill empty pool with new chunks from central reserve.

CAtomicCounter m_RefCnt

Reference counter for this object.

void x_CleanPoolSpace(void)

Free some space in pool to allow new chunks to be put in there.

CNCMMChunksPool(void)

Empty constructor to avoid any problems in some compilers.

CNCMMFreeChunk ** x_AdvanceChunkPtr(CNCMMFreeChunk **chunk_ptr)

Shift pointer to chunk in the pool to next one rotating pointer to the beginning of the pool array as...

static void Initialize(void)

Initialize chunks pooling system.

void AddRef(void)

Add reference to the pool.

CNCMMFreeChunk * m_NextChain

Next chain of the same size in the chain pool.

CNCMMFreeChunk * m_ChainStart

Starting chunk in the chunks chain which this chunk is part of.

unsigned int GetSlabGrade(void)

Get emptiness grade of the slab when this chain was marked as free.

CNCMMFreeChunk * GetChainStart(void)

Get starting chunk of the chain this chunk belongs to.

CNCMMFreeChunk * m_PrevChain

Previous chain of the same size in the chain pool.

unsigned int m_SlabGrade

Emptiness grade of the slab which this chunk is part of at the time when its chain was marked as free...

unsigned int m_ChainSize

Number of chunks in the chain which this chunk is part of.

unsigned int GetChainSize(void)

Get number of chunks in the chain this chunk belongs to.

CNCMMFreeChunkBase(void)

This class cannot work as standalone one.

Representation of the free memory chunk, i.e.

static CNCMMFreeChunk * ConstructChain(void *mem_ptr, unsigned int chain_size)

Create chain of chunks which will start at memory location mem_ptr and continue for chain_size chunks...

void DestroyChain(unsigned int chain_size)

Destroy chain of chunks which starts from this chunk and continues for chain_size chunks.

void MarkChain(unsigned int chain_size, unsigned int slab_grade)

Mark the chunks chain with its data.

Central storage of all memory chunks that are not used by anybody but cannot be released to the syste...

CNCMMReserve(void)

Empty constructor to avoid any problems with some compilers.

static void x_MarkChainFree(SNCMMChainInfo *chain, SNCMMChainInfo *chain_left, SNCMMChainInfo *chain_right)

Mark given chain as free, fill information about resulted emptiness grade of the containing slab and ...

static void x_OccupyChain(const SNCMMChainInfo &chain, unsigned int need_size)

Mark whole chain or its part of need_size chunks as occupied.

static bool x_MergeChainIfValid(const SNCMMChainInfo &chain_from, SNCMMChainInfo &chain_to)

Merge 2 chains into one only if chain_from is not occupied by some other thread.

void x_InitInstance(void)

Initialize storage object.

bool x_FindFreeChain(unsigned int min_size, SNCMMChainInfo *chain)

Find free chain with size equal or greater than the given min_size.

static unsigned int GetChunks(CNCMMFreeChunk **chunk_ptrs, unsigned int max_cnt)

Get several memory chunks for use as single units.

static void x_SortChunkPtrs(CNCMMFreeChunk **chunk_ptrs, unsigned int cnt)

Sort pointers to memory chunks by the absolute value of their pointer, i.e.

static void DumpChunks(CNCMMFreeChunk **chunk_ptrs, unsigned int cnt)

Throw several memory chunks into the central storage.

static void x_CreateMergedChain(const SNCMMChainInfo &chain)

Create new chunks chain after merging.

bool UnlinkIfExist(const SNCMMChainInfo &chain)

Remove given chain of chunks from this instance of storage.

unsigned int FillChunksFromChains(CNCMMFreeChunk **chunk_ptrs, unsigned int max_cnt, SNCMMChainInfo *chain_ptrs)

Fill array of chunks with up to max_cnt chunks.

static void IntroduceChain(CNCMMFreeChunk *chain, unsigned int chain_size)

Introduce newly created chain.

CNCBitMask< kNCMMCntChunksInSlab+1 > m_ExistMask

Bit mask containing information about chain sizes that exist in the storage.

void x_Unlink(const SNCMMChainInfo &chain)

Remove given chain from the storage.

void Link(const SNCMMChainInfo &chain)

Put newly created chain of chunks into this instance of storage.

void x_MarkListIfEmpty(unsigned int list_index)

Mark list of chains with specified index if it's empty.

static CNCMMReserve sm_Instances[kNCMMSlabEmptyGrades]

Instances of storage for each value of slab's emptiness grade.

static void x_CreateNewChain(const SNCMMChainInfo &chain)

Create new chunks chain from information provided and put it into appropriate storage instance.

bool x_GetChain(unsigned int min_size, SNCMMChainInfo *chain)

Get chain with size equal or greater than given min_size.

static void x_MergeChain(const SNCMMChainInfo &chain_from, SNCMMChainInfo &chain_to)

Merge 2 chains into one.

static void * GetChain(unsigned int chain_size)

Get chain with given size (number of memory chunks inside the chain).

static void DumpChain(void *chain_ptr, unsigned int chain_size)

Throw the chain of given size into the central storage.

CNCMMFreeChunk * m_Chains[kNCMMCntChunksInSlab+1]

Lists of chains grouped by size (number of chunks in them).

static void Initialize(void)

Initialize central reserve system.

CNCMMMutex m_ObjLock

Mutex protecting access to the object.

Helper class to make CNCMMSizePool available different for each thread.

static CNCMMMutex sm_CreateLock

Global lock managing creation and deletion of pool instances.

CNCMMSizePool_Getter(void)

Empty constructor to avoid any problems with some compilers.

static void DeleteTlsObject(void *obj_ptr)

Delete CNCMMSizePool instance from the current thread.

static CNCMMSizePool * GetMainPool(unsigned int size_index)

Get pool for size with given index located in main thread.

void Initialize(void)

Initialize static structures of the getter and parent object.

static CNCMMSizePool * sm_PoolPtrs[kNCMMMaxThreadsCnt]

Array of pool instances that are used at the moment.

CNCMMSizePool * CreateTlsObject(void)

Create instance of CNCMMSizePool for the current thread.

static unsigned int sm_RefCnts[kNCMMMaxThreadsCnt]

Reference counters for each array of pools.

Per-thread pool of equally-sized memory blocks.

void x_AddSetToList(CNCMMBlocksSet *bl_set, unsigned int list_grade)

Add blocks set to the pool's list of sets with given index.

CNCBitMask< kNCMMTotalEmptyGrades > m_ExistMask

Mask for non-empty lists in m_Sets.

unsigned int m_SizeIndex

Index of blocks size located in this pool (index is from kNCMMSmallSize)

CNCMMBlocksSet * m_Sets[kNCMMTotalEmptyGrades+1]

Blocks sets distributed by their total emptiness grades.

void x_RemoveSetFromList(CNCMMBlocksSet *bl_set, unsigned int list_grade)

Remove set from the pool's list of sets with given index.

static CNCMMSizePool_Getter sm_Getter

Getter providing pools on thread-by-thread basis.

static void * AllocateBlock(size_t size)

Allocate new block with given size.

static void DeallocateBlock(void *mem_ptr, CNCMMBlocksSet *bl_set)

Deallocate block which belongs to the given blocks set.

CNCMMBlocksSet * x_GetEmptySet(void)

Get empty set from this pool (adjusting statistics accordingly) or by doing global allocation.

void * x_AllocateBlock(void)

Allocate block from this instance of blocks pool.

CNCMMSizePool(unsigned int size_index)

Create instance of blocks pool for given size index (indexes are from kNCMMSmallSize).

void x_DeallocateBlock(void *mem_ptr, CNCMMBlocksSet *bl_set)

Deallocate block belonging to given blocks set from this instance of blocks pool.

void x_NewEmptySet(CNCMMBlocksSet *bl_set, unsigned int grade)

Add just emptied blocks set with given grade before last deallocation.

CNCMMBlocksSet * m_EmptySet

Completely empty blocks set saved for speed optimization.

void x_CheckGradeChange(CNCMMBlocksSet *bl_set, unsigned int old_grade)

Check if emptiness grade of the given blocks set is changed and is different from given old value.

static void Initialize(void)

Initialize pooling system.

static CFastRWLock * sm_DestructLock

Mutex providing exclusive execution of object destructor.

CNCMMMutex m_ObjLock

Mutex protecting access to the object.

void x_AddBlocksSet(CNCMMBlocksSet *bl_set, unsigned int grade)

Add blocks set with given emptiness grade to this pool instance.

CNCBitMask< kNCMMCntChunksInSlab > m_FreeMask

Bit mask showing which chunks in the slab are free (1 - free, 0 - occupied).

unsigned int m_CntFree

Number of free chunks inside the slab.

CNCMMMutex m_ObjLock

Mutex to control access to the object.

CNCMMSlabBase(void)

Class cannot work as standalone one.

unsigned int m_EmptyGrade

Emptiness grade of the slab: the more chunks is occupied the less this number with 0 meaning that all...

Representation of the memory slab - big piece of memory containing several memory chunks.

unsigned int GetEmptyGrade(void)

Get emptiness grade of this slab.

void MarkChainFree(SNCMMChainInfo *chain, SNCMMChainInfo *chain_left, SNCMMChainInfo *chain_right)

Mark chain of memory chunks as free, put resulted emptiness grade into chain structure,...

unsigned int x_CalcEmptyGrade(void)

Calculate new emptiness grade for the slab.

unsigned int MarkChainOccupied(const SNCMMChainInfo &chain)

Mark chain of memory chunks as occupied, return emptiness grade of the slab resulted from this occupa...

CNCMMBlocksSetBase * GetBlocksSet(void *mem_ptr)

Get pointer to blocks set where given pointer belongs to.

unsigned int x_GetChunkIndex(void *mem_ptr)

Get index of the chunk where given memory pointer belongs to.

CNCMMFreeChunk m_Chunks[kNCMMCntChunksInSlab]

Data of the slab - set of chunks it consists of.

Helper class to make CNCMMStats available different for each thread.

static void DeleteTlsObject(void *obj_ptr)

Delete CNCMMStats instance from the current thread.

CNCMMStats_Getter(void)

Empty constructor to avoid any problems with some compilers.

CNCMMStats * CreateTlsObject(void)

Create instance of CNCMMStats for the current thread.

void Initialize(void)

Initialize static structures of the getter and parent object.

Per-thread statistics of memory manager operations.

Uint8 m_ChunksPoolCleans

Number of releases chunks from pool to central reserve.

static CNCMMStats_Getter sm_Getter

Getter providing statistics on thread-by-thread basis.

static void ChunksChainAlloced(size_t block_size, unsigned int chain_size)

Register allocation of chain with given number of chunks for the memory block with given size.

void Print(CPrintTextProxy &proxy)

Print all memory statistics.

CNCMMMutex m_ObjLock

Mutex controlling access to the object.

Uint8 m_BlocksAlloced[kNCMMCntSmallSizes]

Number of memory blocks allocated distributed by their size.

CNCStatFigure< size_t > m_SysMemAggr

Aggregate values of memory allocated from OS over time.

size_t m_OverheadMem

Amount of memory used by memory manager itself.

static void BlocksSetCreated(unsigned int size_index)

Register creation of new set of blocks with given size index.

static void MemBlockAlloced(unsigned int size_index)

Register allocation of memory block with size with given index.

static void CollectAllStats(CNCMMStats *stats)

Take all statistics from all threads collected at this moment and put it inside one statistics object...

Uint8 m_SlabsFreed

Number of memory slabs deallocated.

size_t m_ReservedMem

Amount of memory not used by anything but reserved in internal structures for future uses.

Uint8 m_BlocksFreed[kNCMMCntSmallSizes]

Number of memory blocks deallocated distributed by their size.

size_t m_FreeMem

Amount of free memory not used by anything.

size_t GetSystemMem(void) const

Get amount of memory allocated from OS.

Uint8 m_ChainsCentrallyAlloced

Number of chunk chains allocated from central reserve (as opposed to allocation from chains pool).

Uint8 m_ChainsAlloced[kNCMMCntChunksInSlab+1]

Number of created chunks chains distributed by their size.

Uint8 m_SysAllocs

Number of memory allocations from OS.

CNCStatFigure< size_t > m_DataMemAggr

Aggregate values of memory used by data allocated by program over time.

void x_CollectAllTo(CNCMMStats *stats)

Sum up statistics contained in this object into another object.

void InitInstance(void)

Initialize the statistics instance.

static void BigBlockAlloced(size_t block_size)

Register allocation of big block - block that doesn't fit into one memory slab.

static void BigBlockFreed(size_t block_size)

Register deallocation of big block - block that doesn't fit into one memory slab.

static void FreeChunkDeleted(void)

Register deletion of free memory chunk (i.e. CNCMMFreeChunk).

static void ChainCentrallyFreed(void)

Register deallocation of chain from central reserve (as opposed to deallocation to chains pool).

static CNCMMStats sm_Stats[kNCMMMaxThreadsCnt]

Array of all statistics instances used in manager.

void SysMemRealloced(void)

Register reallocation of system memory to align it properly.

Uint8 m_SysReallocs

Number of re-allocations of memory from OS to align it properly.

size_t m_LostMem

Amount of lost memory that won't be used by anything ever.

static void Initialize(void)

Initialize statistics subsystem.

static void OverheadMemAlloced(size_t mem_size)

Register allocation of memory needed only for manager purposes only.

size_t m_DataMem

Amount of memory used by data blocks requested by user.

static void ChunksPoolRefilled(unsigned int chunks_cnt)

Register refilling of CNCMMChunksPool with chunks_cnt new chunks from central reserve.

static void ChunksChainFreed(size_t block_size, unsigned int chain_size)

Register deallocation of chain with given number of chunks for the memory block with given size.

Uint8 m_SetsCreated[kNCMMCntSmallSizes]

Number of created blocks sets distributed by blocks size.

CNCMMStats(void)

Empty constructor to avoid any problems in some compilers.

static void SlabDeleted(void)

Register deallocation of memory slab.

Uint8 m_SysFrees

Number of releases of memory to OS.

Uint8 m_SlabsAlloced

Number of memory slabs allocated.

static void OverheadMemFreed(size_t mem_size)

Register deallocation of memory needed only for manager purposes only.

static void AggregateUsage(CNCMMStats *stats)

Same as CollectAllStats() but summarize only memory usage numbers from statistics.

static void SlabCreated(void)

Register allocation of new memory slab.

static void MemBlockFreed(unsigned int size_index)

Register deallocation of memory block with size with given index.

Uint8 m_BigFreed

Number of big memory blocks (not fitting into memory slab) deallocated.

CNCStatFigure< size_t > m_FreeMemAggr

Aggregate values of free memory over time.

static void ChunksPoolCleaned(unsigned int chunks_cnt)

Register releasing of chunks_cnt chunks from CNCMMChunksPool to the central reserve.

CNCStatFigure< size_t > m_RsrvMemAggr

Aggregate values of memory reserved in internal structures over time.

size_t GetFreeMem(void) const

Get amount of free memory not used by anything.

CNCStatFigure< size_t > m_OvrhdMemAggr

Aggregate values of memory used by memory manager over time.

Uint8 m_ChunksPoolRefills

Number of refillings of chunks pool from central reserve.

Uint8 m_SetsDeleted[kNCMMCntSmallSizes]

Number of deleted blocks sets distributed by blocks size.

Uint8 m_BigAlloced

Number of big memory blocks (not fitting into memory slab) allocated.

static void BlocksSetDeleted(unsigned int size_index)

Register deletion of set of blocks with given size index.

Uint8 m_ChainsFreed[kNCMMCntChunksInSlab+1]

Number of deleted chunks chains distributed by their size.

static void FreeChunkCreated(void)

Register creation of free memory chunk (i.e. CNCMMFreeChunk).

CNCStatFigure< size_t > m_LostMemAggr

Aggregate values of lost memory over time.

void SysMemAlloced(size_t alloced_size, size_t asked_size)

Register memory allocation from OS.

size_t m_SystemMem

Amount of memory allocated from OS.

static void ReservedMemCreated(size_t mem_size)

Register memory reservation for future use.

void SysMemFreed(size_t alloced_size, size_t asked_size)

Register memory releasing to OS.

static void ReservedMemDeleted(size_t mem_size)

Register re-use of reserved memory or its return to central storage.

static void ChainCentrallyAlloced(void)

Register allocation of chain from central reserve (as opposed to allocation from chains pool).

void AddAggregateMeasures(const CNCMMStats &stats)

Register measurement of memory usage summary for the purpose of calculating average usage values.

Uint8 m_ChainsCentrallyFreed

Number of chunk chains deallocated to central reserve (as opposed to storage in chains pool).

static void SetLimits(size_t limit, size_t alert_level)

Set maximum memory amount that process can use and amount of memory that should be considered dangero...

static size_t GetMemoryLimit(void)

Get maximum memory that can be used by NetCache.

static bool IsOnAlert(void)

Check if memory consumption is above alert level.

static bool InitializeApp(void)

Do initialization steps when application started working.

static void PrintStats(CPrintTextProxy &proxy)

Print memory usage statistics.

static size_t GetMemoryUsed(void)

Get amount of memory used by NetCache at the moment.

static void FinalizeApp(void)

Do finalization steps when application has finished.

CTimeout – Timeout interval.

void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)

TNCBIAtomicValue TValue

Alias TValue for TNCBIAtomicValue.

void Set(TValue new_value) THROWS_NONE

Set atomic counter value.

TValue Add(int delta) THROWS_NONE

Atomically add value (=delta), and return new counter value.

#define ERR_POST(message)

Error posting with file, line number information but without error codes.

void Critical(CExceptionArgs_Base &args)

#define END_NCBI_SCOPE

End previously defined NCBI scope.

#define BEGIN_NCBI_SCOPE

Define ncbi namespace.

bool Run(TRunMode flags=fRunDefault)

Run the thread.

void Lock(void)

Acquire mutex for the current thread with no nesting checks.

bool WaitForSignal(CMutex &mutex, const CDeadline &deadline=CDeadline::eInfinite)

Release mutex and lock the calling thread until the condition variable is signalled.

void SignalAll(void)

Wake all threads that are currently waiting on the condition variable.

void Join(void **exit_data=0)

Wait for the thread termination.

void Unlock(void)

Release mutex with no owner or nesting checks.

unsigned int

A callback function used to compare two keys in a database.

const struct ncbi::grid::netcache::search::fields::SIZE size

static void * s_SQLITE_Mem_Realloc(void *ptr, int new_size)

Resize memory allocated for SQLite.

static unsigned int kNCMMSmallSizeIndex[kNCMMMaxSmallSize/8+1]

List of indexes inside kNCMMSmallSize for each block size that can be requested.

static const unsigned int kNCMMChunksPerSlabGrade

Number of chunks in each slab's emptiness grade.

static sqlite3_mem_methods s_NCMallocMethods

All methods of memory management exposed to SQLite.

static const int kNCMMSQLiteBigBlockReal

The real size of big block that will be allocated for SQLite if it requests for something greater tha...

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 block...

static void * s_SQLITE_Mem_Malloc(int size)

Allocate memory for SQLite.

static const DWORD kNCVirtAllocPerm

Combination of flags used as "permission" parameter to VirtAlloc().

static const int kNCMMBGThreadWaitSecs

Frequency of background thread iterations in seconds between them.

static const DWORD kNCVirtAllocType

Combination of flags used as "type" parameter to VirtAlloc().

static CFastMutex s_CacheDeleteLock

static unsigned int kNCMMBlocksPerSet[kNCMMCntSmallSizes]

Number of blocks that fits into one blocks set for each block size.

static const size_t kNCMMMemPageSize

Size of memory page that is a granularity of all allocations from OS.

static void s_SQLITE_Mem_Shutdown(void *)

Deinitialize memory managing module for SQLite.

static const int kNCMMSQLiteBigBlockMin

"Magic" minimum size of block requested by SQLite that should be converted to allocation of maximum s...

static const unsigned int kNCMMSmallSize[kNCMMCntSmallSizes]

List of all distinct sizes of small blocks memory manager can allocate.

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 a...

static void s_SQLITE_Mem_Free(void *ptr)

Free memory allocated for SQLite.

static unsigned int kNCMMOverheadPerSet[kNCMMCntSmallSizes]

Number of bytes used by manager in each blocks set (different for each block size).

static const size_t kNCMMSizePoolArraySize

Size of CNCMMSizePool[] array containing pools for each block size that memory manager can allocate.

static unsigned int kNCMMBlocksPerGrade[kNCMMCntSmallSizes]

Number of blocks that fits into one emptiness grade of blocks set.

static const DWORD kNCVirtFreeType

Combination of flags used as "type" parameter to VirtFree().

static const size_t kNCMMDefMemoryLimit

Default global limit on memory consumption.

static unsigned int kNCMMLostPerSet[kNCMMCntSmallSizes]

Number of bytes lost at the end of blocks set for each block size.

static const size_t kNCMMLimitToleranceChunks

Number of chunks that manager allows to be used on top of global limit for memory consumption.

static int s_SQLITE_Mem_Init(void *)

Initialize memory managing module for SQLite.

static const size_t kNCMMMemPageAlignMask

Mask that can move pointer address or memory size to the memory page boundary.

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_Size(void *ptr)

Get size of memory allocated for SQLite.

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 kNCMMSetEmptyGrades

Number of emptiness grades in which all blocks sets will be divided.

ENCMMMode

Mode of operation of memory manager with regards to allocation of new memory chunks for database cach...

@ eNCFinalized

Memory manager was finalized, application will soon stop working.

@ eNCMemStable

Memory consumption should stay the same, so database cache should reuse memory from old pages.

@ eNCMemGrowing

New memory chunks can be allocated for database cache without limits.

static const size_t kNCMMSetBaseSize

Size of the blocks set meta-data.

static const size_t kNCMMChunkSize

Size of memory chunks - minimum piece of memory operated by manager.

static const unsigned int kNCMMCntChunksInSlab

Number of memory chunks that will fit inside one slab.

static const unsigned int kNCMMMaxThreadsCnt

Maximum number of threads when manager is the most effective in avoiding contention between threads f...

static const unsigned int kNCMMCntSmallSizes

Number of distinct sizes (below size of memory chunk) that memory manager can allocate.

static const size_t kNCMMMaxCombinedSize

Maximum size of allocated block that can be achieved by combining several memory chunks together.

static const size_t kNCMMSetDataSize

Size of the real data part inside blocks set.

static const unsigned int kNCMMCntChunksInPool

Number of chunks stored in chunks pool to speed up requests for free chunks.

static const size_t kNCMMSlabSize

Size of memory slab - the minimum piece of memory allocated from system.

static const size_t kNCMMBlockExtraSize

Size of extra-information stored in the set for each block in addition to overall set meta-data.

static const unsigned int kNCMMSlabEmptyGrades

Number of emptiness grades in which all slabs will be divided.

static const size_t kNCMMAlignMask

Mask to get aligned memory address from arbitrary memory address.

static const unsigned int kNCMMTotalEmptyGrades

Total number of emptiness grades that blocks sets will have.

static const size_t kNCMMAlignSize

Alignment boundary to which manager will align all memory allocated from system.

std::enable_if< std::is_unsigned< T >::value, string >::type g_ToSizeStr(T size)

string g_ToSmartStr(T num)

Helper structure used to transfer information about free chunks chains between different classes.

void Initialize(void)

Initialize data with zeros.

void AssignFromChain(CNCMMFreeChunk *chain)

Copy information about chain from the chain itself.

unsigned int size

Number of chunks in the chain.

CNCMMFreeChunk * start

Starting chunk of the chain.

unsigned int slab_grade

Emptiness grade of the slab where chain is located.

voidp calloc(uInt items, uInt size)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4