]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/Pages.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 54 Interprocess Communication */
12 #include "base/RunnersRegistry.h"
13 #include "base/TextException.h"
14 #include "ipc/mem/PagePool.h"
15 #include "ipc/mem/Pages.h"
18 // Uses a single PagePool instance, for now.
19 // Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
21 // TODO: make pool id more unique so it does not conflict with other Squids?
22 static const char *PagePoolId
= "squid-page-pool";
23 static Ipc::Mem::PagePool
*ThePagePool
= 0;
24 static int TheLimits
[Ipc::Mem::PageId::maxPurpose
];
26 // TODO: make configurable to avoid waste when mem-cached objects are small/big
34 Ipc::Mem::GetPage(const PageId::Purpose purpose
, PageId
&page
)
36 return ThePagePool
&& PagesAvailable(purpose
) > 0 ?
37 ThePagePool
->get(purpose
, page
) : false;
41 Ipc::Mem::PutPage(PageId
&page
)
44 ThePagePool
->put(page
);
48 Ipc::Mem::PagePointer(const PageId
&page
)
51 return ThePagePool
->pagePointer(page
);
58 for (int i
= 0; i
< PageId::maxPurpose
; ++i
)
59 limit
+= PageLimit(i
);
64 Ipc::Mem::PageLimit(const int purpose
)
66 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
67 return TheLimits
[purpose
];
70 // note: adjust this if we start recording needs during reconfigure
72 Ipc::Mem::NotePageNeed(const int purpose
, const int count
)
74 Must(0 <= purpose
&& purpose
<= PageId::maxPurpose
);
76 TheLimits
[purpose
] += count
;
82 return ThePagePool
? ThePagePool
->level() : 0;
86 Ipc::Mem::PageLevel(const int purpose
)
88 return ThePagePool
? ThePagePool
->level(purpose
) : 0;
91 /// initializes shared memory pages
92 class SharedMemPagesRr
: public Ipc::Mem::RegisteredRunner
95 /* RegisteredRunner API */
96 SharedMemPagesRr(): owner(NULL
) {}
97 virtual void useConfig();
98 virtual void create();
100 virtual ~SharedMemPagesRr();
103 Ipc::Mem::PagePool::Owner
*owner
;
106 RunnerRegistrationEntry(SharedMemPagesRr
);
109 SharedMemPagesRr::useConfig()
111 if (Ipc::Mem::PageLimit() <= 0)
114 Ipc::Mem::RegisteredRunner::useConfig();
118 SharedMemPagesRr::create()
121 owner
= Ipc::Mem::PagePool::Init(PagePoolId
, Ipc::Mem::PageLimit(),
122 Ipc::Mem::PageSize());
126 SharedMemPagesRr::open()
129 ThePagePool
= new Ipc::Mem::PagePool(PagePoolId
);
132 SharedMemPagesRr::~SharedMemPagesRr()