]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/Pages.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/TextException.h"
10 #include "base/RunnersRegistry.h"
11 #include "ipc/mem/PagePool.h"
12 #include "ipc/mem/Pages.h"
16 // Uses a single PagePool instance, for now.
17 // Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
19 // TODO: make pool id more unique so it does not conflict with other Squids?
20 static const char *PagePoolId
= "squid-page-pool";
21 static Ipc::Mem::PagePool
*ThePagePool
= 0;
22 static int TheLimits
[Ipc::Mem::PageId::maxPurpose
];
24 // TODO: make configurable to avoid waste when mem-cached objects are small/big
32 Ipc::Mem::GetPage(const PageId::Purpose purpose
, PageId
&page
)
34 return ThePagePool
&& PagesAvailable(purpose
) > 0 ?
35 ThePagePool
->get(purpose
, page
) : false;
39 Ipc::Mem::PutPage(PageId
&page
)
42 ThePagePool
->put(page
);
46 Ipc::Mem::PagePointer(const PageId
&page
)
49 return ThePagePool
->pagePointer(page
);
56 for (int i
= 0; i
< PageId::maxPurpose
; ++i
)
57 limit
+= PageLimit(i
);
62 Ipc::Mem::PageLimit(const int purpose
)
64 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
65 return TheLimits
[purpose
];
68 // note: adjust this if we start recording needs during reconfigure
70 Ipc::Mem::NotePageNeed(const int purpose
, const int count
)
72 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
74 TheLimits
[purpose
] += count
;
80 return ThePagePool
? ThePagePool
->level() : 0;
84 Ipc::Mem::PageLevel(const int purpose
)
86 return ThePagePool
? ThePagePool
->level(purpose
) : 0;
89 /// initializes shared memory pages
90 class SharedMemPagesRr
: public Ipc::Mem::RegisteredRunner
93 /* RegisteredRunner API */
94 SharedMemPagesRr(): owner(NULL
) {}
95 virtual void run(const RunnerRegistry
&);
96 virtual void create(const RunnerRegistry
&);
97 virtual void open(const RunnerRegistry
&);
98 virtual ~SharedMemPagesRr();
101 Ipc::Mem::PagePool::Owner
*owner
;
104 RunnerRegistrationEntry(rrAfterConfig
, SharedMemPagesRr
);
108 SharedMemPagesRr::run(const RunnerRegistry
&r
)
110 if (Ipc::Mem::PageLimit() <= 0)
113 Ipc::Mem::RegisteredRunner::run(r
);
117 SharedMemPagesRr::create(const RunnerRegistry
&)
120 owner
= Ipc::Mem::PagePool::Init(PagePoolId
, Ipc::Mem::PageLimit(),
121 Ipc::Mem::PageSize());
125 SharedMemPagesRr::open(const RunnerRegistry
&)
128 ThePagePool
= new Ipc::Mem::PagePool(PagePoolId
);
131 SharedMemPagesRr::~SharedMemPagesRr()