From 60516e3915e5f5854e8c0286252fae49f63060af Mon Sep 17 00:00:00 2001 From: Alja Mrak-Tadel Date: Thu, 9 Jul 2015 13:18:28 -0700 Subject: [PATCH] Reserver ram resources in prefetching. --- src/XrdFileCache/XrdFileCache.cc | 39 +++++++++++++++------------- src/XrdFileCache/XrdFileCacheFile.cc | 7 ++++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/XrdFileCache/XrdFileCache.cc b/src/XrdFileCache/XrdFileCache.cc index b2b678240c0..1a3ad8bf9fe 100644 --- a/src/XrdFileCache/XrdFileCache.cc +++ b/src/XrdFileCache/XrdFileCache.cc @@ -217,15 +217,8 @@ Cache::RegisterPrefetchFile(File* file) if (Factory::GetInstance().RefConfiguration().m_prefetch) { - if (Factory::GetInstance().RefConfiguration().m_hdfsmode) { XrdSysMutexHelper lock(&m_prefetch_mutex); m_files.push_back(file); - } - else - { - // don't need to lock it becuse it File object is created in constructor of IOEntireFile - m_files.push_back(file); - } } } //______________________________________________________________________________ @@ -266,18 +259,28 @@ Cache::GetNextFileToPrefetch() void Cache::Prefetch() { + const static int limitRAM= Factory::GetInstance().RefConfiguration().m_NRamBuffers * 0.7; + XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::Prefetch thread start"); - - while (true) { - File* f = GetNextFileToPrefetch(); - XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::Prefetch got file (%p)", f); - if (f) { - f->Prefetch(); - } - else { - // wait for new file, AMT should I wait for the signal instead ??? - XrdSysTimer::Wait(1); + while (true) { + bool doPrefetch = false; + m_RAMblock_mutex.Lock(); + if (m_RAMblocks_used < limitRAM) + doPrefetch = true; + m_RAMblock_mutex.UnLock(); + + if (doPrefetch) { + File* f = GetNextFileToPrefetch(); + XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::Prefetch got file (%p)", f); + if (f) { + f->Prefetch(); + continue; + } } - } + + // wait for new file or more resources, AMT should I wait for the signal instead ??? + XrdSysTimer::Wait(1); + + } } diff --git a/src/XrdFileCache/XrdFileCacheFile.cc b/src/XrdFileCache/XrdFileCacheFile.cc index b2bbd832639..9be06a3f979 100644 --- a/src/XrdFileCache/XrdFileCacheFile.cc +++ b/src/XrdFileCache/XrdFileCacheFile.cc @@ -720,6 +720,7 @@ void File::dec_ref_count(Block* b) b-> m_refcnt--; if ( b->m_refcnt == 0) { int i = b->m_offset/BufferSize(); + delete m_block_map[i]; size_t ret = m_block_map.erase(i); if (ret != 1) { clLog()->Error(XrdCl::AppMsg, "File::OnBlockZeroRefCount did not erase %d from map.", i); @@ -765,7 +766,10 @@ void File::ProcessBlockResponse(Block* b, XrdCl::XRootDStatus *status) // case when there is a prefetch that is failed or prefetch that stopped has just been initated if (b->m_refcnt == 0) { assert(b->m_prefetch); - m_block_map.erase((int)(b->m_offset/BufferSize())); + cache()->RAMBlockReleased(); + int bidx = (int)(b->m_offset/BufferSize()); + delete m_block_map[bidx]; + m_block_map.erase(bidx); } @@ -841,6 +845,7 @@ void File::Prefetch() BlockMap_i bi = m_block_map.find(f); if (bi == m_block_map.end()) { clLog()->Dump(XrdCl::AppMsg, "Prefetch::Prefetch take block %d", f); + cache()->RequestRAMBlock(); RequestBlock(f, true); /// inc_ref_count(b); AMT don't increase it, there is no-one to annulate it 0 m_prefetchReadCnt++;