MemStore.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 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 20 Memory Cache */
10 
11 #include "squid.h"
12 #include "base/RunnersRegistry.h"
13 #include "CollapsedForwarding.h"
14 #include "HttpReply.h"
15 #include "ipc/mem/Page.h"
16 #include "ipc/mem/Pages.h"
17 #include "MemObject.h"
18 #include "MemStore.h"
19 #include "mime_header.h"
20 #include "sbuf/SBuf.h"
21 #include "sbuf/Stream.h"
22 #include "SquidConfig.h"
23 #include "SquidMath.h"
24 #include "store/forward.h"
25 #include "StoreStats.h"
26 #include "tools.h"
27 
29 static const auto MapLabel = "cache_mem_map";
31 static const char *SpaceLabel = "cache_mem_space";
33 static const char *ExtrasLabel = "cache_mem_ex";
34 // TODO: sync with Rock::SwapDir::*Path()
35 
38 class ShmWriter: public Packable
39 {
40 public:
41  ShmWriter(MemStore &aStore, StoreEntry *anEntry, const sfileno aFileNo, Ipc::StoreMapSliceId aFirstSlice = -1);
42 
43  /* Packable API */
44  void append(const char *aBuf, int aSize) override;
45  void vappendf(const char *fmt, va_list ap) override;
46 
47 public:
49 
53 
56 
57  uint64_t totalWritten;
58 
59 protected:
60  void copyToShm();
62 
63 private:
65  const sfileno fileNo;
66 
67  /* set by (and only valid during) append calls */
68  const char *buf;
69  int bufSize;
70  int bufWritten;
71 };
72 
73 /* ShmWriter */
74 
75 ShmWriter::ShmWriter(MemStore &aStore, StoreEntry *anEntry, const sfileno aFileNo, Ipc::StoreMapSliceId aFirstSlice):
76  entry(anEntry),
77  firstSlice(aFirstSlice),
78  lastSlice(firstSlice),
79  totalWritten(0),
80  store(aStore),
81  fileNo(aFileNo),
82  buf(nullptr),
83  bufSize(0),
84  bufWritten(0)
85 {
86  Must(entry);
87 }
88 
89 void
90 ShmWriter::append(const char *aBuf, int aBufSize)
91 {
92  Must(!buf);
93  buf = aBuf;
94  bufSize = aBufSize;
95  if (bufSize) {
96  Must(buf);
97  bufWritten = 0;
98  copyToShm();
99  }
100  buf = nullptr;
101  bufSize = 0;
102  bufWritten = 0;
103 }
104 
105 void
106 ShmWriter::vappendf(const char *fmt, va_list ap)
107 {
108  SBuf vaBuf;
109  va_list apCopy;
110  va_copy(apCopy, ap);
111  vaBuf.vappendf(fmt, apCopy);
112  va_end(apCopy);
113  append(vaBuf.rawContent(), vaBuf.length());
114 }
115 
117 void
119 {
120  Must(bufSize > 0); // do not use up shared memory pages for nothing
121  Must(firstSlice < 0 || lastSlice >= 0);
122 
123  // fill, skip slices that are already full
124  while (bufWritten < bufSize) {
126  if (firstSlice < 0)
128  copyToShmSlice(slice);
129  }
130 
131  debugs(20, 7, "stored " << bufWritten << '/' << totalWritten << " header bytes of " << *entry);
132 }
133 
135 void
137 {
139  debugs(20, 7, "entry " << *entry << " slice " << lastSlice << " has " <<
140  page);
141 
142  Must(bufWritten <= bufSize);
143  const int64_t writingDebt = bufSize - bufWritten;
144  const int64_t pageSize = Ipc::Mem::PageSize();
145  const int64_t sliceOffset = totalWritten % pageSize;
146  const int64_t copySize = std::min(writingDebt, pageSize - sliceOffset);
147  memcpy(static_cast<char*>(PagePointer(page)) + sliceOffset, buf + bufWritten,
148  copySize);
149 
150  debugs(20, 7, "copied " << slice.size << '+' << copySize << " bytes of " <<
151  entry << " from " << sliceOffset << " in " << page);
152 
153  slice.size += copySize;
154  bufWritten += copySize;
155  totalWritten += copySize;
156  // fresh anchor.basics.swap_file_sz is already set [to the stale value]
157 
158  // either we wrote everything or we filled the entire slice
159  Must(bufWritten == bufSize || sliceOffset + copySize == pageSize);
160 }
161 
162 /* MemStore */
163 
164 MemStore::MemStore(): map(nullptr), lastWritingSlice(-1)
165 {
166 }
167 
169 {
170  delete map;
171 }
172 
173 void
175 {
176  const int64_t entryLimit = EntryLimit();
177  if (entryLimit <= 0)
178  return; // no shared memory cache configured or a misconfiguration
179 
180  // check compatibility with the disk cache, if any
181  if (Config.cacheSwap.n_configured > 0) {
182  const int64_t diskMaxSize = Store::Root().maxObjectSize();
183  const int64_t memMaxSize = maxObjectSize();
184  if (diskMaxSize == -1) {
185  debugs(20, DBG_IMPORTANT, "WARNING: disk-cache maximum object size "
186  "is unlimited but mem-cache maximum object size is " <<
187  memMaxSize / 1024.0 << " KB");
188  } else if (diskMaxSize > memMaxSize) {
189  debugs(20, DBG_IMPORTANT, "WARNING: disk-cache maximum object size "
190  "is too large for mem-cache: " <<
191  diskMaxSize / 1024.0 << " KB > " <<
192  memMaxSize / 1024.0 << " KB");
193  }
194  }
195 
198 
199  Must(!map);
200  map = new MemStoreMap(SBuf(MapLabel));
201  map->cleaner = this;
202 }
203 
204 void
206 {
207  const size_t pageSize = Ipc::Mem::PageSize();
208 
209  stats.mem.shared = true;
210  stats.mem.capacity =
212  stats.mem.size =
214  stats.mem.count = currentCount();
215 }
216 
217 void
219 {
220  storeAppendPrintf(&e, "\n\nShared Memory Cache\n");
221 
222  storeAppendPrintf(&e, "Maximum Size: %.0f KB\n", maxSize()/1024.0);
223  storeAppendPrintf(&e, "Current Size: %.2f KB %.2f%%\n",
224  currentSize() / 1024.0,
226 
227  if (map) {
228  const int entryLimit = map->entryLimit();
229  const int slotLimit = map->sliceLimit();
230  storeAppendPrintf(&e, "Maximum entries: %9d\n", entryLimit);
231  if (entryLimit > 0) {
232  storeAppendPrintf(&e, "Current entries: %" PRId64 " %.2f%%\n",
233  currentCount(), (100.0 * currentCount() / entryLimit));
234  }
235 
236  storeAppendPrintf(&e, "Maximum slots: %9d\n", slotLimit);
237  if (slotLimit > 0) {
238  const unsigned int slotsFree =
240  if (slotsFree <= static_cast<unsigned int>(slotLimit)) {
241  const int usedSlots = slotLimit - static_cast<int>(slotsFree);
242  storeAppendPrintf(&e, "Used slots: %9d %.2f%%\n",
243  usedSlots, (100.0 * usedSlots / slotLimit));
244  }
245 
246  if (slotLimit < 100) { // XXX: otherwise too expensive to count
248  map->updateStats(stats);
249  stats.dump(e);
250  }
251  }
252  }
253 }
254 
255 void
257 {
258 }
259 
260 uint64_t
262 {
263  return 0; // XXX: irrelevant, but Store parent forces us to implement this
264 }
265 
266 uint64_t
268 {
269  return Config.memMaxSize;
270 }
271 
272 uint64_t
274 {
277 }
278 
279 uint64_t
281 {
282  return map ? map->entryCount() : 0;
283 }
284 
285 int64_t
287 {
289 }
290 
291 void
293 {
294 }
295 
296 bool
298 {
299  // no need to keep e in the global store_table for us; we have our own map
300  return false;
301 }
302 
303 StoreEntry *
305 {
306  if (!map)
307  return nullptr;
308 
309  sfileno index;
310  const Ipc::StoreMapAnchor *const slot = map->openForReading(key, index);
311  if (!slot)
312  return nullptr;
313 
314  // create a brand new store entry and initialize it with stored info
315  StoreEntry *e = new StoreEntry();
316 
317  try {
318  // XXX: We do not know the URLs yet, only the key, but we need to parse and
319  // store the response for the Root().find() callers to be happy because they
320  // expect IN_MEMORY entries to already have the response headers and body.
321  e->createMemObject();
322 
323  anchorEntry(*e, index, *slot);
324 
325  // TODO: make copyFromShm() throw on all failures, simplifying this code
326  if (copyFromShm(*e, index, *slot))
327  return e;
328  debugs(20, 3, "failed for " << *e);
329  } catch (...) {
330  // see store_client::parseHttpHeadersFromDisk() for problems this may log
331  debugs(20, DBG_IMPORTANT, "ERROR: Cannot load a cache hit from shared memory" <<
332  Debug::Extra << "exception: " << CurrentException <<
333  Debug::Extra << "cache_mem entry: " << *e);
334  }
335 
336  map->freeEntry(index); // do not let others into the same trap
337  destroyStoreEntry(static_cast<hash_link *>(e));
338  return nullptr;
339 }
340 
341 void
343 {
344  if (!map)
345  return;
346 
347  Ipc::StoreMapUpdate update(updatedE);
348  assert(updatedE);
349  assert(updatedE->mem_obj);
350  if (!map->openForUpdating(update, updatedE->mem_obj->memCache.index))
351  return;
352 
353  try {
354  updateHeadersOrThrow(update);
355  } catch (const std::exception &ex) {
356  debugs(20, 2, "error starting to update entry " << *updatedE << ": " << ex.what());
357  map->abortUpdating(update);
358  }
359 }
360 
361 void
363 {
364  // our +/- hdr_sz math below does not work if the chains differ [in size]
366 
367  const uint64_t staleHdrSz = update.entry->mem().baseReply().hdr_sz;
368  debugs(20, 7, "stale hdr_sz: " << staleHdrSz);
369 
370  /* we will need to copy same-slice payload after the stored headers later */
371  Must(staleHdrSz > 0);
372  update.stale.splicingPoint = map->sliceContaining(update.stale.fileNo, staleHdrSz);
373  Must(update.stale.splicingPoint >= 0);
374  Must(update.stale.anchor->basics.swap_file_sz >= staleHdrSz);
375 
376  Must(update.stale.anchor);
377  ShmWriter writer(*this, update.entry, update.fresh.fileNo);
379  const uint64_t freshHdrSz = writer.totalWritten;
380  debugs(20, 7, "fresh hdr_sz: " << freshHdrSz << " diff: " << (freshHdrSz - staleHdrSz));
381 
382  /* copy same-slice payload remaining after the stored headers */
383  const Ipc::StoreMapSlice &slice = map->readableSlice(update.stale.fileNo, update.stale.splicingPoint);
384  const Ipc::StoreMapSlice::Size sliceCapacity = Ipc::Mem::PageSize();
385  const Ipc::StoreMapSlice::Size headersInLastSlice = staleHdrSz % sliceCapacity;
386  Must(headersInLastSlice > 0); // or sliceContaining() would have stopped earlier
387  Must(slice.size >= headersInLastSlice);
388  const Ipc::StoreMapSlice::Size payloadInLastSlice = slice.size - headersInLastSlice;
389  const MemStoreMapExtras::Item &extra = extras->items[update.stale.splicingPoint];
390  char *page = static_cast<char*>(PagePointer(extra.page));
391  debugs(20, 5, "appending same-slice payload: " << payloadInLastSlice);
392  writer.append(page + headersInLastSlice, payloadInLastSlice);
393  update.fresh.splicingPoint = writer.lastSlice;
394 
395  update.fresh.anchor->basics.swap_file_sz -= staleHdrSz;
396  update.fresh.anchor->basics.swap_file_sz += freshHdrSz;
397 
398  map->closeForUpdating(update);
399 }
400 
401 bool
403 {
404  Assure(!entry.hasMemStore());
405  Assure(entry.mem().memCache.io != Store::ioDone);
406 
407  if (!map)
408  return false;
409 
410  sfileno index;
411  const Ipc::StoreMapAnchor *const slot = map->openForReading(
412  reinterpret_cast<cache_key*>(entry.key), index);
413  if (!slot)
414  return false;
415 
416  anchorEntry(entry, index, *slot);
417  if (!updateAnchoredWith(entry, index, *slot))
418  throw TextException("updateAnchoredWith() failure", Here());
419  return true;
420 }
421 
422 bool
424 {
425  if (!map)
426  return false;
427 
428  assert(entry.mem_obj);
429  assert(entry.hasMemStore());
430  const sfileno index = entry.mem_obj->memCache.index;
431  const Ipc::StoreMapAnchor &anchor = map->readableEntry(index);
432  return updateAnchoredWith(entry, index, anchor);
433 }
434 
436 bool
438 {
439  entry.swap_file_sz = anchor.basics.swap_file_sz;
440  const bool copied = copyFromShm(entry, index, anchor);
441  return copied;
442 }
443 
445 void
447 {
448  assert(!e.hasDisk()); // no conflict with disk entry basics
449  anchor.exportInto(e);
450 
451  assert(e.mem_obj);
452  if (anchor.complete()) {
456  } else {
458  assert(e.mem_obj->object_sz < 0);
460  }
461 
463 
465  mc.index = index;
466  mc.io = Store::ioReading;
467 }
468 
470 bool
472 {
473  debugs(20, 7, "mem-loading entry " << index << " from " << anchor.start);
474  assert(e.mem_obj);
475 
476  // emulate the usual Store code but w/o inapplicable checks and callbacks:
477 
478  Ipc::StoreMapSliceId sid = anchor.start; // optimize: remember the last sid
479  bool wasEof = anchor.complete() && sid < 0;
480  int64_t sliceOffset = 0;
481 
482  SBuf httpHeaderParsingBuffer;
483  while (sid >= 0) {
484  const Ipc::StoreMapSlice &slice = map->readableSlice(index, sid);
485  // slice state may change during copying; take snapshots now
486  wasEof = anchor.complete() && slice.next < 0;
487  const Ipc::StoreMapSlice::Size wasSize = slice.size;
488 
489  debugs(20, 8, "entry " << index << " slice " << sid << " eof " <<
490  wasEof << " wasSize " << wasSize << " <= " <<
491  anchor.basics.swap_file_sz << " sliceOffset " << sliceOffset <<
492  " mem.endOffset " << e.mem_obj->endOffset());
493 
494  if (e.mem_obj->endOffset() < sliceOffset + wasSize) {
495  // size of the slice data that we already copied
496  const size_t prefixSize = e.mem_obj->endOffset() - sliceOffset;
497  assert(prefixSize <= wasSize);
498 
499  const MemStoreMapExtras::Item &extra = extras->items[sid];
500 
501  char *page = static_cast<char*>(PagePointer(extra.page));
502  const StoreIOBuffer sliceBuf(wasSize - prefixSize,
503  e.mem_obj->endOffset(),
504  page + prefixSize);
505 
506  copyFromShmSlice(e, sliceBuf);
507  debugs(20, 8, "entry " << index << " copied slice " << sid <<
508  " from " << extra.page << '+' << prefixSize);
509 
510  // parse headers if needed; they might span multiple slices!
511  if (!e.hasParsedReplyHeader()) {
512  httpHeaderParsingBuffer.append(sliceBuf.data, sliceBuf.length);
513  auto &reply = e.mem().adjustableBaseReply();
514  if (reply.parseTerminatedPrefix(httpHeaderParsingBuffer.c_str(), httpHeaderParsingBuffer.length()))
515  httpHeaderParsingBuffer = SBuf(); // we do not need these bytes anymore
516  }
517  }
518  // else skip a [possibly incomplete] slice that we copied earlier
519 
520  // careful: the slice may have grown _and_ gotten the next slice ID!
521  if (slice.next >= 0) {
522  assert(!wasEof);
523  // here we know that slice.size may not change any more
524  if (wasSize >= slice.size) { // did not grow since we started copying
525  sliceOffset += wasSize;
526  sid = slice.next;
527  }
528  } else if (wasSize >= slice.size) { // did not grow
529  break;
530  }
531  }
532 
533  if (!wasEof) {
534  debugs(20, 7, "mem-loaded " << e.mem_obj->endOffset() << '/' <<
535  anchor.basics.swap_file_sz << " bytes of " << e);
536  return true;
537  }
538 
539  if (anchor.writerHalted) {
540  debugs(20, 5, "mem-loaded aborted " << e.mem_obj->endOffset() << '/' <<
541  anchor.basics.swap_file_sz << " bytes of " << e);
542  return false;
543  }
544 
545  debugs(20, 5, "mem-loaded all " << e.mem_obj->endOffset() << '/' <<
546  anchor.basics.swap_file_sz << " bytes of " << e);
547 
548  if (!e.hasParsedReplyHeader())
549  throw TextException(ToSBuf("truncated mem-cached headers; accumulated: ", httpHeaderParsingBuffer.length()), Here());
550 
551  // from StoreEntry::complete()
555 
556  assert(e.mem_obj->object_sz >= 0);
557  assert(static_cast<uint64_t>(e.mem_obj->object_sz) == anchor.basics.swap_file_sz);
558  // would be nice to call validLength() here, but it needs e.key
559 
560  // we read the entire response into the local memory; no more need to lock
561  disconnect(e);
562  return true;
563 }
564 
566 void
568 {
569  debugs(20, 7, "buf: " << buf.offset << " + " << buf.length);
570 
571  // local memory stores both headers and body so copy regardless of pstate
572  const int64_t offBefore = e.mem_obj->endOffset();
573  assert(e.mem_obj->data_hdr.write(buf)); // from MemObject::write()
574  const int64_t offAfter = e.mem_obj->endOffset();
575  // expect to write the entire buf because StoreEntry::write() never fails
576  assert(offAfter >= 0 && offBefore <= offAfter &&
577  static_cast<size_t>(offAfter - offBefore) == buf.length);
578 }
579 
581 bool
583 {
584  if (e.mem_status == IN_MEMORY) {
585  debugs(20, 5, "already loaded from mem-cache: " << e);
586  return false;
587  }
588 
589  if (e.mem_obj && e.mem_obj->memCache.offset > 0) {
590  debugs(20, 5, "already written to mem-cache: " << e);
591  return false;
592  }
593 
594  if (shutting_down) {
595  debugs(20, 5, "avoid heavy optional work during shutdown: " << e);
596  return false;
597  }
598 
599  // To avoid SMP workers releasing each other caching attempts, restrict disk
600  // caching to StoreEntry publisher. This check goes before memoryCachable()
601  // that may incorrectly release() publisher's entry via checkCachable().
602  if (Store::Root().transientsReader(e)) {
603  debugs(20, 5, "yield to entry publisher: " << e);
604  return false;
605  }
606 
607  if (!e.memoryCachable()) {
608  debugs(20, 7, "Not memory cachable: " << e);
609  return false; // will not cache due to entry state or properties
610  }
611 
612  assert(e.mem_obj);
613 
614  if (!e.mem_obj->vary_headers.isEmpty()) {
615  // XXX: We must store/load SerialisedMetaData to cache Vary in RAM
616  debugs(20, 5, "Vary not yet supported: " << e.mem_obj->vary_headers);
617  return false;
618  }
619 
620  const int64_t expectedSize = e.mem_obj->expectedReplySize(); // may be < 0
621  const int64_t loadedSize = e.mem_obj->endOffset();
622  const int64_t ramSize = max(loadedSize, expectedSize);
623  if (ramSize > maxObjectSize()) {
624  debugs(20, 5, "Too big max(" <<
625  loadedSize << ", " << expectedSize << "): " << e);
626  return false; // will not cache due to cachable entry size limits
627  }
628 
629  if (!e.mem_obj->isContiguous()) {
630  debugs(20, 5, "not contiguous");
631  return false;
632  }
633 
634  if (!map) {
635  debugs(20, 5, "No map to mem-cache " << e);
636  return false;
637  }
638 
639  if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) {
640  debugs(20, 5, "Not mem-caching ENTRY_SPECIAL " << e);
641  return false;
642  }
643 
644  return true;
645 }
646 
648 bool
650 {
651  sfileno index = 0;
652  Ipc::StoreMapAnchor *slot = map->openForWriting(reinterpret_cast<const cache_key *>(e.key), index);
653  if (!slot) {
654  debugs(20, 5, "No room in mem-cache map to index " << e);
655  return false;
656  }
657 
658  assert(e.mem_obj);
659  e.mem_obj->memCache.index = index;
661  slot->set(e);
662  // Do not allow others to feed off an unknown-size entry because we will
663  // stop swapping it out if it grows too large.
664  if (e.mem_obj->expectedReplySize() >= 0)
665  map->startAppending(index);
666  e.memOutDecision(true);
667  return true;
668 }
669 
671 void
673 {
674  assert(map);
675  assert(e.mem_obj);
677 
678  const int64_t eSize = e.mem_obj->endOffset();
679  if (e.mem_obj->memCache.offset >= eSize) {
680  debugs(20, 5, "postponing copying " << e << " for lack of news: " <<
681  e.mem_obj->memCache.offset << " >= " << eSize);
682  return; // nothing to do (yet)
683  }
684 
685  // throw if an accepted unknown-size entry grew too big or max-size changed
686  Must(eSize <= maxObjectSize());
687 
688  const int32_t index = e.mem_obj->memCache.index;
689  assert(index >= 0);
690  Ipc::StoreMapAnchor &anchor = map->writeableEntry(index);
691  lastWritingSlice = anchor.start;
692 
693  // fill, skip slices that are already full
694  // Optimize: remember lastWritingSlice in e.mem_obj
695  while (e.mem_obj->memCache.offset < eSize) {
698  if (anchor.start < 0)
699  anchor.start = lastWritingSlice;
700  copyToShmSlice(e, anchor, slice);
701  }
702 
703  debugs(20, 7, "mem-cached available " << eSize << " bytes of " << e);
704 }
705 
707 void
709 {
711  debugs(20, 7, "entry " << e << " slice " << lastWritingSlice << " has " <<
712  page);
713 
714  const int64_t bufSize = Ipc::Mem::PageSize();
715  const int64_t sliceOffset = e.mem_obj->memCache.offset % bufSize;
716  StoreIOBuffer sharedSpace(bufSize - sliceOffset, e.mem_obj->memCache.offset,
717  static_cast<char*>(PagePointer(page)) + sliceOffset);
718 
719  // check that we kept everything or purge incomplete/sparse cached entry
720  const ssize_t copied = e.mem_obj->data_hdr.copy(sharedSpace);
721  if (copied <= 0) {
722  debugs(20, 2, "Failed to mem-cache " << (bufSize - sliceOffset) <<
723  " bytes of " << e << " from " << e.mem_obj->memCache.offset <<
724  " in " << page);
725  throw TexcHere("data_hdr.copy failure");
726  }
727 
728  debugs(20, 7, "mem-cached " << copied << " bytes of " << e <<
729  " from " << e.mem_obj->memCache.offset << " in " << page);
730 
731  slice.size += copied;
732  e.mem_obj->memCache.offset += copied;
734 }
735 
739 MemStore::nextAppendableSlice(const sfileno fileNo, sfileno &sliceOffset)
740 {
741  // allocate the very first slot for the entry if needed
742  if (sliceOffset < 0) {
743  Ipc::StoreMapAnchor &anchor = map->writeableEntry(fileNo);
744  Must(anchor.start < 0);
745  Ipc::Mem::PageId page;
746  sliceOffset = reserveSapForWriting(page); // throws
747  extras->items[sliceOffset].page = page;
748  anchor.start = sliceOffset;
749  }
750 
751  const size_t sliceCapacity = Ipc::Mem::PageSize();
752  do {
753  Ipc::StoreMap::Slice &slice = map->writeableSlice(fileNo, sliceOffset);
754 
755  if (slice.size >= sliceCapacity) {
756  if (slice.next >= 0) {
757  sliceOffset = slice.next;
758  continue;
759  }
760 
761  Ipc::Mem::PageId page;
762  slice.next = sliceOffset = reserveSapForWriting(page);
763  extras->items[sliceOffset].page = page;
764  debugs(20, 7, "entry " << fileNo << " new slice: " << sliceOffset);
765  continue; // to get and return the slice at the new sliceOffset
766  }
767 
768  return slice;
769  } while (true);
770  /* not reached */
771 }
772 
776 {
777  Must(extras);
778  Must(sliceId >= 0);
779  Ipc::Mem::PageId page = extras->items[sliceId].page;
780  Must(page);
781  return page;
782 }
783 
785 sfileno
787 {
788  Ipc::Mem::PageId slot;
789  if (freeSlots->pop(slot)) {
790  const auto slotId = slot.number - 1;
791  debugs(20, 5, "got a previously free slot: " << slotId);
792 
794  debugs(20, 5, "and got a previously free page: " << page);
795  map->prepFreeSlice(slotId);
796  return slotId;
797  } else {
798  debugs(20, 3, "but there is no free page, returning " << slotId);
799  freeSlots->push(slot);
800  }
801  }
802 
803  // catch free slots delivered to noteFreeMapSlice()
804  assert(!waitingFor);
805  waitingFor.slot = &slot;
806  waitingFor.page = &page;
807  if (map->purgeOne()) {
808  assert(!waitingFor); // noteFreeMapSlice() should have cleared it
809  assert(slot.set());
810  assert(page.set());
811  const auto slotId = slot.number - 1;
812  map->prepFreeSlice(slotId);
813  debugs(20, 5, "got previously busy " << slotId << " and " << page);
814  return slotId;
815  }
816  assert(waitingFor.slot == &slot && waitingFor.page == &page);
817  waitingFor.slot = nullptr;
818  waitingFor.page = nullptr;
819 
820  debugs(47, 3, "cannot get a slice; entries: " << map->entryCount());
821  throw TexcHere("ran out of mem-cache slots");
822 }
823 
824 void
826 {
827  Ipc::Mem::PageId &pageId = extras->items[sliceId].page;
828  debugs(20, 9, "slice " << sliceId << " freed " << pageId);
829  assert(pageId);
830  Ipc::Mem::PageId slotId;
832  slotId.number = sliceId + 1;
833  if (!waitingFor) {
834  // must zero pageId before we give slice (and pageId extras!) to others
835  Ipc::Mem::PutPage(pageId);
836  freeSlots->push(slotId);
837  } else {
838  *waitingFor.slot = slotId;
839  *waitingFor.page = pageId;
840  waitingFor.slot = nullptr;
841  waitingFor.page = nullptr;
842  pageId = Ipc::Mem::PageId();
843  }
844 }
845 
846 void
848 {
849  assert(e.mem_obj);
850 
851  debugs(20, 7, "entry " << e);
852 
853  switch (e.mem_obj->memCache.io) {
854  case Store::ioUndecided:
855  if (!shouldCache(e) || !startCaching(e)) {
857  e.memOutDecision(false);
858  return;
859  }
860  break;
861 
862  case Store::ioDone:
863  case Store::ioReading:
864  return; // we should not write in all of the above cases
865 
866  case Store::ioWriting:
867  break; // already decided to write and still writing
868  }
869 
870  try {
871  copyToShm(e);
872  if (e.store_status == STORE_OK) // done receiving new content
873  completeWriting(e);
874  else
876  return;
877  } catch (const std::exception &x) { // TODO: should we catch ... as well?
878  debugs(20, 2, "mem-caching error writing entry " << e << ": " << x.what());
879  // fall through to the error handling code
880  }
881 
882  disconnect(e);
883 }
884 
885 void
887 {
888  assert(e.mem_obj);
889  const int32_t index = e.mem_obj->memCache.index;
890  assert(index >= 0);
891  assert(map);
892 
893  debugs(20, 5, "mem-cached all " << e.mem_obj->memCache.offset << " bytes of " << e);
894 
895  e.mem_obj->memCache.index = -1;
897  map->closeForWriting(index);
898 
900  e.storeWriterDone();
901 }
902 
903 void
905 {
906  debugs(47, 5, e);
907  if (e.hasMemStore()) {
910  if (!e.locked()) {
911  disconnect(e);
912  e.destroyMemObject();
913  }
914  } else if (const auto key = e.publicKey()) {
915  // the entry may have been loaded and then disconnected from the cache
916  evictIfFound(key);
917  if (!e.locked())
918  e.destroyMemObject();
919  }
920 }
921 
922 void
924 {
925  if (map)
926  map->freeEntryByKey(key);
927 }
928 
929 void
931 {
932  assert(e.mem_obj);
933  MemObject &mem_obj = *e.mem_obj;
934  if (e.hasMemStore()) {
935  if (mem_obj.memCache.io == Store::ioWriting) {
936  map->abortWriting(mem_obj.memCache.index);
937  mem_obj.memCache.index = -1;
938  mem_obj.memCache.io = Store::ioDone;
940  e.storeWriterDone();
941  } else {
942  assert(mem_obj.memCache.io == Store::ioReading);
943  map->closeForReading(mem_obj.memCache.index);
944  mem_obj.memCache.index = -1;
945  mem_obj.memCache.io = Store::ioDone;
946  }
947  }
948 }
949 
950 bool
952 {
953  return Config.memShared && Config.memMaxSize > 0;
954 }
955 
957 int64_t
959 {
960  if (!Requested())
961  return 0;
962 
963  const int64_t minEntrySize = Ipc::Mem::PageSize();
964  const int64_t entryLimit = Config.memMaxSize / minEntrySize;
965  return entryLimit;
966 }
967 
972 {
973 public:
974  /* RegisteredRunner API */
975  MemStoreRr(): spaceOwner(nullptr), mapOwner(nullptr), extrasOwner(nullptr) {}
976  void finalizeConfig() override;
977  void claimMemoryNeeds() override;
978  void useConfig() override;
979  ~MemStoreRr() override;
980 
981 protected:
982  /* Ipc::Mem::RegisteredRunner API */
983  void create() override;
984 
985 private:
989 };
990 
992 
993 void
995 {
997 }
998 
999 void
1001 {
1002  // decide whether to use a shared memory cache if the user did not specify
1003  if (!Config.memShared.configured()) {
1005  Config.memMaxSize > 0);
1006  } else if (Config.memShared && !Ipc::Mem::Segment::Enabled()) {
1007  fatal("memory_cache_shared is on, but no support for shared memory detected");
1008  } else if (Config.memShared && !UsingSmp()) {
1009  debugs(20, DBG_IMPORTANT, "WARNING: memory_cache_shared is on, but only"
1010  " a single worker is running");
1011  }
1012 
1014  debugs(20, DBG_IMPORTANT, "WARNING: mem-cache size is too small (" <<
1015  (Config.memMaxSize / 1024.0) << " KB), should be >= " <<
1016  (Ipc::Mem::PageSize() / 1024.0) << " KB");
1017  }
1018 }
1019 
1020 void
1022 {
1025 }
1026 
1027 void
1029 {
1030  if (!MemStore::Enabled())
1031  return;
1032 
1033  const int64_t entryLimit = MemStore::EntryLimit();
1034  assert(entryLimit > 0);
1035 
1036  Ipc::Mem::PageStack::Config spaceConfig;
1038  spaceConfig.pageSize = 0; // the pages are stored in Ipc::Mem::Pages
1039  spaceConfig.capacity = entryLimit;
1040  spaceConfig.createFull = true; // all pages are initially available
1041  Must(!spaceOwner);
1043  Must(!mapOwner);
1044  mapOwner = MemStoreMap::Init(SBuf(MapLabel), entryLimit);
1045  Must(!extrasOwner);
1047 }
1048 
1050 {
1051  delete extrasOwner;
1052  delete mapOwner;
1053  delete spaceOwner;
1054 }
1055 
Anchor & writeableEntry(const AnchorId anchorId)
writeable anchor for the entry created by openForWriting()
Definition: StoreMap.cc:238
bool updateAnchored(StoreEntry &) override
Definition: MemStore.cc:423
int hdr_sz
Definition: Message.h:81
void fatal(const char *message)
Definition: fatal.cc:28
uint64_t totalWritten
cumulative number of bytes appended so far
Definition: MemStore.cc:57
void freeEntryByKey(const cache_key *const key)
Definition: StoreMap.cc:331
HttpReply & adjustableBaseReply()
Definition: MemObject.cc:121
ShmWriter(MemStore &aStore, StoreEntry *anEntry, const sfileno aFileNo, Ipc::StoreMapSliceId aFirstSlice=-1)
Definition: MemStore.cc:75
void updateHeaders(StoreEntry *e) override
make stored metadata and HTTP headers the same as in the given entry
Definition: MemStore.cc:342
Ipc::StoreMap MemStoreMap
Definition: MemStore.h:23
#define Here()
source code location of the caller
Definition: Here.h:15
approximate stats of a set of ReadWriteLocks
Definition: ReadWriteLock.h:70
uint32_t poolId
pool ID
Definition: PageStack.h:125
void closeForWriting(const sfileno fileno)
successfully finish creating or updating the entry at fileno pos
Definition: StoreMap.cc:201
void startAppending(const sfileno fileno)
restrict opened for writing entry to appending operations; allow reads
Definition: StoreMap.cc:192
void append(const char *aBuf, int aSize) override
Appends a c-string to existing packed data.
Definition: MemStore.cc:90
bool startCaching(StoreEntry &e)
locks map anchor and preps to store the entry in shared memory
Definition: MemStore.cc:649
MemStore()
Definition: MemStore.cc:164
const cache_key * publicKey() const
Definition: Store.h:112
StoreEntry * get(const cache_key *) override
Definition: MemStore.cc:304
unsigned char cache_key
Store key.
Definition: forward.h:29
static bool Enabled()
whether Squid is correctly configured to use a shared memory cache
Definition: MemStore.h:68
static const auto MapLabel
shared memory segment path to use for MemStore maps
Definition: MemStore.cc:29
#define EBIT_SET(flag, bit)
Definition: defines.h:65
bool isEmpty() const
Definition: SBuf.h:435
double count
number of cached objects
Definition: StoreStats.h:21
MemObject * mem_obj
Definition: Store.h:220
mem_hdr data_hdr
Definition: MemObject.h:148
void finalizeConfig() override
Definition: MemStore.cc:1000
size_t memMaxSize
Definition: SquidConfig.h:91
void createMemObject()
Definition: store.cc:1575
PoolId pool
Definition: Page.h:39
int bufWritten
buf bytes appended so far
Definition: MemStore.cc:70
MemObject & mem()
Definition: Store.h:47
SBuf & vappendf(const char *fmt, va_list vargs)
Definition: SBuf.cc:239
Shared memory page identifier, address, or handler.
Definition: Page.h:23
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:855
int64_t offset
bytes written/read to/from the memory cache so far
Definition: MemObject.h:199
@ ENTRY_VALIDATED
Definition: enums.h:108
static PoolId IdForMemStoreSpace()
stack of free cache_mem slot positions
Definition: PageStack.h:167
void stat(StoreEntry &e) const override
Definition: MemStore.cc:218
void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: MemStore.cc:256
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:203
int64_t offset
Definition: StoreIOBuffer.h:58
Definition: SBuf.h:93
sfileno lastWritingSlice
the last allocate slice for writing a store entry (during copyToShm)
Definition: MemStore.h:106
void set(const StoreEntry &anEntry, const cache_key *aKey=nullptr)
store StoreEntry key and basics for an inode slot
Definition: StoreMap.cc:959
int64_t expectedReplySize() const
Definition: MemObject.cc:238
Edition fresh
new anchor and the updated chain prefix
Definition: StoreMap.h:209
void create() override
called when the runner should create a new memory segment
Definition: MemStore.cc:1028
bool isContiguous() const
Definition: MemObject.cc:406
SliceId sliceContaining(const sfileno fileno, const uint64_t nth) const
Definition: StoreMap.cc:421
bool anchorToCache(StoreEntry &) override
Definition: MemStore.cc:402
double capacity
the size limit
Definition: StoreStats.h:22
const A & max(A const &lhs, A const &rhs)
uint64_t currentSize() const override
current size
Definition: MemStore.cc:273
uint16_t flags
Definition: Store.h:231
void packHeadersUsingSlowPacker(Packable &p) const
same as packHeadersUsingFastPacker() but assumes that p cannot quickly process small additions
Definition: HttpReply.cc:95
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:423
bool write(StoreIOBuffer const &)
Definition: stmem.cc:303
int64_t endOffset() const
Definition: MemObject.cc:214
void push(PageId &page)
makes value available as a free page number to future pop() callers
Definition: PageStack.cc:465
#define shm_new(Class)
Definition: Pointer.h:200
static const char * SpaceLabel
shared memory segment path to use for the free slices index
Definition: MemStore.cc:31
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
Definition: StoreMap.cc:751
MemStore & store
Definition: MemStore.cc:64
void prepFreeSlice(const SliceId sliceId)
prepare a chain-unaffiliated slice for being added to an entry chain
Definition: StoreMap.cc:413
uint64_t minSize() const override
the minimum size the store will shrink to via normal housekeeping
Definition: MemStore.cc:261
void destroyMemObject()
Definition: store.cc:386
static Owner * Init(const SBuf &path, const int slotLimit)
initialize shared memory
Definition: StoreMap.cc:43
std::atomic< uint8_t > writerHalted
whether StoreMap::abortWriting() was called for a read-locked entry
Definition: StoreMap.h:83
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:63
std::atomic< StoreMapSliceId > start
where the chain of StoreEntry slices begins [app]
Definition: StoreMap.h:111
double size
bytes currently in use
Definition: StoreStats.h:20
void getStats(StoreInfoStats &stats) const override
collect statistics
Definition: MemStore.cc:205
static bool Requested()
Definition: MemStore.cc:951
void closeForUpdating(Update &update)
makes updated info available to others, unlocks, and cleans up
Definition: StoreMap.cc:605
uint64_t maxSize() const override
Definition: MemStore.cc:267
const sfileno fileNo
Definition: MemStore.cc:65
double doublePercent(const double, const double)
Definition: SquidMath.cc:25
const Anchor * openForReading(const cache_key *const key, sfileno &fileno)
opens entry (identified by key) for reading, increments read level
Definition: StoreMap.cc:440
SlotAndPage waitingFor
a cache for a single "hot" free slot and page
Definition: MemStore.h:117
std::atomic< StoreMapSliceId > next
ID of the next entry slice.
Definition: StoreMap.h:49
struct Ipc::StoreMapAnchor::Basics basics
void memOutDecision(const bool willCacheInRam)
Definition: store.cc:1791
void configure(bool beSet)
enables or disables the option; updating to 'configured' state
Definition: YesNoNone.h:53
void copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor, Ipc::StoreMap::Slice &slice)
copies at most one slice worth of local memory to shared memory
Definition: MemStore.cc:708
const char * rawContent() const
Definition: SBuf.cc:509
const Anchor & readableEntry(const AnchorId anchorId) const
readable anchor for the entry created by openForReading()
Definition: StoreMap.cc:245
void claimMemoryNeeds() override
Definition: MemStore.cc:994
MemStoreMap::Owner * mapOwner
primary map Owner
Definition: MemStore.cc:987
void copyToShm(StoreEntry &e)
copies all local data to shared memory
Definition: MemStore.cc:672
void evictIfFound(const cache_key *) override
Definition: MemStore.cc:923
SBuf vary_headers
Definition: MemObject.h:221
@ IN_MEMORY
Definition: enums.h:31
void NotePageNeed(const int purpose, const int count)
claim the need for a number of pages for a given purpose
Definition: Pages.cc:72
const HttpReply & baseReply() const
Definition: MemObject.h:60
@ ENTRY_FWD_HDR_WAIT
Definition: enums.h:106
int entryLimit() const
maximum entryCount() possible
Definition: StoreMap.cc:733
int32_t StoreMapSliceId
Definition: StoreMap.h:24
void completeWriting(StoreEntry &e)
all data has been received; there will be no more write() calls
Definition: MemStore.cc:886
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition: store.cc:1929
Edition stale
old anchor and chain
Definition: StoreMap.h:208
Mem mem
all cache_dirs stats
Definition: StoreStats.h:48
static const char * ExtrasLabel
shared memory segment path to use for IDs of shared pages with slice data
Definition: MemStore.cc:33
int sliceLimit() const
maximum number of slices possible
Definition: StoreMap.cc:745
#define EBIT_TEST(flag, bit)
Definition: defines.h:67
DefineRunnerRegistrator(MemStoreRr)
bool set() const
true if and only if both critical components have been initialized
Definition: Page.h:29
void closeForReading(const sfileno fileno)
closes open entry after reading, decrements read level
Definition: StoreMap.cc:497
@ ioDone
Definition: forward.h:40
~MemStore() override
Definition: MemStore.cc:168
bool hasMemStore() const
whether there is a corresponding locked shared memory table entry
Definition: Store.h:212
StoreEntry * entry
the store entry being updated
Definition: StoreMap.h:207
#define shm_old(Class)
Definition: Pointer.h:201
Ipc::Mem::Owner< MemStoreMapExtras > * extrasOwner
PageIds Owner.
Definition: MemStore.cc:988
struct SquidConfig::@95 Store
store_status_t store_status
Definition: Store.h:243
#define assert(EX)
Definition: assert.h:17
uint64_t currentCount() const override
the total number of objects stored right now
Definition: MemStore.cc:280
void evictCached(StoreEntry &) override
Definition: MemStore.cc:904
YesNoNone memShared
whether the memory cache is shared among workers
Definition: SquidConfig.h:89
void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override
adjust slice-linked state before a locked Readable slice is erased
Definition: MemStore.cc:825
FREE destroyStoreEntry
@ NOT_IN_MEMORY
Definition: enums.h:30
std::atomic< uint64_t > swap_file_sz
Definition: StoreMap.h:105
size_t PageLevel()
approximate total number of shared memory pages used now
Definition: Pages.cc:80
int entryCount() const
number of writeable and readable entries
Definition: StoreMap.cc:739
~MemStoreRr() override
Definition: MemStore.cc:1049
void PutPage(PageId &page)
makes identified page available as a free page to future GetPage() callers
Definition: Pages.cc:41
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:181
Store::IoStatus io
current I/O state
Definition: MemObject.h:201
bool configured() const
Definition: YesNoNone.h:67
#define Assure(condition)
Definition: Assure.h:35
StoreMapAnchor * anchor
StoreMap::anchors[fileNo], for convenience/speed.
Definition: StoreMap.h:193
void dump(StoreEntry &e) const
mem_status_t mem_status
Definition: Store.h:239
const char * c_str()
Definition: SBuf.cc:516
bool complete() const
Definition: StoreMap.h:77
void useConfig() override
Definition: Segment.cc:377
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:419
@ STORE_OK
Definition: enums.h:45
void copyToShm()
copies the entire buffer to shared memory
Definition: MemStore.cc:118
Anchor * openForWriting(const cache_key *const key, sfileno &fileno)
Definition: StoreMap.cc:141
size_t maxInMemObjSize
Definition: SquidConfig.h:268
void anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
anchors StoreEntry to an already locked map entry
Definition: MemStore.cc:446
static std::ostream & Extra(std::ostream &)
Definition: debug.cc:1316
SBuf & append(const SBuf &S)
Definition: SBuf.cc:185
signed_int32_t sfileno
Definition: forward.h:22
bool freeEntry(const sfileno)
Definition: StoreMap.cc:313
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
unused map slot IDs
Definition: MemStore.h:99
sfileno reserveSapForWriting(Ipc::Mem::PageId &page)
finds a slot and a free page to fill or throws
Definition: MemStore.cc:786
size_t pageSize
page size, used to calculate shared memory size
Definition: PageStack.h:126
void setMemStatus(mem_status_t)
Definition: store.cc:1524
static bool Enabled()
Whether shared memory support is available.
Definition: Segment.cc:322
StoreEntry * entry
the entry being updated
Definition: MemStore.cc:48
Ipc::StoreMapSliceId lastSlice
the slot keeping the last byte of the appended content (at least)
Definition: MemStore.cc:55
bool pop(PageId &page)
sets value and returns true unless no free page numbers are found
Definition: PageStack.cc:442
MemStoreMap * map
index of mem-cached entries
Definition: MemStore.h:100
void exportInto(StoreEntry &) const
load StoreEntry basics that were previously stored with set()
Definition: StoreMap.cc:979
ssize_t copy(StoreIOBuffer const &) const
Definition: stmem.cc:187
void init() override
Definition: MemStore.cc:174
StoreMapSliceId splicingPoint
the last slice in the chain still containing metadata/headers
Definition: StoreMap.h:198
const Slice & readableSlice(const AnchorId anchorId, const SliceId sliceId) const
readable slice within an entry chain opened by openForReading()
Definition: StoreMap.cc:230
char * PagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: Pages.cc:48
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
Definition: MemStore.cc:362
int32_t index
entry position inside the memory cache
Definition: MemObject.h:198
uint32_t number
page number within the segment
Definition: Page.h:42
sfileno fileNo
StoreMap::fileNos[name], for convenience/speed.
Definition: StoreMap.h:194
int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: Controller.cc:181
size_t PageLimit()
the total number of shared memory pages that can be in use at any time
Definition: Pages.cc:55
bool shared
whether memory cache is shared among workers
Definition: StoreStats.h:42
bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
copies the entire entry from shared to local memory
Definition: MemStore.cc:471
Ipc::Mem::Owner< Ipc::Mem::PageStack > * spaceOwner
free slices Owner
Definition: MemStore.cc:986
bool GetPage(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: Pages.cc:34
Ipc::Mem::PageId * slot
local slot variable, waiting to be filled
Definition: MemStore.h:114
PageStack construction and SharedMemorySize calculation parameters.
Definition: PageStack.h:123
void write(StoreEntry &e)
copy non-shared entry data of the being-cached entry to our cache
Definition: MemStore.cc:847
StoreMapCleaner * cleaner
notified before a readable entry is freed
Definition: StoreMap.h:361
void copyFromShmSlice(StoreEntry &, const StoreIOBuffer &)
imports one shared memory slice into local memory
Definition: MemStore.cc:567
an std::runtime_error with thrower location info
Definition: TextException.h:20
static int64_t EntryLimit()
calculates maximum number of entries we need to store and map
Definition: MemStore.cc:958
@ ioUndecided
Definition: forward.h:40
bool purgeOne()
either finds and frees an entry with at least 1 slice or returns false
Definition: StoreMap.cc:702
int64_t object_sz
Definition: MemObject.h:215
int bufSize
buf size
Definition: MemStore.cc:69
State of an entry with regards to the [shared] memory caching.
Definition: MemObject.h:195
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63
bool dereference(StoreEntry &e) override
Definition: MemStore.cc:297
#define Must(condition)
Definition: TextException.h:75
uint64_t swap_file_sz
Definition: Store.h:229
@ ENTRY_SPECIAL
Definition: enums.h:79
#define DBG_IMPORTANT
Definition: Stream.h:38
bool createFull
whether a newly created PageStack should be prefilled with PageIds
Definition: PageStack.h:130
Ipc::StoreMap::Slice & nextAppendableSlice(const sfileno entryIndex, sfileno &sliceOffset)
Definition: MemStore.cc:739
bool updateAnchoredWith(StoreEntry &, const sfileno, const Ipc::StoreMapAnchor &)
updates Transients entry after its anchor has been located
Definition: MemStore.cc:437
#define PRId64
Definition: types.h:104
const HttpReply & freshestReply() const
Definition: MemObject.h:68
void abortWriting(const sfileno fileno)
stop writing the entry, freeing its slot for others to use if possible
Definition: StoreMap.cc:252
Ipc::Mem::PageId pageForSlice(Ipc::StoreMapSliceId sliceId)
safely returns a previously allocated memory page for the given entry slice
Definition: MemStore.cc:775
int shutting_down
const char * buf
content being appended now
Definition: MemStore.cc:68
bool memoryCachable()
checkCachable() and can be cached in memory
Definition: store.cc:1276
size_t PagesAvailable()
approximate total number of shared memory pages we can allocate now
Definition: Pages.h:47
PageCount capacity
the maximum number of pages
Definition: PageStack.h:127
size_t PageSize()
returns page size in bytes; all pages are assumed to be the same size
Definition: Pages.cc:28
void vappendf(const char *fmt, va_list ap) override
Definition: MemStore.cc:106
static void Broadcast(const StoreEntry &e, const bool includingThisWorker=false)
notify other workers about changes in entry state (e.g., new data)
std::atomic< Size > size
slice contents size
Definition: StoreMap.h:48
int locked() const
Definition: Store.h:145
void useConfig() override
Definition: MemStore.cc:1021
@ ioWriting
Definition: forward.h:40
bool hasParsedReplyHeader() const
whether this entry has access to [deserialized] [HTTP] response headers
Definition: store.cc:231
bool UsingSmp()
Whether there should be more than one worker process running.
Definition: tools.cc:696
void copyToShmSlice(Ipc::StoreMap::Slice &slice)
copies at most one slice worth of buffer to shared memory
Definition: MemStore.cc:136
Ipc::StoreMapSliceId firstSlice
Definition: MemStore.cc:52
void disconnect(StoreEntry &e)
called when the entry is about to forget its association with mem cache
Definition: MemStore.cc:930
Ipc::Mem::PageId * page
local page variable, waiting to be filled
Definition: MemStore.h:115
void storeWriterDone()
called when a store writer ends its work (successfully or not)
Definition: store.cc:1808
void abortUpdating(Update &update)
undoes partial update, unlocks, and cleans up
Definition: StoreMap.cc:269
bool openForUpdating(Update &update, sfileno fileNoHint)
finds and locks the Update entry for an exclusive metadata update
Definition: StoreMap.cc:523
@ ioReading
Definition: forward.h:40
Ipc::Mem::Pointer< Extras > extras
IDs of pages with slice data.
Definition: MemStore.h:103
void reference(StoreEntry &e) override
somebody needs this entry (many cache replacement policies need to know)
Definition: MemStore.cc:292
uint32_t Size
Definition: StoreMap.h:31
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
const A & min(A const &lhs, A const &rhs)
aggregates anchor and slice owners for Init() caller convenience
Definition: StoreMap.h:232
bool shouldCache(StoreEntry &e) const
whether we should cache the entry
Definition: MemStore.cc:582
int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: MemStore.cc:286
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:13
class SquidConfig Config
Definition: SquidConfig.cc:12
Slice & writeableSlice(const AnchorId anchorId, const SliceId sliceId)
writeable slice within an entry chain created by openForWriting()
Definition: StoreMap.cc:222
@ STORE_PENDING
Definition: enums.h:46
Controller & Root()
safely access controller singleton
Definition: Controller.cc:926

 

Introduction

Documentation

Support

Miscellaneous