]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/Pages.cc
Initial shared memory pages implementation.
[thirdparty/squid.git] / src / ipc / mem / Pages.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "config.h"
9 #include "base/TextException.h"
10 #include "ipc/mem/PagePool.h"
11 #include "ipc/mem/Pages.h"
12 #include "structs.h"
13 #include "SwapDir.h"
14
15 // Uses a single PagePool instance, for now.
16 // Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
17
18 // TODO: make pool id more unique so it does not conflict with other Squids?
19 static const String PagePoolId = "squid-page-pool";
20 static Ipc::Mem::PagePool *ThePagePool = 0;
21
22 // XXX: temporary function until we have a better page size handling
23 static unsigned int
24 calculatePageSize()
25 {
26 unsigned int max_objsize = 0;
27 for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
28 const SwapDir *const sd = dynamic_cast<SwapDir *>(INDEXSD(i));
29 if (sd->max_objsize > max_objsize)
30 max_objsize = sd->max_objsize;
31 }
32 return max_objsize;
33 }
34
35 void
36 Ipc::Mem::Init()
37 {
38 Must(!ThePagePool);
39 // XXX: pool capacity and page size should be configurable/meaningful
40 ThePagePool = new PagePool(PagePoolId, 1024, calculatePageSize());
41 }
42
43 void
44 Ipc::Mem::Attach()
45 {
46 Must(!ThePagePool);
47 // TODO: make pool id more unique so it does not conflict with other Squid instances?
48 ThePagePool = new PagePool(PagePoolId);
49 }
50
51 bool
52 Ipc::Mem::GetPage(PageId &page)
53 {
54 Must(ThePagePool);
55 return ThePagePool->get(page);
56 }
57
58 void
59 Ipc::Mem::PutPage(PageId &page)
60 {
61 Must(ThePagePool);
62 ThePagePool->put(page);
63 }
64
65 void *
66 Ipc::Mem::PagePointer(const PageId &page)
67 {
68 Must(ThePagePool);
69 return ThePagePool->pagePointer(page);
70 }