From: Alex Rousskov Date: Wed, 2 Feb 2011 01:49:34 +0000 (-0700) Subject: Polished skipping of cache_dirs inactive in a given strand (e.g. Coordinator) X-Git-Tag: take02~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=14911a4e01015b5b559b25fad08f2185d46c7190;p=thirdparty%2Fsquid.git Polished skipping of cache_dirs inactive in a given strand (e.g. Coordinator) by adding SwapDir::active() method. The directory is active if it makes sense to call its init/create/get methods in a given strand. Fixed counting cache_dirs that need dedicated strands. We no longer assume that all cache_dirs do but use SwapDir::needsDiskStrand() to ask each dir. The result is stored in Config.cacheSwap.n_strands to optimize NumberOfKids(). --- diff --git a/src/StoreHashIndex.h b/src/StoreHashIndex.h index 1b76377eb7..655d846eec 100644 --- a/src/StoreHashIndex.h +++ b/src/StoreHashIndex.h @@ -82,6 +82,7 @@ public: private: /* migration logic */ StorePointer store(int const x) const; + SwapDir &dir(int const idx) const; }; class StoreHashIndexEntry : public StoreEntry diff --git a/src/SwapDir.cc b/src/SwapDir.cc index 95fc5736f3..29ea1f90f5 100644 --- a/src/SwapDir.cc +++ b/src/SwapDir.cc @@ -161,6 +161,25 @@ SwapDir::type() const return theType; } +bool +SwapDir::active() const +{ + if (IamWorkerProcess()) + return true; + + // we are inside a disker dedicated to this disk + if (IamDiskProcess() && index == (KidIdentifier-1 - Config.workers)) + return true; + + return false; // Coordinator, wrong disker, etc. +} + +bool +SwapDir::needsDiskStrand() const +{ + return false; +} + /* NOT performance critical. Really. Don't bother optimising for speed * - RBC 20030718 */ diff --git a/src/SwapDir.h b/src/SwapDir.h index 6789b08531..8e8187c48e 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -118,6 +118,9 @@ public: virtual void reconfigure(int, char *) = 0; char const *type() const; + virtual bool needsDiskStrand() const; ///< needs a dedicated kid process + virtual bool active() const; ///< may be used in this strand + /* official Store interface functions */ virtual void diskFull(); diff --git a/src/cache_cf.cc b/src/cache_cf.cc index eaa610107c..75ae7f0287 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1884,13 +1884,6 @@ find_fstype(char *type) static void parse_cachedir(SquidConfig::_cacheSwap * swap) { - // coordinator does not need to handle cache_dir. - if (IamCoordinatorProcess()) { - // make sure the NumberOfKids() is correct for coordinator - ++swap->n_processes; // XXX: does not work in reconfigure - return; - } - char *type_str; char *path_str; RefCount sd; @@ -1956,7 +1949,9 @@ parse_cachedir(SquidConfig::_cacheSwap * swap) sd->parse(swap->n_configured, path_str); ++swap->n_configured; - ++swap->n_processes; + + if (sd->needsDiskStrand()) + ++swap->n_strands; /* Update the max object size */ update_maxobjsize(); diff --git a/src/fs/rock/RockSwapDir.cc b/src/fs/rock/RockSwapDir.cc index 9a8a4500c6..55ff9881cd 100644 --- a/src/fs/rock/RockSwapDir.cc +++ b/src/fs/rock/RockSwapDir.cc @@ -187,6 +187,12 @@ Rock::SwapDir::init() theFile->open(O_RDWR, 0644, this); } +bool +Rock::SwapDir::needsDiskStrand() const +{ + return true; +} + void Rock::SwapDir::parse(int anIndex, char *aPath) { diff --git a/src/fs/rock/RockSwapDir.h b/src/fs/rock/RockSwapDir.h index 2f91692d69..fb1336898b 100644 --- a/src/fs/rock/RockSwapDir.h +++ b/src/fs/rock/RockSwapDir.h @@ -30,6 +30,7 @@ public: protected: /* protected ::SwapDir API */ + virtual bool needsDiskStrand() const; virtual void create(); virtual void init(); virtual int canStore(StoreEntry const &) const; diff --git a/src/store_dir.cc b/src/store_dir.cc index 69eb361930..4703544c59 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -515,6 +515,14 @@ StoreHashIndex::store(int const x) const return INDEXSD(x); } +SwapDir & +StoreHashIndex::dir(const int i) const +{ + SwapDir *sd = dynamic_cast(INDEXSD(i)); + assert(sd); + return *sd; +} + void StoreController::sync(void) { @@ -700,15 +708,18 @@ StoreController::get(const cache_key *key) // ask each cache_dir until the entry is found; use static starting // point to avoid asking the same subset of disks more often // TODO: coordinate with put() to be able to guess the right disk often + static int idx = 0; for (int n = 0; n < cacheDirs; ++n) { - static int idx = 0; + idx = (idx + 1) % cacheDirs; SwapDir *sd = dynamic_cast(INDEXSD(idx)); + if (!sd->active()) + continue; + if (StoreEntry *e = sd->get(key)) { debugs(20, 3, HERE << "cache_dir " << idx << " got cached entry: " << *e); return e; } - idx = (idx + 1) % cacheDirs; } } @@ -774,8 +785,10 @@ StoreHashIndex::callback() void StoreHashIndex::create() { - for (int i = 0; i < Config.cacheSwap.n_configured; i++) - store(i)->create(); + for (int i = 0; i < Config.cacheSwap.n_configured; i++) { + if (dir(i).active()) + store(i)->create(); + } } /* Lookup an object in the cache. @@ -832,13 +845,8 @@ StoreHashIndex::init() * above * Step 3: have the hash index walk the searches itself. */ - if (IamDiskProcess() && - i != KidIdentifier % Config.cacheSwap.n_configured) { - debugs(20, 3, HERE << " skipping init for cache_dir " << - dynamic_cast(*store(i)).path); - continue; - } - store(i)->init(); + if (dir(i).active()) + store(i)->init(); } } diff --git a/src/structs.h b/src/structs.h index dd034b4fc7..3d9115e587 100644 --- a/src/structs.h +++ b/src/structs.h @@ -497,8 +497,8 @@ struct SquidConfig { RefCount *swapDirs; int n_allocated; int n_configured; - ///< number of disk processes (set even when n_configured is not) - int n_processes; + ///< number of disk processes required to support all cache_dirs + int n_strands; } cacheSwap; /* * I'm sick of having to keep doing this .. diff --git a/src/tools.cc b/src/tools.cc index 5d9a1218e2..39ed3eeda1 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -871,8 +871,7 @@ NumberOfKids() // XXX: detect and abort when called before workers/cache_dirs are parsed - // XXX: this is not always the case as there are other cache_dir types - const int rockDirs = Config.cacheSwap.n_processes; + const int rockDirs = Config.cacheSwap.n_strands; const bool needCoord = Config.workers > 1 || rockDirs > 0; return (needCoord ? 1 : 0) + Config.workers + rockDirs;