Riferimenti per il file balloc.c

A block allocator. Continua...

#include "stdinc.h"
#include "ircd.h"
#include "balloc.h"
#include "irc_string.h"
#include "tools.h"
#include "client.h"
#include "send.h"
#include "numeric.h"
#include "fdlist.h"
#include "event.h"

Vai al codice sorgente di questo file.

Funzioni

static int BlockHeapGarbageCollect (BlockHeap *bh)
 Performs garbage collection on the block heap.
static void heap_garbage_collection (void *)
static void free_block (void *ptr, size_t size)
 Returns memory for the block back to either the malloc heap in case of !HAVE_MMAP, or back to the OS otherwise.
void initBlockHeap (void)
 Opens /dev/zero and saves the file handle for future allocations.
static void * get_block (size_t size)
static int newblock (BlockHeap *bh)
 Allocates a new block for addition to a blockheap.
BlockHeapBlockHeapCreate (const char *const name, size_t elemsize, int elemsperblock)
 Creates a new blockheap.
void * BlockHeapAlloc (BlockHeap *bh)
 Returns a pointer to a struct within our BlockHeap that's free for the taking.
int BlockHeapFree (BlockHeap *bh, void *ptr)
 Returns an element to the free pool, does not free().
int BlockHeapDestroy (BlockHeap *bh)
 Completely free()s a BlockHeap. Use for cleanup.
static size_t block_heap_get_used_mem (const BlockHeap *const bh)
 Returns the number of bytes being used.
static size_t block_heap_get_free_mem (const BlockHeap *const bh)
 Returns the number of bytes being free for further allocations.
static size_t block_heap_get_size_mem (const BlockHeap *const bh)
 Returns the total number of bytes of memory belonging to a heap.
static unsigned int block_heap_get_used_elm (const BlockHeap *const bh)
 Returns the number of elements being used.
static unsigned int block_heap_get_free_elm (const BlockHeap *const bh)
 Returns the number of elements being free for further allocations.
static unsigned int block_heap_get_size_elm (const BlockHeap *const bh)
 Returns the number of total elements belonging to a heap. Includes free and used elements.
void block_heap_report_stats (struct Client *client_p)

Variabili

static BlockHeapheap_list = NULL


Descrizione dettagliata

A block allocator.

Versione:
Id
balloc.c 670 2006-06-12 12:20:55Z michael

About the block allocator

Basically we have three ways of getting memory off of the operating system. Below are this list of methods and the order of preference.

1. mmap() anonymous pages with the MMAP_ANON flag.
2. mmap() via the /dev/zero trick.
3. malloc()

The advantages of 1 and 2 are this. We can munmap() the pages which will return the pages back to the operating system, thus reducing the size of the process as the memory is unused. malloc() on many systems just keeps a heap of memory to itself, which never gets given back to the OS, except on exit. This of course is bad, if say we have an event that causes us to allocate say, 200MB of memory, while our normal memory consumption would be 15MB. In the malloc() case, the amount of memory allocated to our process never goes down, as malloc() has it locked up in its heap. With the mmap() method, we can munmap() the block and return it back to the OS, thus causing our memory consumption to go down after we no longer need it.

Definizione nel file balloc.c.


Documentazione delle funzioni

static unsigned int block_heap_get_free_elm ( const BlockHeap *const   bh  )  [static]

Returns the number of elements being free for further allocations.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Number of elements being free for further allocations

Definizione alla linea 474 del file balloc.c.

Riferimenti BlockHeap::freeElems.

Referenziato da block_heap_report_stats().

static size_t block_heap_get_free_mem ( const BlockHeap *const   bh  )  [static]

Returns the number of bytes being free for further allocations.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Number of bytes being free for further allocations

Definizione alla linea 441 del file balloc.c.

Riferimenti BlockHeap::elemSize, e BlockHeap::freeElems.

Referenziato da block_heap_report_stats().

static unsigned int block_heap_get_size_elm ( const BlockHeap *const   bh  )  [static]

Returns the number of total elements belonging to a heap. Includes free and used elements.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Number of total elements belonging to a heap

Definizione alla linea 485 del file balloc.c.

Riferimenti BlockHeap::blocksAllocated, e BlockHeap::elemsPerBlock.

Referenziato da block_heap_report_stats().

static size_t block_heap_get_size_mem ( const BlockHeap *const   bh  )  [static]

Returns the total number of bytes of memory belonging to a heap.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Total number of bytes of memory belonging to a heap

Definizione alla linea 451 del file balloc.c.

Riferimenti BlockHeap::blocksAllocated, BlockHeap::elemSize, e BlockHeap::elemsPerBlock.

Referenziato da block_heap_report_stats().

static unsigned int block_heap_get_used_elm ( const BlockHeap *const   bh  )  [static]

Returns the number of elements being used.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Number of elements being free for further allocations

Definizione alla linea 463 del file balloc.c.

Riferimenti BlockHeap::blocksAllocated, BlockHeap::elemsPerBlock, e BlockHeap::freeElems.

Referenziato da block_heap_report_stats().

static size_t block_heap_get_used_mem ( const BlockHeap *const   bh  )  [static]

Returns the number of bytes being used.

Parametri:
bh Pointer to a BlockHeap
Restituisce:
Number of bytes being used

Definizione alla linea 429 del file balloc.c.

Riferimenti BlockHeap::blocksAllocated, BlockHeap::elemSize, BlockHeap::elemsPerBlock, e BlockHeap::freeElems.

Referenziato da block_heap_report_stats().

void block_heap_report_stats ( struct Client client_p  ) 

void* BlockHeapAlloc ( BlockHeap bh  ) 

