]>
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"
17 // Uses a single PagePool instance, for now.
18 // Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
20 // TODO: make pool id more unique so it does not conflict with other Squids?
21 static const char *PagePoolId
= "squid-page-pool";
22 static Ipc::Mem::PagePool
*ThePagePool
= 0;
23 static int TheLimits
[Ipc::Mem::PageId::maxPurpose
];
25 // TODO: make configurable to avoid waste when mem-cached objects are small/big
33 Ipc::Mem::GetPage(const PageId::Purpose purpose
, PageId
&page
)
35 return ThePagePool
&& PagesAvailable(purpose
) > 0 ?
36 ThePagePool
->get(purpose
, page
) : false;
40 Ipc::Mem::PutPage(PageId
&page
)
43 ThePagePool
->put(page
);
47 Ipc::Mem::PagePointer(const PageId
&page
)
50 return ThePagePool
->pagePointer(page
);
57 for (int i
= 0; i
< PageId::maxPurpose
; ++i
)
58 limit
+= PageLimit(i
);
63 Ipc::Mem::PageLimit(const int purpose
)
65 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
66 return TheLimits
[purpose
];
69 // note: adjust this if we start recording needs during reconfigure
71 Ipc::Mem::NotePageNeed(const int purpose
, const int count
)
73 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
75 TheLimits
[purpose
] += count
;
81 return ThePagePool
? ThePagePool
->level() : 0;
85 Ipc::Mem::PageLevel(const int purpose
)
87 return ThePagePool
? ThePagePool
->level(purpose
) : 0;
90 /// initializes shared memory pages
91 class SharedMemPagesRr
: public Ipc::Mem::RegisteredRunner
94 /* RegisteredRunner API */
95 SharedMemPagesRr(): owner(NULL
) {}
96 virtual void run(const RunnerRegistry
&);
97 virtual void create(const RunnerRegistry
&);
98 virtual void open(const RunnerRegistry
&);
99 virtual ~SharedMemPagesRr();
102 Ipc::Mem::PagePool::Owner
*owner
;
105 RunnerRegistrationEntry(rrAfterConfig
, SharedMemPagesRr
);
109 SharedMemPagesRr::run(const RunnerRegistry
&r
)
111 if (Ipc::Mem::PageLimit() <= 0)
114 Ipc::Mem::RegisteredRunner::run(r
);
118 SharedMemPagesRr::create(const RunnerRegistry
&)
121 owner
= Ipc::Mem::PagePool::Init(PagePoolId
, Ipc::Mem::PageLimit(),
122 Ipc::Mem::PageSize());
126 SharedMemPagesRr::open(const RunnerRegistry
&)
129 ThePagePool
= new Ipc::Mem::PagePool(PagePoolId
);
132 SharedMemPagesRr::~SharedMemPagesRr()