]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added memory_cache_shared to squid.conf. Report whether mem_cache is shared.
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 25 May 2011 00:33:52 +0000 (18:33 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 25 May 2011 00:33:52 +0000 (18:33 -0600)
Allow the user to explicitly disable shared memory caching in SMP mode.

Added YesNoNone class to allow Squid to compute the default value of a boolean
option (based on other options) instead of using a hard-coded default. The
class is used to automatically enable shared memory caching in SMP
environments (and disable it in non-SMP environments) unless the user says
otherwise.

This needs more work to reduce the number of shared memory pages if shared
memory caching is disabled (the pages may still be needed for SMP I/O).

src/MemStore.cc
src/cache_cf.cc
src/cf.data.depend
src/cf.data.pre
src/store_dir.cc
src/structs.h

index c9f77a86c40b912d0f8b011af366734a5f1c3868..7944840bddc7b14185de9f1750999a1d3633fec1 100644 (file)
@@ -359,7 +359,12 @@ RunnerRegistrationEntry(rrAfterConfig, MemStoreRr);
 
 void MemStoreRr::run(const RunnerRegistry &)
 {
-    if (!UsingSmp())
+    // decide whether to use a shared memory cache if the user did not specify
+    if (!Config.memShared.configured()) {
+        Config.memShared.configure(UsingSmp() && Config.memMaxSize > 0);
+    }
+
+    if (!Config.memShared)
         return;
 
     if (IamMasterProcess()) {
index 224337e621d0539e12f152d51c748109afe3435f..1e3d09de23289af5a03faf9c5f57f7a42bd0eff7 100644 (file)
@@ -3319,6 +3319,44 @@ dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings *
     storeAppendPrintf(entry, "\n");
 }
 
+YesNoNone::YesNoNone(): option(0)
+{
+}
+
+void
+YesNoNone::configure(bool beSet)
+{
+    option = beSet ? +1 : -1;
+}
+
+YesNoNone::operator void*() const
+{
+    assert(option != 0); // must call configure() first
+    return option > 0 ? (void*)this : NULL;
+}
+
+
+static void
+free_YesNoNone(YesNoNone *option)
+{
+    return;
+}
+
+static void
+parse_YesNoNone(YesNoNone *option)
+{
+    int value = 0;
+    parse_onoff(&value);
+    option->configure(value > 0);
+}
+
+static void
+dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
+{
+    if (option.configured())
+        dump_onoff(entry, name, option ? 1 : 0);
+}
+
 static void
 free_memcachemode(SquidConfig * config)
 {
index fc5f3ff1b27633f375dae964ed4fa8dbb36bcfee..a963ca5fac51ebd80e33c236d4b705b42f96ece5 100644 (file)
@@ -45,6 +45,7 @@ int
 kb_int64_t
 kb_size_t
 logformat
+YesNoNone
 memcachemode
 obsolete
 onoff
index 32a73d5f8e1ea80f547511d0dda35133c4317512..7f0a73035d7ce4e686d85fade3d2e4f83e3eb2d8 100644 (file)
@@ -2550,6 +2550,18 @@ DOC_START
        enough to keep larger objects from hoarding cache_mem.
 DOC_END
 
+NAME: memory_cache_shared
+COMMENT: on|off
+TYPE: YesNoNone
+LOC: Config.memShared
+DEFAULT: none
+DOC_START
+       Controls whether the memory cache is shared among SMP workers.
+
+       By default, the memory cache is shared only if there are multiple
+       worker processes with positive cache_mem setting.
+DOC_END
+
 NAME: memory_cache_mode
 TYPE: memcachemode
 LOC: Config
index 8ecdbad5d00b41bea935b609b259868d54150070..8e8e5b82e95050e8b78de7f99dc3ee83f5b633cf 100644 (file)
@@ -92,7 +92,7 @@ STDIRSELECT *storeDirSelectSwapDir = storeDirSelectSwapDirLeastLoad;
 void
 StoreController::init()
 {
-    if (UsingSmp() && IamWorkerProcess()) {
+    if (Config.memShared && IamWorkerProcess()) {
         memStore = new MemStore;
         memStore->init();
     }
@@ -870,7 +870,8 @@ StoreHashIndex::init()
      * moment it remains at approximately 24 hours.  */
     store_hash_buckets = storeKeyHashBuckets(buckets);
     debugs(20, 1, "Using " << store_hash_buckets << " Store buckets");
-    debugs(20, 1, "Max Mem  size: " << ( Config.memMaxSize >> 10) << " KB");
+    debugs(20, 1, "Max Mem  size: " << ( Config.memMaxSize >> 10) << " KB" <<
+        (memStore ? " [shared]" : ""));
     debugs(20, 1, "Max Swap size: " << (Store::Root().maxSize() >> 10) << " KB");
 
     store_table = hash_create(storeKeyHashCmp,
index 924bebfa708da96e89cad3b580cd417fd29160e7..8d79f866d3aae4618c223f740640e0027d87d796 100644 (file)
@@ -146,6 +146,28 @@ class RemovalPolicySettings;
 class external_acl;
 class SwapDir;
 
+/// Used for boolean enabled/disabled options with complex default logic.
+/// Allows Squid to compute the right default after configuration.
+/// Checks that not-yet-defined option values are not used.
+class YesNoNone {
+// TODO: generalize to non-boolean option types
+public:
+    YesNoNone();
+
+    /// returns true iff enabled; asserts if the option has not been configured
+    operator void *() const; // TODO: use a fancy/safer version of the operator
+
+    /// enables or disables the option; 
+    void configure(bool beSet);
+
+    /// whether the option was enabled or disabled, by user or Squid
+    bool configured() const { return option != 0; }
+
+private:
+    enum { optUnspecified = -1, optDisabled = 0, optEnabled = 1 };
+    int option; ///< configured value or zero
+};
+
 struct SquidConfig {
 
     struct {
@@ -155,6 +177,8 @@ struct SquidConfig {
         int highWaterMark;
         int lowWaterMark;
     } Swap;
+
+    YesNoNone memShared; ///< whether the memory cache is shared among workers
     size_t memMaxSize;
 
     struct {