The Pedigree Project 0.1
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MemoryPool Class Reference

#include <MemoryPool.h>

+ Collaboration diagram for MemoryPool:

Classes

class  ActiveOperation
 

Public Member Functions

 MemoryPool (const char *poolName)
 
bool initialise (size_t poolSize, size_t bufferSize=1024)
 
bool initialised ()
 Call if you aren't certain that the object has been initialised yet.
 
uintptr_t allocate ()
 
uintptr_t allocateNow ()
 
void free (uintptr_t buffer)
 Frees an allocated buffer, allowing it to be used elsewhere.
 
bool trim ()
 Trims the pool, freeing pages that are not otherwise in use.
 

Private Member Functions

bool beginOperation ()
 
void endOperation ()
 
uintptr_t allocateDoer (bool canBlock)
 Allocation doer.
 

Private Attributes

ConditionVariable m_Condition
 
ConditionVariable m_DrainCondition
 
Mutex m_Lock
 
Mutex m_MappingLock
 
size_t m_BufferSize
 Size of each buffer in this pool.
 
size_t m_BufferCount
 Number of buffers we have available.
 
MemoryRegion m_Pool
 MemoryRegion describing the actual pool of memory.
 
bool m_bInitialised
 Has this instance been initialised yet?
 
bool m_bClosing
 Destruction has begun; no new operations may enter.
 
size_t m_ActiveOperations
 Operations which entered before destruction began.
 
ExtensibleBitmap m_AllocBitmap
 Allocation bitmap.
 
MemoryPoolPressureHandler m_PressureHandler
 Memory pressure handler for this pool.
 

Detailed Description

MemoryPool - a class which encapsulates a pool of memory with constant sized buffers that can be allocated around the kernel. Intended to be used instead of the heap for areas where similar sized buffers are regularly allocated, such as networking code.

Definition at line 60 of file MemoryPool.h.

Constructor & Destructor Documentation

◆ MemoryPool() [1/2]

MemoryPool::MemoryPool ( )

Definition at line 77 of file MemoryPool.cc.

◆ MemoryPool() [2/2]

MemoryPool::MemoryPool ( const char *  poolName)

Definition at line 95 of file MemoryPool.cc.

◆ ~MemoryPool()

MemoryPool::~MemoryPool ( )
virtual

Definition at line 113 of file MemoryPool.cc.

Member Function Documentation

◆ allocate()

uintptr_t MemoryPool::allocate ( )

Allocates a buffer from the pool. Will block if no buffers are available yet.

Definition at line 223 of file MemoryPool.cc.

References allocateDoer().

◆ allocateDoer()

uintptr_t MemoryPool::allocateDoer ( bool  canBlock)
private

◆ allocateNow()

uintptr_t MemoryPool::allocateNow ( )

Allocates a buffer from the pool. If no buffers are available, this function will return straight away.

Returns
Zero if a buffer couldn't be allocated.

Definition at line 227 of file MemoryPool.cc.

References allocateDoer().

◆ beginOperation()

bool MemoryPool::beginOperation ( )
private

Definition at line 143 of file MemoryPool.cc.

◆ endOperation()

void MemoryPool::endOperation ( )
private

Definition at line 155 of file MemoryPool.cc.

◆ free()

void MemoryPool::free ( uintptr_t  buffer)

Frees an allocated buffer, allowing it to be used elsewhere.

Definition at line 299 of file MemoryPool.cc.

References ExtensibleBitmap::clear(), m_AllocBitmap, m_bClosing, m_bInitialised, m_BufferCount, m_BufferSize, m_Pool, ConditionVariable::signal(), MemoryRegion::size(), ExtensibleBitmap::test(), and MemoryRegion::virtualAddress().

Referenced by Ipc::IpcMessage::~IpcMessage().

+ Here is the caller graph for this function:

◆ initialise()

bool MemoryPool::initialise ( size_t  poolSize,
size_t  bufferSize = 1024 
)

◆ initialised()

bool MemoryPool::initialised ( )
inline

Call if you aren't certain that the object has been initialised yet.

Definition at line 73 of file MemoryPool.h.

◆ trim()

bool MemoryPool::trim ( )

Trims the pool, freeing pages that are not otherwise in use.

Definition at line 332 of file MemoryPool.cc.

References PhysicalMemoryManager::getPageSize(), m_AllocBitmap, m_bClosing, m_bInitialised, m_BufferSize, m_Pool, Semaphore::release(), MemoryRegion::size(), ExtensibleBitmap::test(), Semaphore::tryAcquire(), and MemoryRegion::virtualAddress().

Referenced by MemoryPoolPressureHandler::compact().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_ActiveOperations

size_t MemoryPool::m_ActiveOperations
private

Operations which entered before destruction began.

Definition at line 147 of file MemoryPool.h.

◆ m_AllocBitmap

ExtensibleBitmap MemoryPool::m_AllocBitmap
private

Allocation bitmap.

Definition at line 150 of file MemoryPool.h.

Referenced by allocateDoer(), free(), and trim().

◆ m_bClosing

bool MemoryPool::m_bClosing
private

Destruction has begun; no new operations may enter.

Definition at line 144 of file MemoryPool.h.

Referenced by free(), initialise(), and trim().

◆ m_bInitialised

bool MemoryPool::m_bInitialised
private

Has this instance been initialised yet?

Definition at line 141 of file MemoryPool.h.

Referenced by allocateDoer(), free(), initialise(), and trim().

◆ m_BufferCount

size_t MemoryPool::m_BufferCount
private

Number of buffers we have available.

Definition at line 133 of file MemoryPool.h.

Referenced by allocateDoer(), free(), and initialise().

◆ m_BufferSize

size_t MemoryPool::m_BufferSize
private

Size of each buffer in this pool.

Definition at line 130 of file MemoryPool.h.

Referenced by allocateDoer(), free(), initialise(), and trim().

◆ m_Condition

ConditionVariable MemoryPool::m_Condition
private

Definition at line 103 of file MemoryPool.h.

◆ m_DrainCondition

ConditionVariable MemoryPool::m_DrainCondition
private

Definition at line 104 of file MemoryPool.h.

◆ m_Lock

Mutex MemoryPool::m_Lock
private

Definition at line 105 of file MemoryPool.h.

◆ m_MappingLock

Mutex MemoryPool::m_MappingLock
private

Definition at line 106 of file MemoryPool.h.

◆ m_Pool

MemoryRegion MemoryPool::m_Pool
private

MemoryRegion describing the actual pool of memory.

Definition at line 137 of file MemoryPool.h.

Referenced by allocateDoer(), free(), initialise(), and trim().

◆ m_PressureHandler

MemoryPoolPressureHandler MemoryPool::m_PressureHandler
private

Memory pressure handler for this pool.

Definition at line 154 of file MemoryPool.h.

Referenced by initialise().


The documentation for this class was generated from the following files: