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).
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()) {
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)
{
kb_int64_t
kb_size_t
logformat
+YesNoNone
memcachemode
obsolete
onoff
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
void
StoreController::init()
{
- if (UsingSmp() && IamWorkerProcess()) {
+ if (Config.memShared && IamWorkerProcess()) {
memStore = new MemStore;
memStore->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,
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 {
int highWaterMark;
int lowWaterMark;
} Swap;
+
+ YesNoNone memShared; ///< whether the memory cache is shared among workers
size_t memMaxSize;
struct {