From 2a1427b307c80b873da98a11be27272e29cfeaae Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Thu, 18 Feb 2016 23:27:25 -0800 Subject: [PATCH] pfc.prefetch now takes int argument: max number of blocks to prefetch per file. --- src/XrdFileCache/XrdFileCacheFactory.cc | 14 ++++---- src/XrdFileCache/XrdFileCacheFactory.hh | 6 ++-- src/XrdFileCache/XrdFileCacheFile.cc | 43 +++++++++++++------------ src/XrdFileCache/XrdFileCacheFile.hh | 2 +- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/XrdFileCache/XrdFileCacheFactory.cc b/src/XrdFileCache/XrdFileCacheFactory.cc index ec8c68f76c8..5449e7a2183 100644 --- a/src/XrdFileCache/XrdFileCacheFactory.cc +++ b/src/XrdFileCache/XrdFileCacheFactory.cc @@ -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(); @@ -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" ) diff --git a/src/XrdFileCache/XrdFileCacheFactory.hh b/src/XrdFileCache/XrdFileCacheFactory.hh index d4108efbbe0..b2c30f783ff 100644 --- a/src/XrdFileCache/XrdFileCacheFactory.hh +++ b/src/XrdFileCache/XrdFileCacheFactory.hh @@ -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 @@ -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 }; diff --git a/src/XrdFileCache/XrdFileCacheFile.cc b/src/XrdFileCache/XrdFileCacheFile.cc index 5785d0467f5..41fc3170133 100644 --- a/src/XrdFileCache/XrdFileCacheFile.cc +++ b/src/XrdFileCache/XrdFileCacheFile.cc @@ -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) : @@ -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); } @@ -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); } diff --git a/src/XrdFileCache/XrdFileCacheFile.hh b/src/XrdFileCache/XrdFileCacheFile.hh index 36b1d8a7e4f..1a98651cc45 100644 --- a/src/XrdFileCache/XrdFileCacheFile.hh +++ b/src/XrdFileCache/XrdFileCacheFile.hh @@ -111,7 +111,7 @@ namespace XrdFileCache XrdSysMutex m_syncStatusMutex; //!< mutex locking fsync status XrdJob *m_syncer; std::vector m_writes_during_sync; - int m_non_flushed_cnt; + int m_non_flushed_cnt; bool m_in_sync; typedef std::list IntList_t;