]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polished skipping of cache_dirs inactive in a given strand (e.g. Coordinator)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 2 Feb 2011 01:49:34 +0000 (18:49 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 2 Feb 2011 01:49:34 +0000 (18:49 -0700)
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().

src/StoreHashIndex.h
src/SwapDir.cc
src/SwapDir.h
src/cache_cf.cc
src/fs/rock/RockSwapDir.cc
src/fs/rock/RockSwapDir.h
src/store_dir.cc
src/structs.h
src/tools.cc

index 1b76377eb789cc481cf9a94247b16e27c57da806..655d846eec29feddab541ca7282a66bfa4b2251b 100644 (file)
@@ -82,6 +82,7 @@ public:
 private:
     /* migration logic */
     StorePointer store(int const x) const;
+    SwapDir &dir(int const idx) const;
 };
 
 class StoreHashIndexEntry : public StoreEntry
index 95fc5736f3bfdee3539ac528ea6d1488fd9b658c..29ea1f90f56e99be550288659951ac453280ca57 100644 (file)
@@ -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
  */
index 6789b085314d12dd7ac3d0ca8de7de40f9b9ae32..8e8187c48e8da644ade8744f7e2ecb3e32b408ec 100644 (file)
@@ -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();
 
index eaa610107cee621718fa4dfb9194991c1d219cd1..75ae7f0287f34cea155dcbb6f7feff1d93b89142 100644 (file)
@@ -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<SwapDir> 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();
index 9a8a4500c644a475aa4f4d69e418a77174ef499d..55ff9881cd76d3cc3120dbcc5fe435c42e913c82 100644 (file)
@@ -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)
 {
index 2f91692d6914acdd25d80e8681957e306d3fbba7..fb1336898b92ee3158d4da316bbd13f0ee3b1b51 100644 (file)
@@ -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;
index 69eb361930fe0087dddb3fb97df104d5c0305ede..4703544c59247098620de8c3ca35d7a5c003daf3 100644 (file)
@@ -515,6 +515,14 @@ StoreHashIndex::store(int const x) const
     return INDEXSD(x);
 }
 
+SwapDir &
+StoreHashIndex::dir(const int i) const
+{
+    SwapDir *sd = dynamic_cast<SwapDir*>(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<SwapDir*>(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<const SwapDir &>(*store(i)).path);
-            continue;
-        }
-        store(i)->init();
+        if (dir(i).active())
+            store(i)->init();
     }
 }
 
index dd034b4fc717d5532a557c606d35b254250e53ce..3d9115e587b62e39541dee59a6f9fcb5c25a4290 100644 (file)
@@ -497,8 +497,8 @@ struct SquidConfig {
         RefCount<class Store> *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 ..
index 5d9a1218e24b4d665419304e78e330b5e4009957..39ed3eeda1ba56c4a5f1cd93e1bd7651d653ae5d 100644 (file)
@@ -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;