|
The Pedigree Project 0.1
|
#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. | |
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.
| MemoryPool::MemoryPool | ( | ) |
Definition at line 77 of file MemoryPool.cc.
| MemoryPool::MemoryPool | ( | const char * | poolName | ) |
Definition at line 95 of file MemoryPool.cc.
|
virtual |
Definition at line 113 of file MemoryPool.cc.
| 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().
|
private |
Allocation doer.
Definition at line 231 of file MemoryPool.cc.
References LockGuard< T >::disown(), ExtensibleBitmap::getFirstClear(), PhysicalMemoryManager::getPageSize(), m_AllocBitmap, m_bInitialised, m_BufferCount, m_BufferSize, m_Pool, ConditionVariable::mutexAcquired(), ExtensibleBitmap::set(), MemoryRegion::size(), MemoryRegion::virtualAddress(), and ConditionVariable::wait().
Referenced by allocate(), and allocateNow().
Here is the caller graph for this function:| uintptr_t MemoryPool::allocateNow | ( | ) |
Allocates a buffer from the pool. If no buffers are available, this function will return straight away.
Definition at line 227 of file MemoryPool.cc.
References allocateDoer().
|
private |
Definition at line 143 of file MemoryPool.cc.
|
private |
Definition at line 155 of file MemoryPool.cc.
| 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:| bool MemoryPool::initialise | ( | size_t | poolSize, |
| size_t | bufferSize = 1024 |
||
| ) |
Initialises the pool, preparing it for use
| poolSize | Number of pages in the pool. |
| bufferSize | Size of each buffer. Will be rounded to the next power of two. |
Definition at line 168 of file MemoryPool.cc.
References PhysicalMemoryManager::allocateRegion(), Dec, PhysicalMemoryManager::getPageSize(), Hex, PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, m_bClosing, m_bInitialised, m_BufferCount, m_BufferSize, m_Pool, m_PressureHandler, MemoryRegion::name(), MemoryPressureManager::registerHandler(), MemoryRegion::size(), PhysicalMemoryManager::virtualOnly, and VirtualAddressSpace::Write.
|
inline |
Call if you aren't certain that the object has been initialised yet.
Definition at line 73 of file MemoryPool.h.
| 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:
|
private |
Operations which entered before destruction began.
Definition at line 147 of file MemoryPool.h.
|
private |
Allocation bitmap.
Definition at line 150 of file MemoryPool.h.
Referenced by allocateDoer(), free(), and trim().
|
private |
Destruction has begun; no new operations may enter.
Definition at line 144 of file MemoryPool.h.
Referenced by free(), initialise(), and trim().
|
private |
Has this instance been initialised yet?
Definition at line 141 of file MemoryPool.h.
Referenced by allocateDoer(), free(), initialise(), and trim().
|
private |
Number of buffers we have available.
Definition at line 133 of file MemoryPool.h.
Referenced by allocateDoer(), free(), and initialise().
|
private |
Size of each buffer in this pool.
Definition at line 130 of file MemoryPool.h.
Referenced by allocateDoer(), free(), initialise(), and trim().
|
private |
Definition at line 103 of file MemoryPool.h.
|
private |
Definition at line 104 of file MemoryPool.h.
|
private |
Definition at line 105 of file MemoryPool.h.
|
private |
Definition at line 106 of file MemoryPool.h.
|
private |
MemoryRegion describing the actual pool of memory.
Definition at line 137 of file MemoryPool.h.
Referenced by allocateDoer(), free(), initialise(), and trim().
|
private |
Memory pressure handler for this pool.
Definition at line 154 of file MemoryPool.h.
Referenced by initialise().