Returns a pointer to a struct within our BlockHeap that's free for the taking.

Parametri:
bh Pointer to the Blockheap
Restituisce:
Address pointer to allocated data space, or NULL if unsuccessful

Definizione alla linea 258 del file balloc.c.

Riferimenti BlockHeap::base, BlockHeapGarbageCollect(), _dlink_node::data, dlinkDelete(), BlockHeap::elemSize, Block::free_list, Block::freeElems, BlockHeap::freeElems, _dlink_list::head, newblock(), Block::next, e outofmemory().

Referenziato da add_id(), add_user_host(), add_user_to_channel(), allocate_topic(), dbuf_alloc(), find_or_add_ip(), find_or_add_userhost(), make_channel(), make_client(), e make_dlink_node().

BlockHeap* BlockHeapCreate ( const char *const   name,
size_t  elemsize,
int  elemsperblock 
)

Creates a new blockheap.

Creates a new blockheap from which smaller blocks can be allocated. Intended to be used instead of multiple calls to malloc() when performance is an issue.

Parametri:
name Name of the blockheap
elemsize Size of the basic element to be stored
elemsperblock Number of elements to be stored in a single block of memory. When the blockheap runs out of free memory, it will allocate elemsize * elemsperblock more.
Restituisce:
Pointer to new BlockHeap, or NULL if unsuccessful

Definizione alla linea 211 del file balloc.c.

Riferimenti BlockHeap::elemSize, BlockHeap::elemsPerBlock, BlockHeap::name, newblock(), BlockHeap::next, e outofmemory().

Referenziato da dbuf_init(), init_channels(), init_client(), init_dlink_nodes(), init_hash(), e init_ip_hash_table().

int BlockHeapDestroy ( BlockHeap bh  ) 

Completely free()s a BlockHeap. Use for cleanup.

Parametri:
bh Pointer to the BlockHeap to be destroyed
Restituisce:
0 if successful, 1 if bh == NULL

Definizione alla linea 394 del file balloc.c.

Riferimenti Block::alloc_size, BlockHeap::base, Block::elems, free_block(), BlockHeap::next, e Block::next.

int BlockHeapFree ( BlockHeap bh,
void *  ptr 
)

Returns an element to the free pool, does not free().

Parametri:
bh Pointer to BlockHeap containing element
ptr Pointer to element to be "freed"
Restituisce:
0 if successful, 1 if element not contained within BlockHeap

Definizione alla linea 306 del file balloc.c.

Riferimenti MemBlock::block, dlinkAdd(), BlockHeap::elemSize, Block::free_list, Block::freeElems, BlockHeap::freeElems, mem_frob, outofmemory(), e MemBlock::self.

Referenziato da dbuf_delete(), delete_user_host(), destroy_channel(), free_client(), free_dlink_node(), free_topic(), garbage_collect_ip_entries(), remove_ban(), remove_one_ip(), e remove_user_from_channel().

static int BlockHeapGarbageCollect ( BlockHeap bh  )  [static]

Performs garbage collection on the block heap.

Performs garbage collection on the block heap. Any blocks that are completely unallocated are removed from the heap. Garbage collection will never remove the root node of the heap.

Parametri:
bh Pointer to the BlockHeap to be cleaned up
Restituisce:
0 if successful, 1 if bh == NULL

Definizione alla linea 339 del file balloc.c.

Riferimenti Block::alloc_size, BlockHeap::base, BlockHeap::blocksAllocated, Block::elems, BlockHeap::elemsPerBlock, free_block(), Block::freeElems, BlockHeap::freeElems, e Block::next.

Referenziato da BlockHeapAlloc(), e heap_garbage_collection().

static void free_block ( void *  ptr,
size_t  size 
) [inline, static]

Returns memory for the block back to either the malloc heap in case of !HAVE_MMAP, or back to the OS otherwise.

Parametri:
ptr Pointer to memory to be freed
size The size of the memory space

Definizione alla linea 87 del file balloc.c.

Referenziato da BlockHeapDestroy(), e BlockHeapGarbageCollect().

static void* get_block ( size_t  size  )  [inline, static]

Parametri:
size Size of block to allocate
Restituisce:
Address pointer to allocated data space

Definizione alla linea 126 del file balloc.c.

Riferimenti _fde::fd.

Referenziato da newblock().

static void heap_garbage_collection ( void *  arg  )  [static]

Definizione alla linea 143 del file balloc.c.

Riferimenti BlockHeapGarbageCollect(), e BlockHeap::next.

Referenziato da initBlockHeap().

void initBlockHeap ( void   ) 

Opens /dev/zero and saves the file handle for future allocations.

Definizione alla linea 107 del file balloc.c.

Riferimenti eventAdd(), fd_open(), heap_garbage_collection(), e outofmemory().

Referenziato da main().

static int newblock ( BlockHeap bh  )  [static]

Allocates a new block for addition to a blockheap.

Parametri:
bh Pointer to parent blockheap
Restituisce:
0 if successful, 1 if not

Definizione alla linea 156 del file balloc.c.

Riferimenti Block::alloc_size, BlockHeap::base, MemBlock::block, BlockHeap::blocksAllocated, dlinkAdd(), Block::elems, BlockHeap::elemSize, BlockHeap::elemsPerBlock, Block::free_list, BlockHeap::freeElems, Block::freeElems, get_block(), Block::next, e MemBlock::self.

Referenziato da BlockHeapAlloc(), e BlockHeapCreate().


Documentazione delle variabili

BlockHeap* heap_list = NULL [static]

Definizione alla linea 76 del file balloc.c.


Generato il Wed Apr 15 00:19:20 2009 per ircd-hybrid da  doxygen 1.5.6