]>
Commit | Line | Data |
---|---|---|
3e0ddf16 AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 54 Interprocess Communication | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "config.h" | |
56f8aa50 | 9 | #include "base/TextException.h" |
a4555399 | 10 | #include "base/RunnersRegistry.h" |
56f8aa50 | 11 | #include "ipc/mem/PagePool.h" |
3e0ddf16 | 12 | #include "ipc/mem/Pages.h" |
56f8aa50 DK |
13 | #include "structs.h" |
14 | #include "SwapDir.h" | |
3e0ddf16 | 15 | |
56f8aa50 | 16 | // Uses a single PagePool instance, for now. |
3e0ddf16 | 17 | // Eventually, we may have pools dedicated to memory caching, disk I/O, etc. |
56f8aa50 DK |
18 | |
19 | // TODO: make pool id more unique so it does not conflict with other Squids? | |
a4555399 | 20 | static const char *PagePoolId = "squid-page-pool"; |
56f8aa50 DK |
21 | static Ipc::Mem::PagePool *ThePagePool = 0; |
22 | ||
72261456 | 23 | // TODO: make configurable to avoid waste when mem-cached objects are small/big |
d1ad4017 | 24 | size_t |
9199139f AR |
25 | Ipc::Mem::PageSize() |
26 | { | |
72261456 | 27 | return 32*1024; |
56f8aa50 DK |
28 | } |
29 | ||
56f8aa50 | 30 | bool |
551f8a18 | 31 | Ipc::Mem::GetPage(const PageId::Purpose purpose, PageId &page) |
56f8aa50 | 32 | { |
551f8a18 | 33 | return ThePagePool && PagesAvailable(purpose) > 0 ? |
9199139f | 34 | ThePagePool->get(purpose, page) : false; |
56f8aa50 DK |
35 | } |
36 | ||
37 | void | |
38 | Ipc::Mem::PutPage(PageId &page) | |
39 | { | |
40 | Must(ThePagePool); | |
41 | ThePagePool->put(page); | |
42 | } | |
43 | ||
8ed94021 | 44 | char * |
56f8aa50 DK |
45 | Ipc::Mem::PagePointer(const PageId &page) |
46 | { | |
47 | Must(ThePagePool); | |
48 | return ThePagePool->pagePointer(page); | |
49 | } | |
72261456 AR |
50 | |
51 | size_t | |
e0bdae60 DK |
52 | Ipc::Mem::PageLimit() |
53 | { | |
551f8a18 DK |
54 | size_t limit = 0; |
55 | for (int i = 0; i < PageId::maxPurpose; ++i) | |
56 | limit += PageLimit(i); | |
57 | return limit; | |
e0bdae60 DK |
58 | } |
59 | ||
60 | size_t | |
551f8a18 | 61 | Ipc::Mem::PageLimit(const int purpose) |
72261456 | 62 | { |
551f8a18 DK |
63 | switch (purpose) { |
64 | case PageId::cachePage: | |
551f8a18 DK |
65 | return Config.memMaxSize > 0 ? Config.memMaxSize / PageSize() : 0; |
66 | case PageId::ioPage: | |
67 | // XXX: this should be independent from memory cache pages | |
0a11e039 | 68 | return PageLimit(PageId::cachePage)/2; |
551f8a18 DK |
69 | default: |
70 | Must(false); | |
71 | } | |
72 | return 0; | |
e0bdae60 DK |
73 | } |
74 | ||
75 | size_t | |
76 | Ipc::Mem::PageLevel() | |
77 | { | |
551f8a18 | 78 | return ThePagePool ? ThePagePool->level() : 0; |
72261456 AR |
79 | } |
80 | ||
b940ff87 | 81 | size_t |
551f8a18 | 82 | Ipc::Mem::PageLevel(const int purpose) |
b940ff87 | 83 | { |
551f8a18 | 84 | return ThePagePool ? ThePagePool->level(purpose) : 0; |
b940ff87 | 85 | } |
a4555399 AR |
86 | |
87 | /// initializes shared memory pages | |
88 | class SharedMemPagesRr: public RegisteredRunner | |
89 | { | |
90 | public: | |
91 | /* RegisteredRunner API */ | |
68353d5a | 92 | SharedMemPagesRr(): owner(NULL) {} |
a4555399 | 93 | virtual void run(const RunnerRegistry &); |
c011f9bc | 94 | virtual ~SharedMemPagesRr(); |
68353d5a DK |
95 | |
96 | private: | |
97 | Ipc::Mem::PagePool::Owner *owner; | |
a4555399 AR |
98 | }; |
99 | ||
100 | RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr); | |
101 | ||
102 | ||
103 | void SharedMemPagesRr::run(const RunnerRegistry &) | |
104 | { | |
60be8b2d AR |
105 | if (!UsingSmp()) |
106 | return; | |
a4555399 | 107 | |
9fbeec6b AR |
108 | // When cache_dirs start using shared memory pages, they would |
109 | // need to communicate their needs to us somehow. | |
e0bdae60 | 110 | if (Config.memMaxSize <= 0) |
9fbeec6b AR |
111 | return; |
112 | ||
551f8a18 | 113 | if (Ipc::Mem::PageLimit() <= 0) { |
3f2ac0f7 DK |
114 | if (IamMasterProcess()) { |
115 | debugs(54, DBG_IMPORTANT, "WARNING: mem-cache size is too small (" | |
e0bdae60 | 116 | << (Config.memMaxSize / 1024.0) << " KB), should be >= " << |
3f2ac0f7 DK |
117 | (Ipc::Mem::PageSize() / 1024.0) << " KB"); |
118 | } | |
119 | return; | |
120 | } | |
121 | ||
826e236d | 122 | if (IamMasterProcess()) { |
68353d5a | 123 | Must(!owner); |
551f8a18 | 124 | owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(), Ipc::Mem::PageSize()); |
68353d5a DK |
125 | } |
126 | ||
127 | Must(!ThePagePool); | |
128 | ThePagePool = new Ipc::Mem::PagePool(PagePoolId); | |
a4555399 | 129 | } |
c011f9bc DK |
130 | |
131 | SharedMemPagesRr::~SharedMemPagesRr() | |
132 | { | |
60be8b2d AR |
133 | if (!UsingSmp()) |
134 | return; | |
135 | ||
c011f9bc | 136 | delete ThePagePool; |
282ee641 | 137 | ThePagePool = NULL; |
68353d5a | 138 | delete owner; |
c011f9bc | 139 | } |