]>
Commit | Line | Data |
---|---|---|
3e0ddf16 AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 54 Interprocess Communication | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "config.h" | |
56f8aa50 DK |
9 | #include "base/TextException.h" |
10 | #include "ipc/mem/PagePool.h" | |
3e0ddf16 | 11 | #include "ipc/mem/Pages.h" |
56f8aa50 DK |
12 | #include "structs.h" |
13 | #include "SwapDir.h" | |
3e0ddf16 | 14 | |
56f8aa50 | 15 | // Uses a single PagePool instance, for now. |
3e0ddf16 | 16 | // Eventually, we may have pools dedicated to memory caching, disk I/O, etc. |
56f8aa50 DK |
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 | ||
72261456 | 22 | // TODO: make configurable to avoid waste when mem-cached objects are small/big |
d1ad4017 AR |
23 | size_t |
24 | Ipc::Mem::PageSize() { | |
72261456 | 25 | return 32*1024; |
56f8aa50 DK |
26 | } |
27 | ||
28 | void | |
29 | Ipc::Mem::Init() | |
30 | { | |
31 | Must(!ThePagePool); | |
72261456 AR |
32 | const size_t capacity = Limit() / PageSize(); |
33 | ThePagePool = new PagePool(PagePoolId, capacity, PageSize()); | |
56f8aa50 DK |
34 | } |
35 | ||
36 | void | |
37 | Ipc::Mem::Attach() | |
38 | { | |
39 | Must(!ThePagePool); | |
40 | // TODO: make pool id more unique so it does not conflict with other Squid instances? | |
41 | ThePagePool = new PagePool(PagePoolId); | |
42 | } | |
43 | ||
44 | bool | |
45 | Ipc::Mem::GetPage(PageId &page) | |
46 | { | |
72261456 | 47 | return ThePagePool ? ThePagePool->get(page) : false; |
56f8aa50 DK |
48 | } |
49 | ||
50 | void | |
51 | Ipc::Mem::PutPage(PageId &page) | |
52 | { | |
53 | Must(ThePagePool); | |
54 | ThePagePool->put(page); | |
55 | } | |
56 | ||
57 | void * | |
58 | Ipc::Mem::PagePointer(const PageId &page) | |
59 | { | |
60 | Must(ThePagePool); | |
61 | return ThePagePool->pagePointer(page); | |
62 | } | |
72261456 AR |
63 | |
64 | size_t | |
65 | Ipc::Mem::Limit() | |
66 | { | |
67 | // TODO: adjust cache_mem description to say that in SMP mode, | |
68 | // in-transit objects are not allocated using cache_mem. Eventually, | |
69 | // they should not use cache_mem even if shared memory is not used: | |
70 | // in-transit objects have nothing to do with caching. | |
71 | return Config.memMaxSize; | |
72 | } | |
73 | ||
74 | // TODO: Implement size_t Ipc::Mem::Level() |