/*
- * $Id$
- *
* DEBUG: section 54 Interprocess Communication
*
*/
-#include "config.h"
-#include "base/TextException.h"
+#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
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
}
/// 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 create(const RunnerRegistry &);
+ virtual void open(const RunnerRegistry &);
virtual ~SharedMemPagesRr();
private:
RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr);
-
-void SharedMemPagesRr::run(const RunnerRegistry &)
+void
+SharedMemPagesRr::run(const RunnerRegistry &r)
{
- if (!UsingSmp())
+ if (Ipc::Mem::PageLimit() <= 0)
return;
- // When cache_dirs start using shared memory pages, they would
- // need to communicate their needs to us somehow.
- if (Config.memMaxSize <= 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::run(r);
+}
- if (IamMasterProcess()) {
- Must(!owner);
- owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(), Ipc::Mem::PageSize());
- }
+void
+SharedMemPagesRr::create(const RunnerRegistry &)
+{
+ Must(!owner);
+ owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(),
+ Ipc::Mem::PageSize());
+}
+void
+SharedMemPagesRr::open(const RunnerRegistry &)
+{
Must(!ThePagePool);
ThePagePool = new Ipc::Mem::PagePool(PagePoolId);
}