Pages.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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/RunnersRegistry.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?
22 static const char *PagePoolId = "squid-page-pool";
23 static Ipc::Mem::PagePool *ThePagePool = 0;
25 
26 // TODO: make configurable to avoid waste when mem-cached objects are small/big
27 size_t
29 {
30  return 32*1024;
31 }
32 
33 bool
35 {
36  return ThePagePool && PagesAvailable(purpose) > 0 ?
37  ThePagePool->get(purpose, page) : false;
38 }
39 
40 void
42 {
43  Must(ThePagePool);
44  ThePagePool->put(page);
45 }
46 
47 char *
49 {
50  Must(ThePagePool);
51  return ThePagePool->pagePointer(page);
52 }
53 
54 size_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 
63 size_t
64 Ipc::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
71 void
72 Ipc::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 
79 size_t
81 {
82  return ThePagePool ? ThePagePool->level() : 0;
83 }
84 
85 size_t
86 Ipc::Mem::PageLevel(const int purpose)
87 {
88  return ThePagePool ? ThePagePool->level(purpose) : 0;
89 }
90 
93 {
94 public:
95  /* RegisteredRunner API */
97  virtual void useConfig();
98  virtual void create();
99  virtual void open();
100  virtual ~SharedMemPagesRr();
101 
102 private:
104 };
105 
107 
108 void
110 {
111  if (Ipc::Mem::PageLimit() <= 0)
112  return;
113 
115 }
116 
117 void
119 {
120  Must(!owner);
123 }
124 
125 void
127 {
128  Must(!ThePagePool);
129  ThePagePool = new Ipc::Mem::PagePool(PagePoolId);
130 }
131 
133 {
134  delete ThePagePool;
135  ThePagePool = NULL;
136  delete owner;
137 }
138 
char * PagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: Pages.cc:48
int i
Definition: membanger.c:49
static Owner * Init(const char *const id, const unsigned int capacity, const size_t pageSize)
Definition: PagePool.cc:19
void NotePageNeed(const int purpose, const int count)
claim the need for a number of pages for a given purpose
Definition: Pages.cc:72
SharedMemPagesRr()
Definition: Pages.cc:96
bool GetPage(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: Pages.cc:34
bool get(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: PagePool.cc:44
virtual ~SharedMemPagesRr()
Definition: Pages.cc:132
Ipc::Mem::PagePool::Owner * owner
Definition: Pages.cc:103
static const char * PagePoolId
Definition: Pages.cc:22
RunnerRegistrationEntry(SharedMemPagesRr)
static Ipc::Mem::PagePool * ThePagePool
Definition: Pages.cc:23
void put(PageId &page)
makes identified page available as a free page to future get() callers
Definition: PagePool.cc:56
char * pagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: PagePool.cc:68
size_t PagesAvailable()
approximate total number of shared memory pages we can allocate now
Definition: Pages.h:47
#define Must(cond)
Definition: TextException.h:89
size_t PageSize()
returns page size in bytes; all pages are assumed to be the same size
Definition: Pages.cc:28
virtual void create()
called when the runner should create a new memory segment
Definition: Pages.cc:118
initializes shared memory pages
Definition: Pages.cc:92
virtual void useConfig()
Definition: Segment.cc:376
Shared memory page identifier, address, or handler.
Definition: Page.h:21
size_t PageLevel()
approximate total number of shared memory pages used now
Definition: Pages.cc:80
static int TheLimits[Ipc::Mem::PageId::maxPurpose]
Definition: Pages.cc:24
virtual void useConfig()
Definition: Pages.cc:109
void PutPage(PageId &page)
makes identified page available as a free page to future GetPage() callers
Definition: Pages.cc:41
virtual void open()
Definition: Pages.cc:126
size_t PageLimit()
the total number of shared memory pages that can be in use at any time
Definition: Pages.cc:55
size_t level() const
approximate number of shared memory pages used now
Definition: PagePool.h:39
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors