PagePool.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"
12#include "base/TextException.h"
13#include "ipc/mem/Page.h"
14#include "ipc/mem/PagePool.h"
15
16// Ipc::Mem::PagePool
17
19Ipc::Mem::PagePool::Init(const char *const shmId, const Ipc::Mem::PoolId stackId, const unsigned int capacity, const size_t pageSize)
20{
21 PageStack::Config config;
22 config.poolId = stackId;
23 config.pageSize = pageSize; // the pages are stored in Ipc::Mem::Pages
24 config.capacity = capacity;
25 config.createFull = true; // all pages are initially available
26 return shm_new(PageStack)(shmId, config);
27}
28
29Ipc::Mem::PagePool::PagePool(const char *const id):
30 pageIndex(shm_old(PageStack)(id)),
31 theLevels(reinterpret_cast<Levels_t *>(
32 reinterpret_cast<char *>(pageIndex.getRaw()) +
33 pageIndex->stackSize() + pageIndex->levelsPaddingSize())),
34 theBuf(reinterpret_cast<char *>(theLevels + PageId::maxPurpose))
35{
36}
37
38size_t
39Ipc::Mem::PagePool::level(const int purpose) const
40{
41 Must(0 <= purpose && purpose < PageId::maxPurpose);
42 return theLevels[purpose];
43}
44
45bool
47{
48 Must(0 <= purpose && purpose < PageId::maxPurpose);
49 if (pageIndex->pop(page)) {
50 page.purpose = purpose;
51 ++theLevels[purpose];
52 return true;
53 }
54 return false;
55}
56
57void
59{
60 if (!page)
61 return;
62
63 Must(0 <= page.purpose && page.purpose < PageId::maxPurpose);
64 --theLevels[page.purpose];
66 return pageIndex->push(page);
67}
68
69char *
71{
72 Must(pageIndex->pageIdIsValid(page));
73 return theBuf + pageSize() * (page.number - 1);
74}
75
#define shm_new(Class)
Definition: Pointer.h:200
#define shm_old(Class)
Definition: Pointer.h:201
#define Must(condition)
Definition: TextException.h:75
Shared memory page identifier, address, or handler.
Definition: Page.h:24
uint32_t number
page number within the segment
Definition: Page.h:42
Purpose purpose
page purpose
Definition: Page.h:45
char * pagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: PagePool.cc:70
size_t pageSize() const
Definition: PagePool.h:35
PageStack::Levels_t Levels_t
Definition: PagePool.h:52
PagePool(const char *const id)
Definition: PagePool.cc:29
unsigned int capacity() const
Definition: PagePool.h:34
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
PageStack construction and SharedMemorySize calculation parameters.
Definition: PageStack.h:123
PageCount capacity
the maximum number of pages
Definition: PageStack.h:127
uint32_t poolId
pool ID
Definition: PageStack.h:125
size_t pageSize
page size, used to calculate shared memory size
Definition: PageStack.h:126
bool createFull
whether a newly created PageStack should be prefilled with PageIds
Definition: PageStack.h:130
uint32_t PoolId
Definition: forward.h:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors