]>
Commit | Line | Data |
---|---|---|
3e0ddf16 AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 54 Interprocess Communication | |
5 | * | |
6 | */ | |
7 | ||
f7f3304a | 8 | #include "squid.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" |
582c2af2 | 13 | #include "protos.h" |
56f8aa50 DK |
14 | #include "structs.h" |
15 | #include "SwapDir.h" | |
3e0ddf16 | 16 | |
56f8aa50 | 17 | // Uses a single PagePool instance, for now. |
3e0ddf16 | 18 | // Eventually, we may have pools dedicated to memory caching, disk I/O, etc. |
56f8aa50 DK |
19 | |
20 | // TODO: make pool id more unique so it does not conflict with other Squids? | |
a4555399 | 21 | static const char *PagePoolId = "squid-page-pool"; |
56f8aa50 | 22 | static Ipc::Mem::PagePool *ThePagePool = 0; |
ea2cdeb6 | 23 | static int TheLimits[Ipc::Mem::PageId::maxPurpose]; |
56f8aa50 | 24 | |
72261456 | 25 | // TODO: make configurable to avoid waste when mem-cached objects are small/big |
d1ad4017 | 26 | size_t |
9199139f AR |
27 | Ipc::Mem::PageSize() |
28 | { | |
72261456 | 29 | return 32*1024; |
56f8aa50 DK |
30 | } |
31 | ||
56f8aa50 | 32 | bool |
551f8a18 | 33 | Ipc::Mem::GetPage(const PageId::Purpose purpose, PageId &page) |
56f8aa50 | 34 | { |
551f8a18 | 35 | return ThePagePool && PagesAvailable(purpose) > 0 ? |
9199139f | 36 | ThePagePool->get(purpose, page) : false; |
56f8aa50 DK |
37 | } |
38 | ||
39 | void | |
40 | Ipc::Mem::PutPage(PageId &page) | |
41 | { | |
42 | Must(ThePagePool); | |
43 | ThePagePool->put(page); | |
44 | } | |
45 | ||
8ed94021 | 46 | char * |
56f8aa50 DK |
47 | Ipc::Mem::PagePointer(const PageId &page) |
48 | { | |
49 | Must(ThePagePool); | |
50 | return ThePagePool->pagePointer(page); | |
51 | } | |
72261456 AR |
52 | |
53 | size_t | |
e0bdae60 DK |
54 | Ipc::Mem::PageLimit() |
55 | { | |
551f8a18 DK |
56 | size_t limit = 0; |
57 | for (int i = 0; i < PageId::maxPurpose; ++i) | |
58 | limit += PageLimit(i); | |
59 | return limit; | |
e0bdae60 DK |
60 | } |
61 | ||
62 | size_t | |
551f8a18 | 63 | Ipc::Mem::PageLimit(const int purpose) |
72261456 | 64 | { |
ea2cdeb6 DK |
65 | Must(0 <= purpose && purpose <= PageId::maxPurpose); |
66 | return TheLimits[purpose]; | |
67 | } | |
68 | ||
69 | // note: adjust this if we start recording needs during reconfigure | |
70 | void | |
71 | Ipc::Mem::NotePageNeed(const int purpose, const int count) | |
72 | { | |
73 | Must(0 <= purpose && purpose <= PageId::maxPurpose); | |
74 | Must(count >= 0); | |
75 | TheLimits[purpose] += count; | |
e0bdae60 DK |
76 | } |
77 | ||
78 | size_t | |
79 | Ipc::Mem::PageLevel() | |
80 | { | |
551f8a18 | 81 | return ThePagePool ? ThePagePool->level() : 0; |
72261456 AR |
82 | } |
83 | ||
b940ff87 | 84 | size_t |
551f8a18 | 85 | Ipc::Mem::PageLevel(const int purpose) |
b940ff87 | 86 | { |
551f8a18 | 87 | return ThePagePool ? ThePagePool->level(purpose) : 0; |
b940ff87 | 88 | } |
a4555399 AR |
89 | |
90 | /// initializes shared memory pages | |
4404f1c5 | 91 | class SharedMemPagesRr: public Ipc::Mem::RegisteredRunner |
a4555399 AR |
92 | { |
93 | public: | |
94 | /* RegisteredRunner API */ | |
68353d5a | 95 | SharedMemPagesRr(): owner(NULL) {} |
a4555399 | 96 | virtual void run(const RunnerRegistry &); |
4404f1c5 DK |
97 | virtual void create(const RunnerRegistry &); |
98 | virtual void open(const RunnerRegistry &); | |
c011f9bc | 99 | virtual ~SharedMemPagesRr(); |
68353d5a DK |
100 | |
101 | private: | |
102 | Ipc::Mem::PagePool::Owner *owner; | |
a4555399 AR |
103 | }; |
104 | ||
105 | RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr); | |
106 | ||
4404f1c5 DK |
107 | void |
108 | SharedMemPagesRr::run(const RunnerRegistry &r) | |
a4555399 | 109 | { |
ea2cdeb6 | 110 | if (Ipc::Mem::PageLimit() <= 0) |
3f2ac0f7 | 111 | return; |
3f2ac0f7 | 112 | |
4404f1c5 DK |
113 | Ipc::Mem::RegisteredRunner::run(r); |
114 | } | |
68353d5a | 115 | |
4404f1c5 DK |
116 | void |
117 | SharedMemPagesRr::create(const RunnerRegistry &) | |
118 | { | |
119 | Must(!owner); | |
120 | owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(), | |
121 | Ipc::Mem::PageSize()); | |
122 | } | |
123 | ||
124 | void | |
125 | SharedMemPagesRr::open(const RunnerRegistry &) | |
126 | { | |
68353d5a DK |
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 | } |