]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/mem/Pages.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / mem / Pages.cc
index ceed891f99a839e2e3db357cca55c782388ec5f4..1d80db7bc442b9b1da244f4b573fa38b2bfb9448 100644 (file)
@@ -1,17 +1,20 @@
 /*
- * $Id$
- *
- * DEBUG: section 54    Interprocess Communication
+ * Copyright (C) 1996-2014 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.
 // 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
-Ipc::Mem::PageSize() {
+Ipc::Mem::PageSize()
+{
     return 32*1024;
 }
 
@@ -30,7 +35,7 @@ bool
 Ipc::Mem::GetPage(const PageId::Purpose purpose, PageId &page)
 {
     return ThePagePool && PagesAvailable(purpose) > 0 ?
-        ThePagePool->get(purpose, page) : false;
+           ThePagePool->get(purpose, page) : false;
 }
 
 void
@@ -59,20 +64,17 @@ Ipc::Mem::PageLimit()
 size_t
 Ipc::Mem::PageLimit(const int purpose)
 {
-    switch (purpose) {
-    case PageId::cachePage:
-        // TODO: adjust cache_mem description to say that in SMP mode,
-        // in-transit objects are not allocated using cache_mem. Eventually,
-        // they should not use cache_mem even if shared memory is not used:
-        // in-transit objects have nothing to do with caching.
-        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
@@ -88,45 +90,42 @@ 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);
 }
@@ -140,3 +139,4 @@ SharedMemPagesRr::~SharedMemPagesRr()
     ThePagePool = NULL;
     delete owner;
 }
+