Skip to content

Commit

Permalink
Implement prefetch score.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja authored and osschar committed Mar 9, 2016
1 parent 22a2738 commit a908ec8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -85,7 +85,9 @@ m_stateCond(0), // We will explicitly lock the condition before use.
m_syncer(new DiskSyncer(this, "XrdFileCache::DiskSyncer")),
m_non_flushed_cnt(0),
m_in_sync(false),
m_downloadCond(0)
m_downloadCond(0),
m_prefetchReadCnt(0),
m_prefetchHitCnt(0)
{
clLog()->Debug(XrdCl::AppMsg, "File::File() %s", m_input.Path());
Open();
Expand Down Expand Up @@ -221,7 +223,7 @@ bool File::Open()
{
int ss = (m_fileSize - 1)/m_cfi.GetBufferSize() + 1;
clLog()->Info(XrdCl::AppMsg, "Creating new file info with size %lld. Reserve space for %d blocks %s", m_fileSize, ss, m_input.Path());
m_cfi.ResizeBits(ss);
m_cfi.ResizeBits(ss, Factory::GetInstance().RefConfiguration().m_prefetch);
m_cfi.WriteHeader(m_infoFile);
}
else
Expand Down Expand Up @@ -359,6 +361,8 @@ int File::ReadBlocksFromDisk(std::list<int>& blocks,
return rs;

total += rs;

CheckPrefetchStatDisk(*ii);
}

return total;
Expand Down Expand Up @@ -507,6 +511,8 @@ int File::Read(char* iUserBuff, long long iUserOff, int iUserSize)
overlap((*bi)->m_offset/BS, BS, iUserOff, iUserSize, user_off, off_in_block, size_to_copy);
memcpy(&iUserBuff[user_off], &((*bi)->m_buff[off_in_block]), size_to_copy);
bytes_read += size_to_copy;

CheckPrefetchStatRAM(*bi);
}
else // it has failed ... krap up.
{
Expand Down Expand Up @@ -787,12 +793,40 @@ void File::Prefetch()

// decrease counter of globally available blocks, resources already checked in global thread
cache()->RequestRAMBlock();
m_prefetchReadCnt++;

Block *b = RequestBlock(block_idx, true);
inc_ref_count(b);
}


//______________________________________________________________________________
void File::CheckPrefetchStatRAM(Block* b)
{
if (Factory::GetInstance().RefConfiguration().m_prefetch) {
if (b->m_prefetch)
m_prefetchHitCnt++;
}
}

//______________________________________________________________________________
void File::CheckPrefetchStatDisk(int idx)
{
if (Factory::GetInstance().RefConfiguration().m_prefetch) {
if (m_cfi.TestPrefetchBit(idx))
m_prefetchHitCnt++;
}
}

//______________________________________________________________________________
float File::GetPrefetchScore()
{
if (m_prefetchReadCnt)
return m_prefetchHitCnt/m_prefetchReadCnt;

return 0;
}

//==============================================================================

//==============================================================================
Expand Down
8 changes: 8 additions & 0 deletions src/XrdFileCache/XrdFileCacheFile.hh
Expand Up @@ -124,6 +124,9 @@ namespace XrdFileCache

Stats m_stats; //!< cache statistics, used in IO detach

int m_prefetchReadCnt;
int m_prefetchHitCnt;

public:

//------------------------------------------------------------------------
Expand Down Expand Up @@ -167,6 +170,8 @@ namespace XrdFileCache

void Prefetch();

float GetPrefetchScore();

private:
Block* RequestBlock(int i, bool prefetch);

Expand All @@ -179,6 +184,9 @@ namespace XrdFileCache

long long BufferSize();

void CheckPrefetchStatRAM(Block* b);
void CheckPrefetchStatDisk(int idx);

//! Short log alias.
XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }

Expand Down

0 comments on commit a908ec8

Please sign in to comment.