From: Dmitry Kurochkin Date: Wed, 27 Apr 2011 01:52:46 +0000 (+0400) Subject: Initialize and cleanup Rock shared maps using RunnersRegistry API. X-Git-Tag: take07~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=902df39853b640ec9910980de93af1ed6d6a7b75;p=thirdparty%2Fsquid.git Initialize and cleanup Rock shared maps using RunnersRegistry API. --- diff --git a/src/fs/rock/RockSwapDir.cc b/src/fs/rock/RockSwapDir.cc index ce06bc823e..73182b9d92 100644 --- a/src/fs/rock/RockSwapDir.cc +++ b/src/fs/rock/RockSwapDir.cc @@ -8,6 +8,7 @@ #include "Parsing.h" #include #include "MemObject.h" +#include "base/RunnersRegistry.h" #include "DiskIO/DiskIOModule.h" #include "DiskIO/DiskIOStrategy.h" #include "DiskIO/ReadRequest.h" @@ -20,15 +21,13 @@ // must be divisible by 1024 due to cur_size and max_size KB madness const int64_t Rock::SwapDir::HeaderSize = 16*1024; -Rock::SwapDir::SwapDir(): ::SwapDir("rock"), filePath(NULL), io(NULL), - mapOwner(NULL), map(NULL) +Rock::SwapDir::SwapDir(): ::SwapDir("rock"), filePath(NULL), io(NULL), map(NULL) { } Rock::SwapDir::~SwapDir() { delete io; - delete mapOwner; delete map; safe_free(filePath); } @@ -195,16 +194,8 @@ Rock::SwapDir::init() // are refcounted. We up our count once to avoid implicit delete's. RefCountReference(); - if (!map && (!UsingSmp() || IamDiskProcess())) { - // XXX: polish, validateOptions() has same code - const int64_t eLimitHi = 0xFFFFFF; // Core sfileno maximum - const int64_t eLimitLo = 0; // dynamic shrinking unsupported - const int64_t eWanted = (maximumSize() - HeaderSize)/max_objsize; - const int64_t eAllowed = min(max(eLimitLo, eWanted), eLimitHi); - Must(!mapOwner); - mapOwner = DirMap::Init(path, eAllowed); - map = new DirMap(path); - } + Must(!map); + map = new DirMap(path); const char *ioModule = UsingSmp() ? "IpcIo" : "Blocking"; if (DiskIOModule *m = DiskIOModule::Find(ioModule)) { @@ -480,9 +471,6 @@ Rock::SwapDir::ioCompletedNotification() fatalf("Rock cache_dir failed to open db file: %s", filePath); } - if (!map) - map = new DirMap(path); - // TODO: lower debugging level debugs(47,1, "Rock cache_dir[" << index << "] limits: " << std::setw(12) << maximumSize() << " disk bytes and " << @@ -688,3 +676,45 @@ Rock::SwapDir::statfs(StoreEntry &e) const storeAppendPrintf(&e, "\n"); } + + +/// initializes shared memory segments used by Rock::SwapDir +class RockSwapDirRr: public RegisteredRunner +{ +public: + /* RegisteredRunner API */ + virtual void run(const RunnerRegistry &); + virtual ~RockSwapDirRr(); + +private: + Vector owners; +}; + +RunnerRegistrationEntry(rrAfterConfig, RockSwapDirRr); + + +void RockSwapDirRr::run(const RunnerRegistry &) +{ + if (IamMasterProcess()) { + Must(owners.empty()); + for (int i = 0; i < Config.cacheSwap.n_configured; ++i) { + const Rock::SwapDir *const sd = + dynamic_cast(INDEXSD(i)); + if (!sd) + continue; + + // XXX: polish, validateOptions() has same code + const int64_t eLimitHi = 0xFFFFFF; // Core sfileno maximum + const int64_t eLimitLo = 0; // dynamic shrinking unsupported + const int64_t eWanted = (sd->maximumSize() - Rock::SwapDir::HeaderSize)/sd->maxObjectSize(); + const int64_t eAllowed = min(max(eLimitLo, eWanted), eLimitHi); + owners.push_back(Rock::SwapDir::DirMap::Init(sd->path, eAllowed)); + } + } +} + +RockSwapDirRr::~RockSwapDirRr() +{ + for (size_t i = 0; i < owners.size(); ++i) + delete owners[i]; +} diff --git a/src/fs/rock/RockSwapDir.h b/src/fs/rock/RockSwapDir.h index 5d9ecc55c2..f4c18c9b3a 100644 --- a/src/fs/rock/RockSwapDir.h +++ b/src/fs/rock/RockSwapDir.h @@ -31,6 +31,13 @@ public: virtual uint64_t currentCount() const; virtual bool doReportStat() const; + // TODO: change cur_size and max_size type to stop this madness + int64_t maximumSize() const { return static_cast(max_size) << 10; } + + static const int64_t HeaderSize; + + typedef Ipc::StoreMapWithExtras DirMap; + protected: /* protected ::SwapDir API */ virtual bool needsDiskStrand() const; @@ -65,8 +72,6 @@ protected: void trackReferences(StoreEntry &e); ///< add to replacement policy scope void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope - // TODO: change cur_size and max_size type to stop this madness - int64_t maximumSize() const { return static_cast(max_size) << 10;} int64_t diskOffset(int filen) const; int64_t diskOffsetLimit() const; int entryLimit() const { return map->entryLimit(); } @@ -75,14 +80,9 @@ protected: const char *filePath; ///< location of cache storage file inside path/ private: - typedef Ipc::StoreMapWithExtras DirMap; - DiskIOStrategy *io; RefCount theFile; ///< cache storage for this cache_dir - DirMap::Owner *mapOwner; DirMap *map; - - static const int64_t HeaderSize; ///< on-disk db header size }; } // namespace Rock