Skip to content

Commit

Permalink
Reserver ram resources in prefetching.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent 3075975 commit c1bba02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
39 changes: 21 additions & 18 deletions src/XrdFileCache/XrdFileCache.cc
Expand Up @@ -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);
}
}
}
//______________________________________________________________________________
Expand Down Expand Up @@ -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);

}
}
7 changes: 6 additions & 1 deletion src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit c1bba02

Please sign in to comment.