diff options
-rw-r--r-- | indra/llcommon/llmemory.cpp | 70 | ||||
-rw-r--r-- | indra/llcommon/llmemory.h | 23 | ||||
-rw-r--r-- | indra/llimage/llimage.cpp | 4 |
3 files changed, 65 insertions, 32 deletions
diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp index 1414ac7b9e..062640f546 100644 --- a/indra/llcommon/llmemory.cpp +++ b/indra/llcommon/llmemory.cpp @@ -1263,13 +1263,16 @@ U16 LLPrivateMemoryPool::LLMemoryChunk::getPageLevel(U32 size) //-------------------------------------------------------------------- const U32 CHUNK_SIZE = 4 << 20 ; //4 MB const U32 LARGE_CHUNK_SIZE = 4 * CHUNK_SIZE ; //16 MB -LLPrivateMemoryPool::LLPrivateMemoryPool(U32 max_size, bool threaded) : - mMutexp(NULL), - mMaxPoolSize(max_size), +LLPrivateMemoryPool::LLPrivateMemoryPool(S32 type) : + mMutexp(NULL), mReservedPoolSize(0), - mHashFactor(1) + mHashFactor(1), + mType(type) { - if(threaded) + const U32 MAX_POOL_SIZE = 256 * 1024 * 1024 ; //256 MB + + mMaxPoolSize = MAX_POOL_SIZE ; + if(type == STATIC_THREADED || type == VOLATILE_THREADED) { mMutexp = new LLMutex ; } @@ -1735,22 +1738,35 @@ LLPrivateMemoryPoolManager* LLPrivateMemoryPoolManager::sInstance = NULL ; LLPrivateMemoryPoolManager::LLPrivateMemoryPoolManager() { + mPoolList.resize(LLPrivateMemoryPool::MAX_TYPES) ; + + for(S32 i = 0 ; i < LLPrivateMemoryPool::MAX_TYPES; i++) + { + mPoolList[i] = NULL ; + } } LLPrivateMemoryPoolManager::~LLPrivateMemoryPoolManager() { +#if 0 //all private pools should be released by their owners before reaching here. - llassert_always(mPoolList.empty()) ; + for(S32 i = 0 ; i < LLPrivateMemoryPool::MAX_TYPES; i++) + { + llassert_always(!mPoolList[i]) ; + } + mPoolList.clear() ; -#if 0 - if(!mPoolList.empty()) +#else + //forcefully release all memory + for(S32 i = 0 ; i < LLPrivateMemoryPool::MAX_TYPES; i++) { - for(std::set<LLPrivateMemoryPool*>::iterator iter = mPoolList.begin(); iter != mPoolList.end(); ++iter) + if(mPoolList[i]) { - delete *iter; + delete mPoolList[i] ; + mPoolList[i] = NULL ; } - mPoolList.clear() ; } + mPoolList.clear() ; #endif } @@ -1774,18 +1790,23 @@ void LLPrivateMemoryPoolManager::destroyClass() } } -LLPrivateMemoryPool* LLPrivateMemoryPoolManager::newPool(U32 max_size, bool threaded) +LLPrivateMemoryPool* LLPrivateMemoryPoolManager::newPool(S32 type) { - LLPrivateMemoryPool* pool = new LLPrivateMemoryPool(max_size, threaded) ; - mPoolList.insert(pool) ; + if(!mPoolList[type]) + { + mPoolList[type] = new LLPrivateMemoryPool(type) ; + } - return pool ; + return mPoolList[type] ; } void LLPrivateMemoryPoolManager::deletePool(LLPrivateMemoryPool* pool) { - mPoolList.erase(pool) ; - delete pool; + if(pool->isEmpty()) + { + mPoolList[pool->getType()] = NULL ; + delete pool; + } } //debug @@ -1794,10 +1815,13 @@ void LLPrivateMemoryPoolManager::updateStatistics() mTotalReservedSize = 0 ; mTotalAllocatedSize = 0 ; - for(std::set<LLPrivateMemoryPool*>::iterator iter = mPoolList.begin(); iter != mPoolList.end(); ++iter) + for(U32 i = 0; i < mPoolList.size(); i++) { - mTotalReservedSize += (*iter)->getTotalReservedSize() ; - mTotalAllocatedSize += (*iter)->getTotalAllocatedSize() ; + if(mPoolList[i]) + { + mTotalReservedSize += mPoolList[i]->getTotalReservedSize() ; + mTotalAllocatedSize += mPoolList[i]->getTotalAllocatedSize() ; + } } } @@ -1840,15 +1864,13 @@ void LLPrivateMemoryPoolTester::destroy() } } -void LLPrivateMemoryPoolTester::run(bool threaded) +void LLPrivateMemoryPoolTester::run(S32 type) { - const U32 max_pool_size = 1024 << 20 ; - if(sPool) { LLPrivateMemoryPoolManager::getInstance()->deletePool(sPool) ; } - sPool = LLPrivateMemoryPoolManager::getInstance()->newPool(max_pool_size, threaded) ; + sPool = LLPrivateMemoryPoolManager::getInstance()->newPool(type) ; //run the test correctnessTest() ; diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 4474df6f86..a5dbabec5a 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -231,7 +231,7 @@ public: } ; private: - LLPrivateMemoryPool(U32 max_size, bool threaded) ; + LLPrivateMemoryPool(S32 type) ; ~LLPrivateMemoryPool() ; public: @@ -241,7 +241,9 @@ public: void dump() ; U32 getTotalAllocatedSize() ; U32 getTotalReservedSize() {return mReservedPoolSize;} - + S32 getType() const {return mType; } + bool isEmpty() const {return !mNumOfChunks; } + private: void lock() ; void unlock() ; @@ -267,6 +269,15 @@ public: SUPER_ALLOCATION //allocation larger than 4MB. }; + enum + { + STATIC = 0 , //static pool(each alllocation stays for a long time) without threading support + VOLATILE, //Volatile pool(each allocation stays for a very short time) without threading support + STATIC_THREADED, //static pool with threading support + VOLATILE_THREADED, //volatile pool with threading support + MAX_TYPES + }; //pool types + private: LLMutex* mMutexp ; U32 mMaxPoolSize; @@ -276,6 +287,8 @@ private: std::vector<LLMemoryChunk*> mChunkHashList ; U16 mNumOfChunks ; U16 mHashFactor ; + + S32 mType ; }; class LL_COMMON_API LLPrivateMemoryPoolManager @@ -288,12 +301,12 @@ public: static LLPrivateMemoryPoolManager* getInstance() ; static void destroyClass() ; - LLPrivateMemoryPool* newPool(U32 max_size, bool threaded) ; + LLPrivateMemoryPool* newPool(S32 type) ; void deletePool(LLPrivateMemoryPool* pool) ; private: static LLPrivateMemoryPoolManager* sInstance ; - std::set<LLPrivateMemoryPool*> mPoolList ; + std::vector<LLPrivateMemoryPool*> mPoolList ; public: //debug and statistics info. @@ -316,7 +329,7 @@ public: static LLPrivateMemoryPoolTester* getInstance() ; static void destroy() ; - void run(bool threaded) ; + void run(S32 type) ; private: void correctnessTest() ; diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 706231307d..9298716022 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -106,11 +106,9 @@ LLImageBase::~LLImageBase() //static void LLImageBase::createPrivatePool() { - const U32 MAX_POOL_SIZE = 512 * 1024 * 1024 ; //512 MB - if(!sPrivatePoolp) { - sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(MAX_POOL_SIZE, true) ; + sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC_THREADED) ; } } |