Skip to content

Commit

Permalink
pfc.prefetch now takes int argument: max number of blocks to prefetch…
Browse files Browse the repository at this point in the history
… per file.
  • Loading branch information
osschar committed Mar 9, 2016
1 parent f8b27a3 commit 2a1427b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
14 changes: 7 additions & 7 deletions src/XrdFileCache/XrdFileCacheFactory.cc
Expand Up @@ -312,11 +312,11 @@ bool Factory::ConfigParameters(std::string part, XrdOucStream& config )
{
m_configuration.m_username = config.GetWord();
}
else if ( part == "cachedir" )
else if ( part == "cachedir" )
{
m_configuration.m_cache_dir = config.GetWord();
}
else if ( part == "diskusage" )
else if ( part == "diskusage" )
{
std::string minV = config.GetWord();
std::string maxV = config.GetWord();
Expand Down Expand Up @@ -364,12 +364,12 @@ bool Factory::ConfigParameters(std::string part, XrdOucStream& config )
else if (part == "prefetch" )
{
int p = ::atoi(config.GetWord());
if (p != 0) {
printf("prefetch enabled !!!!\n");
if (p > 0) {
printf("prefetch enabled, max blocks per file=%d\n", p);
m_configuration.m_prefetch = true;
}
else {
m_configuration.m_prefetch = false;
m_configuration.m_prefetch_max_blocks = p;
} else {
m_configuration.m_prefetch = false;
}
}
else if (part == "nram" )
Expand Down
6 changes: 4 additions & 2 deletions src/XrdFileCache/XrdFileCacheFactory.hh
Expand Up @@ -55,6 +55,7 @@ namespace XrdFileCache
m_bufferSize(1024*1024),
m_NRamBuffers(8000),
m_prefetch(false),
m_prefetch_max_blocks(10),
m_hdfsbsize(128*1024*1024) {}

bool m_hdfsmode; //!< flag for enabling block-level operation
Expand All @@ -65,8 +66,9 @@ namespace XrdFileCache
long long m_diskUsageHWM; //!< cache purge high water mark

long long m_bufferSize; //!< prefetch buffer size, default 1MB
int m_NRamBuffers; //!< number of total in-memory cache blocks
bool m_prefetch; //!< prefetch enable state
int m_NRamBuffers; //!< number of total in-memory cache blocks
bool m_prefetch; //!< prefetch enable state
size_t m_prefetch_max_blocks;//!< maximum number of blocks to prefetch per file

long long m_hdfsbsize; //!< used with m_hdfsmode, default 128MB
};
Expand Down
43 changes: 23 additions & 20 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -48,28 +48,27 @@ namespace XrdPosixGlobals

namespace
{
const int PREFETCH_MAX_ATTEMPTS = 10;
const size_t PREFETCH_MAX_BLOCKS=10;
const int PREFETCH_MAX_ATTEMPTS = 10;

class DiskSyncer : public XrdJob
{
private:
File *m_file;
public:
DiskSyncer(File *pref, const char *desc="") :
XrdJob(desc),
m_file(pref)
{}
void DoIt()
class DiskSyncer : public XrdJob
{
m_file->Sync();
}
};
private:
File *m_file;
public:
DiskSyncer(File *pref, const char *desc="") :
XrdJob(desc),
m_file(pref)
{}
void DoIt()
{
m_file->Sync();
}
};
}

namespace
{
Cache* cache() {return Factory::GetInstance().GetCache();}
Cache* cache() { return Factory::GetInstance().GetCache(); }
}

File::File(XrdOucCacheIO &inputIO, std::string& disk_file_path, long long iOffset, long long iFileSize) :
Expand Down Expand Up @@ -351,7 +350,8 @@ Block* File::RequestBlock(int i, bool prefetch)
clLog()->Dump(XrdCl::AppMsg, "File::RequestBlock() this = %p, b=%p, this idx=%d pOn=(%d) %s", (void*)this, (void*)b, i, prefetch, lPath());
m_block_map[i] = b;

if (m_prefetchState == kOn && m_block_map.size() > PREFETCH_MAX_BLOCKS) {
if (m_prefetchState == kOn && m_block_map.size() > Factory::GetInstance().RefConfiguration().m_prefetch_max_blocks)
{
m_prefetchState = kHold;
cache()->DeRegisterPrefetchFile(this);
}
Expand Down Expand Up @@ -820,14 +820,17 @@ void File::free_block(Block* b)
clLog()->Dump(XrdCl::AppMsg, "File::free_block block (%p) %d %s ", (void*)b, i, lPath());
delete m_block_map[i];
size_t ret = m_block_map.erase(i);
if (ret != 1) {
if (ret != 1)
{
clLog()->Error(XrdCl::AppMsg, "File::OnBlockZeroRefCount did not erase %d from map.", i);
}
else {
else
{
cache()->RAMBlockReleased();
}

if (m_prefetchState == kHold && m_block_map.size() < PREFETCH_MAX_BLOCKS) {
if (m_prefetchState == kHold && m_block_map.size() < Factory::GetInstance().RefConfiguration().m_prefetch_max_blocks)
{
m_prefetchState = kOn;
cache()->RegisterPrefetchFile(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/XrdFileCache/XrdFileCacheFile.hh
Expand Up @@ -111,7 +111,7 @@ namespace XrdFileCache
XrdSysMutex m_syncStatusMutex; //!< mutex locking fsync status
XrdJob *m_syncer;
std::vector<int> m_writes_during_sync;
int m_non_flushed_cnt;
int m_non_flushed_cnt;
bool m_in_sync;

typedef std::list<int> IntList_t;
Expand Down

0 comments on commit 2a1427b

Please sign in to comment.