*
*/
-#include "config.h"
+#include "squid.h"
#include "base/TextException.h"
#include "base/RunnersRegistry.h"
#include "ipc/mem/PagePool.h"
// 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;
}
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
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) * 0.5;
- 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())
- 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::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);
}