Pages.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 54 Interprocess Communication */
10
11#include "squid.h"
13#include "base/TextException.h"
14#include "ipc/mem/PagePool.h"
15#include "ipc/mem/Pages.h"
16#include "tools.h"
17
18// Uses a single PagePool instance, for now.
19// Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
20
21// TODO: make pool id more unique so it does not conflict with other Squids?
22static const char *PagePoolId = "squid-page-pool";
25
26// TODO: make configurable to avoid waste when mem-cached objects are small/big
27size_t
29{
30 return 32*1024;
31}
32
33bool
35{
36 return ThePagePool && PagesAvailable(purpose) > 0 ?
37 ThePagePool->get(purpose, page) : false;
38}
39
40void
42{
44 ThePagePool->put(page);
45}
46
47char *
49{
51 return ThePagePool->pagePointer(page);
52}
53
54size_t
56{
57 size_t limit = 0;
58 for (int i = 0; i <= PageId::maxPurpose; ++i)
59 limit += PageLimit(i);
60 return limit;
61}
62
63size_t
64Ipc::Mem::PageLimit(const int purpose)
65{
66 Must(0 <= purpose && purpose <= PageId::maxPurpose);
67 return TheLimits[purpose];
68}
69
70// note: adjust this if we start recording needs during reconfigure
71void
72Ipc::Mem::NotePageNeed(const int purpose, const int count)
73{
74 Must(0 <= purpose && purpose <= PageId::maxPurpose);
75 Must(count >= 0);
76 TheLimits[purpose] += count;
77}
78
79size_t
81{
82 return ThePagePool ? ThePagePool->level() : 0;
83}
84
85size_t
86Ipc::Mem::PageLevel(const int purpose)
87{
88 return ThePagePool ? ThePagePool->level(purpose) : 0;
89}
90
93{
94public:
95 /* RegisteredRunner API */
96 SharedMemPagesRr(): owner(nullptr) {}
97 void useConfig() override;
98 void create() override;
99 void open() override;
100 ~SharedMemPagesRr() override;
101
102private:
104};
105
107
108void
110{
111 if (Ipc::Mem::PageLimit() <= 0)
112 return;
113
115}
116
117void
119{
120 Must(!owner);
125}
126
127void
129{
132}
133
135{
136 delete ThePagePool;
137 ThePagePool = nullptr;
138 delete owner;
139}
140
DefineRunnerRegistrator(SharedMemPagesRr)
static const char * PagePoolId
Definition: Pages.cc:22
static Ipc::Mem::PagePool * ThePagePool
Definition: Pages.cc:23
static int TheLimits[Ipc::Mem::PageId::maxPurpose+1]
Definition: Pages.cc:24
#define Must(condition)
Definition: TextException.h:75
Shared memory page identifier, address, or handler.
Definition: Page.h:24
char * pagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: PagePool.cc:70
static Owner * Init(const char *const shmId, const Ipc::Mem::PoolId stackId, const unsigned int capacity, const size_t pageSize)
Definition: PagePool.cc:19
size_t level() const
approximate number of shared memory pages used now
Definition: PagePool.h:39
void put(PageId &page)
makes identified page available as a free page to future get() callers
Definition: PagePool.cc:58
bool get(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: PagePool.cc:46
static PoolId IdForMultipurposePool()
multipurpose PagePool of shared memory pages
Definition: PageStack.h:169
void useConfig() override
Definition: Segment.cc:377
initializes shared memory pages
Definition: Pages.cc:93
SharedMemPagesRr()
Definition: Pages.cc:96
Ipc::Mem::PagePool::Owner * owner
Definition: Pages.cc:103
void create() override
called when the runner should create a new memory segment
Definition: Pages.cc:118
~SharedMemPagesRr() override
Definition: Pages.cc:134
void useConfig() override
Definition: Pages.cc:109
void open() override
Definition: Pages.cc:128
size_t PageLevel()
approximate total number of shared memory pages used now
Definition: Pages.cc:80
bool GetPage(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: Pages.cc:34
size_t PagesAvailable()
approximate total number of shared memory pages we can allocate now
Definition: Pages.h:47
size_t PageSize()
returns page size in bytes; all pages are assumed to be the same size
Definition: Pages.cc:28
void NotePageNeed(const int purpose, const int count)
claim the need for a number of pages for a given purpose
Definition: Pages.cc:72
void PutPage(PageId &page)
makes identified page available as a free page to future GetPage() callers
Definition: Pages.cc:41
char * PagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: Pages.cc:48
size_t PageLimit()
the total number of shared memory pages that can be in use at any time
Definition: Pages.cc:55

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors