]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/mem/Pages.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / ipc / mem / Pages.cc
index deecbf90792ed518cc82a76fbb461a8362f23f65..57df37d8e5f8a26d2b9ae5e4fee24c7215a93d27 100644 (file)
@@ -1,17 +1,19 @@
 /*
- * $Id$
- *
- * DEBUG: section 54    Interprocess Communication
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
-#include "config.h"
-#include "base/TextException.h"
+/* DEBUG: section 54    Interprocess Communication */
+
+#include "squid.h"
 #include "base/RunnersRegistry.h"
+#include "base/TextException.h"
 #include "ipc/mem/PagePool.h"
 #include "ipc/mem/Pages.h"
-#include "structs.h"
-#include "SwapDir.h"
+#include "tools.h"
 
 // Uses a single PagePool instance, for now.
 // Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
@@ -19,6 +21,7 @@
 // TODO: make pool id more unique so it does not conflict with other Squids?
 static const char *PagePoolId = "squid-page-pool";
 static Ipc::Mem::PagePool *ThePagePool = 0;
+static int TheLimits[Ipc::Mem::PageId::maxPurpose];
 
 // TODO: make configurable to avoid waste when mem-cached objects are small/big
 size_t
@@ -60,16 +63,17 @@ Ipc::Mem::PageLimit()
 size_t
 Ipc::Mem::PageLimit(const int purpose)
 {
-    switch (purpose) {
-    case PageId::cachePage:
-        return Config.memMaxSize > 0 ? Config.memMaxSize / PageSize() : 0;
-    case PageId::ioPage:
-        // XXX: this should be independent from memory cache pages
-        return PageLimit(PageId::cachePage)/2;
-    default:
-        Must(false);
-    }
-    return 0;
+    Must(0 <= purpose && purpose <= PageId::maxPurpose);
+    return TheLimits[purpose];
+}
+
+// note: adjust this if we start recording needs during reconfigure
+void
+Ipc::Mem::NotePageNeed(const int purpose, const int count)
+{
+    Must(0 <= purpose && purpose <= PageId::maxPurpose);
+    Must(count >= 0);
+    TheLimits[purpose] += count;
 }
 
 size_t
@@ -85,55 +89,50 @@ Ipc::Mem::PageLevel(const int purpose)
 }
 
 /// initializes shared memory pages
-class SharedMemPagesRr: public RegisteredRunner
+class SharedMemPagesRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
     SharedMemPagesRr(): owner(NULL) {}
-    virtual void run(const RunnerRegistry &);
+    virtual void useConfig();
+    virtual void create();
+    virtual void open();
     virtual ~SharedMemPagesRr();
 
 private:
     Ipc::Mem::PagePool::Owner *owner;
 };
 
-RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr);
-
+RunnerRegistrationEntry(SharedMemPagesRr);
 
-void SharedMemPagesRr::run(const RunnerRegistry &)
+void
+SharedMemPagesRr::useConfig()
 {
-    if (!UsingSmp())
-        return;
-
-    // When cache_dirs start using shared memory pages, they would
-    // need to communicate their needs to us somehow.
-    if (Config.memMaxSize <= 0)
+    if (Ipc::Mem::PageLimit() <= 0)
         return;
 
-    if (Ipc::Mem::PageLimit() <= 0) {
-        if (IamMasterProcess()) {
-            debugs(54, DBG_IMPORTANT, "WARNING: mem-cache size is too small ("
-                   << (Config.memMaxSize / 1024.0) << " KB), should be >= " <<
-                   (Ipc::Mem::PageSize() / 1024.0) << " KB");
-        }
-        return;
-    }
+    Ipc::Mem::RegisteredRunner::useConfig();
+}
 
-    if (IamMasterProcess()) {
-        Must(!owner);
-        owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(), Ipc::Mem::PageSize());
-    }
+void
+SharedMemPagesRr::create()
+{
+    Must(!owner);
+    owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(),
+                                     Ipc::Mem::PageSize());
+}
 
+void
+SharedMemPagesRr::open()
+{
     Must(!ThePagePool);
     ThePagePool = new Ipc::Mem::PagePool(PagePoolId);
 }
 
 SharedMemPagesRr::~SharedMemPagesRr()
 {
-    if (!UsingSmp())
-        return;
-
     delete ThePagePool;
     ThePagePool = NULL;
     delete owner;
 }
+