Controller.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 Store Controller */
10 
11 #include "squid.h"
12 #include "mem_node.h"
13 #include "MemStore.h"
14 #include "profiler/Profiler.h"
15 #include "SquidConfig.h"
16 #include "SquidMath.h"
17 #include "store/Controller.h"
18 #include "store/Disks.h"
19 #include "store/LocalSearch.h"
20 #include "tools.h"
21 #include "Transients.h"
22 
23 #if HAVE_SYS_WAIT_H
24 #include <sys/wait.h>
25 #endif
26 
27 /*
28  * store_dirs_rebuilding is initialized to _1_ as a hack so that
29  * storeDirWriteCleanLogs() doesn't try to do anything unless _all_
30  * cache_dirs have been read. For example, without this hack, Squid
31  * will try to write clean log files if -kparse fails (becasue it
32  * calls fatal()).
33  */
35 
37  swapDir(new Disks),
38  sharedMemStore(nullptr),
39  localMemStore(false),
40  transients(NULL)
41 {
43 }
44 
46 {
47  delete sharedMemStore;
48  delete transients;
49  delete swapDir;
50 
51  if (store_table) {
54  store_table = nullptr;
55  }
56 }
57 
58 void
60 {
61  if (IamWorkerProcess()) {
62  if (MemStore::Enabled()) {
63  sharedMemStore = new MemStore;
64  sharedMemStore->init();
65  } else if (Config.memMaxSize > 0) {
66  localMemStore = true;
67  }
68  }
69 
70  swapDir->init();
71 
73  transients = new Transients;
74  transients->init();
75  }
76 }
77 
78 void
80 {
81  swapDir->create();
82 
83 #if !_SQUID_WINDOWS_
84  pid_t pid;
85  do {
86  PidStatus status;
87  pid = WaitForAnyPid(status, WNOHANG);
88  } while (pid > 0 || (pid < 0 && errno == EINTR));
89 #endif
90 }
91 
92 void
94 {
95  static time_t last_warn_time = 0;
96 
97  PROF_start(storeMaintainSwapSpace);
98  swapDir->maintain();
99 
100  /* this should be emitted by the oversize dir, not globally */
101 
102  if (Root().currentSize() > Store::Root().maxSize()) {
103  if (squid_curtime - last_warn_time > 10) {
104  debugs(20, DBG_CRITICAL, "WARNING: Disk space over limit: "
105  << Store::Root().currentSize() / 1024.0 << " KB > "
106  << (Store::Root().maxSize() >> 10) << " KB");
107  last_warn_time = squid_curtime;
108  }
109  }
110 
111  PROF_stop(storeMaintainSwapSpace);
112 }
113 
114 void
116 {
117  if (sharedMemStore)
118  sharedMemStore->getStats(stats);
119  else {
120  // move this code to a non-shared memory cache class when we have it
121  stats.mem.shared = false;
122  stats.mem.capacity = Config.memMaxSize;
123  stats.mem.size = mem_node::StoreMemSize();
124  if (localMemStore) {
125  // XXX: also count internal/in-transit objects
126  stats.mem.count = hot_obj_count;
127  } else {
128  // XXX: count internal/in-transit objects instead
129  stats.mem.count = hot_obj_count;
130  }
131  }
132 
133  swapDir->getStats(stats);
134 
135  // low-level info not specific to memory or disk cache
138 }
139 
140 void
142 {
143  storeAppendPrintf(&output, "Store Directory Statistics:\n");
144  storeAppendPrintf(&output, "Store Entries : %lu\n",
145  (unsigned long int)StoreEntry::inUseCount());
146  storeAppendPrintf(&output, "Maximum Swap Size : %" PRIu64 " KB\n",
147  maxSize() >> 10);
148  storeAppendPrintf(&output, "Current Store Swap Size: %.2f KB\n",
149  currentSize() / 1024.0);
150  storeAppendPrintf(&output, "Current Capacity : %.2f%% used, %.2f%% free\n",
151  Math::doublePercent(currentSize(), maxSize()),
152  Math::doublePercent((maxSize() - currentSize()), maxSize()));
153 
154  if (sharedMemStore)
155  sharedMemStore->stat(output);
156 
157  /* now the swapDir */
158  swapDir->stat(output);
159 }
160 
161 /* if needed, this could be taught to cache the result */
162 uint64_t
164 {
165  /* TODO: include memory cache ? */
166  return swapDir->maxSize();
167 }
168 
169 uint64_t
171 {
172  /* TODO: include memory cache ? */
173  return swapDir->minSize();
174 }
175 
176 uint64_t
178 {
179  /* TODO: include memory cache ? */
180  return swapDir->currentSize();
181 }
182 
183 uint64_t
185 {
186  /* TODO: include memory cache ? */
187  return swapDir->currentCount();
188 }
189 
190 int64_t
192 {
193  /* TODO: include memory cache ? */
194  return swapDir->maxObjectSize();
195 }
196 
197 void
199 {
200  swapDir->updateLimits();
201 
202  store_swap_high = (long) (((float) maxSize() *
203  (float) Config.Swap.highWaterMark) / (float) 100);
204  store_swap_low = (long) (((float) maxSize() *
205  (float) Config.Swap.lowWaterMark) / (float) 100);
207 
208  // TODO: move this into a memory cache class when we have one
209  const int64_t memMax = static_cast<int64_t>(min(Config.Store.maxInMemObjSize, Config.memMaxSize));
210  const int64_t disksMax = swapDir ? swapDir->maxObjectSize() : 0;
211  store_maxobjsize = std::max(disksMax, memMax);
212 }
213 
214 StoreSearch *
216 {
217  // this is the only kind of search we currently support
218  return NewLocalSearch();
219 }
220 
221 void
223 {
224  if (sharedMemStore)
225  sharedMemStore->sync();
226  swapDir->sync();
227 }
228 
229 /*
230  * handle callbacks all avaliable fs'es
231  */
232 int
234 {
235  /* This will likely double count. Thats ok. */
236  PROF_start(storeDirCallback);
237 
238  /* mem cache callbacks ? */
239  int result = swapDir->callback();
240 
241  PROF_stop(storeDirCallback);
242 
243  return result;
244 }
245 
247 void
249 {
250  // special entries do not belong to any specific Store, but are IN_MEMORY
251  if (EBIT_TEST(e.flags, ENTRY_SPECIAL))
252  return;
253 
254  /* Notify the fs that we're referencing this object again */
255 
256  if (e.hasDisk())
257  swapDir->reference(e);
258 
259  // Notify the memory cache that we're referencing this object again
260  if (sharedMemStore && e.mem_status == IN_MEMORY)
261  sharedMemStore->reference(e);
262 
263  // TODO: move this code to a non-shared memory cache class when we have it
264  if (e.mem_obj) {
265  if (mem_policy->Referenced)
267  }
268 }
269 
272 bool
274 {
275  // special entries do not belong to any specific Store, but are IN_MEMORY
276  if (EBIT_TEST(e.flags, ENTRY_SPECIAL))
277  return true;
278 
279  bool keepInStoreTable = false; // keep only if somebody needs it there
280 
281  /* Notify the fs that we're not referencing this object any more */
282 
283  if (e.hasDisk())
284  keepInStoreTable = swapDir->dereference(e) || keepInStoreTable;
285 
286  // Notify the memory cache that we're not referencing this object any more
287  if (sharedMemStore && e.mem_status == IN_MEMORY)
288  keepInStoreTable = sharedMemStore->dereference(e) || keepInStoreTable;
289 
290  // TODO: move this code to a non-shared memory cache class when we have it
291  if (e.mem_obj) {
294  // non-shared memory cache relies on store_table
295  if (localMemStore)
296  keepInStoreTable = wantsLocalMemory || keepInStoreTable;
297  }
298 
299  return keepInStoreTable;
300 }
301 
302 bool
304 {
305  // assuming a public key, checking Transients should cover all cases.
306  return transients && transients->markedForDeletion(key);
307 }
308 
309 bool
311 {
312  // The opposite check order could miss a reader that has arrived after the
313  // !readers() and before the markedForDeletion() check.
314  return markedForDeletion(reinterpret_cast<const cache_key*>(e.key)) &&
315  transients && !transients->readers(e);
316 }
317 
318 bool
320 {
321  return swapDir->hasReadableEntry(e);
322 }
323 
324 StoreEntry *
326 {
327  if (const auto entry = peek(key)) {
328  try {
329  if (!entry->key)
330  allowSharing(*entry, key);
331  checkTransients(*entry);
332  entry->touch();
333  referenceBusy(*entry);
334  return entry;
335  } catch (const std::exception &ex) {
336  debugs(20, 2, "failed with " << *entry << ": " << ex.what());
337  entry->release(true);
338  // fall through
339  }
340  }
341  return NULL;
342 }
343 
345 void
347 {
348  // TODO: refactor to throw on anchorToCache() inSync errors!
349 
350  // anchorToCache() below and many find() callers expect a registered entry
351  addReading(&entry, key);
352 
353  if (entry.hasTransients()) {
354  bool inSync = false;
355  const bool found = anchorToCache(entry, inSync);
356  if (found && !inSync)
357  throw TexcHere("cannot sync");
358  }
359 }
360 
361 StoreEntry *
363 {
364  // We could check for mem_obj presence (and more), moving and merging some
365  // of the duplicated neighborsUdpAck() and neighborsHtcpReply() code here,
366  // but that would mean polluting Store with HTCP/ICP code. Instead, we
367  // should encapsulate callback-related data in a protocol-neutral MemObject
368  // member or use an HTCP/ICP-specific index rather than store_table.
369 
370  // cannot reuse peekAtLocal() because HTCP/ICP callbacks may use private keys
371  return static_cast<StoreEntry*>(hash_lookup(store_table, key));
372 }
373 
377 StoreEntry *
379 {
380  if (StoreEntry *e = static_cast<StoreEntry*>(hash_lookup(store_table, key))) {
381  // callers must only search for public entries
382  assert(!EBIT_TEST(e->flags, KEY_PRIVATE));
383  assert(e->publicKey());
384  checkTransients(*e);
385 
386  // TODO: ignore and maybe handleIdleEntry() unlocked intransit entries
387  // because their backing store slot may be gone already.
388  return e;
389  }
390  return nullptr;
391 }
392 
393 StoreEntry *
395 {
396  debugs(20, 3, storeKeyText(key));
397 
398  if (markedForDeletion(key)) {
399  debugs(20, 3, "ignoring marked in-transit " << storeKeyText(key));
400  return nullptr;
401  }
402 
403  if (StoreEntry *e = peekAtLocal(key)) {
404  debugs(20, 3, "got local in-transit entry: " << *e);
405  return e;
406  }
407 
408  // Must search transients before caches because we must sync those we find.
409  if (transients) {
410  if (StoreEntry *e = transients->get(key)) {
411  debugs(20, 3, "got shared in-transit entry: " << *e);
412  return e;
413  }
414  }
415 
416  if (sharedMemStore) {
417  if (StoreEntry *e = sharedMemStore->get(key)) {
418  debugs(20, 3, HERE << "got mem-cached entry: " << *e);
419  return e;
420  }
421  }
422 
423  if (swapDir) {
424  if (StoreEntry *e = swapDir->get(key)) {
425  debugs(20, 3, "got disk-cached entry: " << *e);
426  return e;
427  }
428  }
429 
430  debugs(20, 4, "cannot locate " << storeKeyText(key));
431  return nullptr;
432 }
433 
434 bool
436 {
437  return transients && e.hasTransients() && transients->isReader(e);
438 }
439 
440 bool
442 {
443  return transients && e.hasTransients() && transients->isWriter(e);
444 }
445 
446 int64_t
448 {
449  return swapDir ? swapDir->accumulateMore(entry) : 0;
450  // The memory cache should not influence for-swapout accumulation decision.
451 }
452 
453 // Must be called from StoreEntry::release() or releaseRequest() because
454 // those methods currently manage local indexing of StoreEntry objects.
455 // TODO: Replace StoreEntry::release*() with Root().evictCached().
456 void
458 {
459  debugs(20, 7, e);
460  if (transients)
461  transients->evictCached(e);
462  memoryEvictCached(e);
463  if (swapDir)
464  swapDir->evictCached(e);
465 }
466 
467 void
469 {
470  debugs(20, 7, storeKeyText(key));
471 
472  if (StoreEntry *entry = peekAtLocal(key)) {
473  debugs(20, 5, "marking local in-transit " << *entry);
474  entry->release(true);
475  return;
476  }
477 
478  if (sharedMemStore)
479  sharedMemStore->evictIfFound(key);
480  if (swapDir)
481  swapDir->evictIfFound(key);
482  if (transients)
483  transients->evictIfFound(key);
484 }
485 
487 bool
488 Store::Controller::memoryCacheHasSpaceFor(const int pagesRequired) const
489 {
490  // XXX: We count mem_nodes but may free shared memory pages instead.
491  const auto fits = mem_node::InUseCount() + pagesRequired <= store_pages_max;
492  debugs(20, 7, fits << ": " << mem_node::InUseCount() << '+' << pagesRequired << '?' << store_pages_max);
493  return fits;
494 }
495 
496 void
497 Store::Controller::freeMemorySpace(const int bytesRequired)
498 {
499  const auto pagesRequired = (bytesRequired + SM_PAGE_SIZE-1) / SM_PAGE_SIZE;
500 
501  if (memoryCacheHasSpaceFor(pagesRequired))
502  return;
503 
504  // XXX: When store_pages_max is smaller than pagesRequired, we should not
505  // look for more space (but we do because we want to abandon idle entries?).
506 
507  // limit our performance impact to one walk per second
508  static time_t lastWalk = 0;
509  if (lastWalk == squid_curtime)
510  return;
511  lastWalk = squid_curtime;
512 
513  debugs(20, 2, "need " << pagesRequired << " pages");
514 
515  // let abandon()/handleIdleEntry() know about the impeding memory shortage
516  memoryPagesDebt_ = pagesRequired;
517 
518  // XXX: SMP-unaware: Walkers should iterate memory cache, not store_table.
519  // XXX: Limit iterations by time, not arbitrary count.
520  const auto walker = mem_policy->PurgeInit(mem_policy, 100000);
521  int removed = 0;
522  while (const auto entry = walker->Next(walker)) {
523  // Abandoned memory cache entries are purged during memory shortage.
524  entry->abandon(__FUNCTION__); // may delete entry
525  ++removed;
526 
527  if (memoryCacheHasSpaceFor(pagesRequired))
528  break;
529  }
530  // TODO: Move to RemovalPolicyWalker::Done() that has more/better details.
531  debugs(20, 3, "removed " << removed << " out of " << hot_obj_count << " memory-cached entries");
532  walker->Done(walker);
533  memoryPagesDebt_ = 0;
534 }
535 
536 // move this into [non-shared] memory cache class when we have one
538 bool
540 {
541  if (!e.memoryCachable())
542  return false;
543 
544  // does the current and expected size obey memory caching limits?
545  assert(e.mem_obj);
546  const int64_t loadedSize = e.mem_obj->endOffset();
547  const int64_t expectedSize = e.mem_obj->expectedReplySize(); // may be < 0
548  const int64_t ramSize = max(loadedSize, expectedSize);
549  const int64_t ramLimit = min(
550  static_cast<int64_t>(Config.memMaxSize),
551  static_cast<int64_t>(Config.Store.maxInMemObjSize));
552  return ramSize <= ramLimit;
553 }
554 
555 void
556 Store::Controller::memoryOut(StoreEntry &e, const bool preserveSwappable)
557 {
558  bool keepInLocalMemory = false;
559  if (sharedMemStore)
560  sharedMemStore->write(e); // leave keepInLocalMemory false
561  else if (localMemStore)
562  keepInLocalMemory = keepForLocalMemoryCache(e);
563 
564  debugs(20, 7, HERE << "keepInLocalMemory: " << keepInLocalMemory);
565 
566  if (!keepInLocalMemory)
567  e.trimMemory(preserveSwappable);
568 }
569 
572 void
574 {
575  // TODO: Untangle memory caching from mem_obj.
576  if (sharedMemStore)
577  sharedMemStore->evictCached(e);
578  else // TODO: move into [non-shared] memory cache class when we have one
579  if (!e.locked())
580  e.destroyMemObject();
581 }
582 
583 void
585 {
586  if (sharedMemStore)
587  sharedMemStore->disconnect(e);
588  // else nothing to do for non-shared memory cache
589 }
590 
591 void
593 {
594  // Marking the transients entry is sufficient to prevent new readers from
595  // starting to wait for `e` updates and to inform the current readers (and,
596  // hence, Broadcast() recipients) about the underlying Store problems.
597  if (transients && e.hasTransients())
598  transients->evictCached(e);
599 }
600 
601 void
603 {
604  // transients->isWriter(e) is false if `e` is writing to its second store
605  // after finishing writing to its first store: At the end of the first swap
606  // out, the transients writer becomes a reader and (XXX) we never switch
607  // back to writing, even if we start swapping out again (to another store).
608  if (transients && e.hasTransients() && transients->isWriter(e))
609  transients->completeWriting(e);
610 }
611 
612 int
614 {
615  return (transients && e.hasTransients()) ?
616  transients->readers(e) : 0;
617 }
618 
619 void
621 {
622  if (transients)
623  transients->disconnect(e);
624 }
625 
626 void
628 {
629  if (transients)
630  transients->clearCollapsingRequirement(e);
631 }
632 
633 void
635 {
636  bool keepInLocalMemory = false;
637 
638  if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) {
639  // Icons (and cache digests?) should stay in store_table until we
640  // have a dedicated storage for them (that would not purge them).
641  // They are not managed [well] by any specific Store handled below.
642  keepInLocalMemory = true;
643  } else if (sharedMemStore) {
644  // leave keepInLocalMemory false; sharedMemStore maintains its own cache
645  } else if (localMemStore) {
646  keepInLocalMemory = keepForLocalMemoryCache(e) && // in good shape and
647  // the local memory cache is not overflowing
648  memoryCacheHasSpaceFor(memoryPagesDebt_);
649  }
650 
651  // An idle, unlocked entry that only belongs to a SwapDir which controls
652  // its own index, should not stay in the global store_table.
653  if (!dereferenceIdle(e, keepInLocalMemory)) {
654  debugs(20, 5, HERE << "destroying unlocked entry: " << &e << ' ' << e);
655  destroyStoreEntry(static_cast<hash_link*>(&e));
656  return;
657  }
658 
659  debugs(20, 5, HERE << "keepInLocalMemory: " << keepInLocalMemory);
660 
661  // TODO: move this into [non-shared] memory cache class when we have one
662  if (keepInLocalMemory) {
664  e.mem_obj->unlinkRequest();
665  return;
666  }
667 
668  // We know the in-memory data will be gone. Get rid of the entire entry if
669  // it has nothing worth preserving on disk either.
670  if (!e.swappedOut()) {
671  e.release(); // deletes e
672  return;
673  }
674 
675  memoryEvictCached(e); // may already be gone
676  // and keep the entry in store_table for its on-disk data
677 }
678 
679 void
681 {
682  /* update the old entry object */
683  Must(old);
684  HttpReply *oldReply = const_cast<HttpReply*>(old->getReply());
685  Must(oldReply);
686 
687  const bool modified = oldReply->updateOnNotModified(newer.getReply());
688  if (!old->timestampsSet() && !modified)
689  return;
690 
691  // XXX: Call memStore->updateHeaders(old) and swapDir->updateHeaders(old) to
692  // update stored headers, stored metadata, and in-transit metadata.
693  debugs(20, 3, *old << " headers were modified: " << modified);
694 }
695 
696 bool
698  const HttpRequestMethod &reqMethod)
699 {
700  const KeyScope keyScope = reqFlags.refresh ? ksRevalidation : ksDefault;
701  // set the flag now so that it gets copied into the Transients entry
702  e->setCollapsingRequirement(true);
703  if (e->makePublic(keyScope)) { // this is needed for both local and SMP collapsing
704  debugs(20, 3, "may " << (transients && e->hasTransients() ?
705  "SMP-" : "locally-") << "collapse " << *e);
706  return true;
707  }
708  // paranoid cleanup; the flag is meaningless for private entries
709  e->setCollapsingRequirement(false);
710  return false;
711 }
712 
713 void
715 {
716  if (transients)
717  transients->monitorIo(e, key, Store::ioReading);
718  e->hashInsert(key);
719 }
720 
721 void
723 {
724  assert(e);
725  if (EBIT_TEST(e->flags, ENTRY_SPECIAL))
726  return; // constant memory-resident entries do not need transients
727 
728  if (transients)
729  transients->monitorIo(e, key, Store::ioWriting);
730  // else: non-SMP configurations do not need transients
731 }
732 
733 void
735 {
736  assert(transients);
737 
738  StoreEntry *collapsed = transients->findCollapsed(xitIndex);
739  if (!collapsed) { // the entry is no longer active, ignore update
740  debugs(20, 7, "not SMP-syncing not-transient " << xitIndex);
741  return;
742  }
743 
744  if (!collapsed->locked()) {
745  debugs(20, 3, "skipping (and may destroy) unlocked " << *collapsed);
746  handleIdleEntry(*collapsed);
747  return;
748  }
749 
750  assert(collapsed->mem_obj);
751 
752  if (EBIT_TEST(collapsed->flags, ENTRY_ABORTED)) {
753  debugs(20, 3, "skipping already aborted " << *collapsed);
754  return;
755  }
756 
757  debugs(20, 7, "syncing " << *collapsed);
758 
759  Transients::EntryStatus entryStatus;
760  transients->status(*collapsed, entryStatus);
761 
762  if (!entryStatus.collapsed) {
763  debugs(20, 5, "removing collapsing requirement for " << *collapsed << " since remote writer probably got headers");
764  collapsed->setCollapsingRequirement(false);
765  }
766 
767  if (entryStatus.waitingToBeFreed) {
768  debugs(20, 3, "will release " << *collapsed << " due to waitingToBeFreed");
769  collapsed->release(true); // may already be marked
770  }
771 
772  if (transients->isWriter(*collapsed))
773  return; // readers can only change our waitingToBeFreed flag
774 
775  assert(transients->isReader(*collapsed));
776 
777  if (entryStatus.abortedByWriter) {
778  debugs(20, 3, "aborting " << *collapsed << " because its writer has aborted");
779  collapsed->abort();
780  return;
781  }
782 
783  if (entryStatus.collapsed && !collapsed->hittingRequiresCollapsing()) {
784  debugs(20, 3, "aborting " << *collapsed << " due to writer/reader collapsing state mismatch");
785  collapsed->abort();
786  return;
787  }
788 
789  bool found = false;
790  bool inSync = false;
791  if (sharedMemStore && collapsed->mem_obj->memCache.io == MemObject::ioDone) {
792  found = true;
793  inSync = true;
794  debugs(20, 7, "fully mem-loaded " << *collapsed);
795  } else if (sharedMemStore && collapsed->hasMemStore()) {
796  found = true;
797  inSync = sharedMemStore->updateAnchored(*collapsed);
798  // TODO: handle entries attached to both memory and disk
799  } else if (swapDir && collapsed->hasDisk()) {
800  found = true;
801  inSync = swapDir->updateAnchored(*collapsed);
802  } else {
803  found = anchorToCache(*collapsed, inSync);
804  }
805 
806  if (entryStatus.waitingToBeFreed && !found) {
807  debugs(20, 3, "aborting unattached " << *collapsed <<
808  " because it was marked for deletion before we could attach it");
809  collapsed->abort();
810  return;
811  }
812 
813  if (inSync) {
814  debugs(20, 5, "synced " << *collapsed);
815  collapsed->invokeHandlers();
816  return;
817  }
818 
819  if (found) { // unrecoverable problem syncing this entry
820  debugs(20, 3, "aborting unsyncable " << *collapsed);
821  collapsed->abort();
822  return;
823  }
824 
825  // the entry is still not in one of the caches
826  debugs(20, 7, "waiting " << *collapsed);
827 }
828 
832 bool
834 {
835  assert(entry.hasTransients());
836  assert(transientsReader(entry));
837 
838  debugs(20, 7, "anchoring " << entry);
839 
840  bool found = false;
841  if (sharedMemStore)
842  found = sharedMemStore->anchorToCache(entry, inSync);
843  if (!found && swapDir)
844  found = swapDir->anchorToCache(entry, inSync);
845 
846  if (found) {
847  if (inSync)
848  debugs(20, 7, "anchored " << entry);
849  else
850  debugs(20, 5, "failed to anchor " << entry);
851  } else {
852  debugs(20, 7, "skipping not yet cached " << entry);
853  }
854 
855  return found;
856 }
857 
858 bool
860 {
861  return MemStore::Enabled() || Disks::SmpAware();
862 }
863 
864 void
866 {
867  if (EBIT_TEST(e.flags, ENTRY_SPECIAL))
868  return;
869  assert(!transients || e.hasTransients());
870 }
871 
872 namespace Store {
874 }
875 
878 {
879  assert(TheRoot);
880  return *TheRoot;
881 }
882 
883 void
885 {
886  TheRoot = root ? root : new Controller;
887 }
888 
889 void
891 {
892  TheRoot = nullptr;
893 }
894 
bool memoryCacheHasSpaceFor(const int pagesRequired) const
whether the memory cache is allowed to store that many additional pages
Definition: Controller.cc:488
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:884
StoreSearch * search()
Definition: Controller.cc:215
static int store_dirs_rebuilding
the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
Definition: Controller.h:139
hash_table * store_table
int PidStatus
Definition: tools.h:94
#define assert(EX)
Definition: assert.h:17
RemovalPolicyNode repl
Definition: MemObject.h:166
size_t maxInMemObjSize
Definition: SquidConfig.h:268
virtual void init() override
Definition: Transients.cc:41
SQUIDCEXTERN void hashFreeMemory(hash_table *)
Definition: hash.cc:272
void release(const bool shareable=false)
Definition: store.cc:1189
size_t store_pages_max
StoreEntry * find(const cache_key *)
Definition: Controller.cc:325
void unlinkRequest()
Definition: MemObject.h:56
double size
bytes currently in use
Definition: StoreStats.h:20
bool timestampsSet()
Definition: store.cc:1454
unsigned char cache_key
Store key.
Definition: forward.h:29
pid_t WaitForAnyPid(PidStatus &status, int flags)
Definition: tools.h:111
virtual void sync() override
prepare for shutdown
Definition: Controller.cc:222
int64_t endOffset() const
Definition: MemObject.cc:218
bool hasTransients() const
whether there is a corresponding locked transients table entry
Definition: Store.h:187
RemovalPolicy * mem_policy
Definition: MemObject.cc:45
void stopSharing(StoreEntry &)
stop any current (and prevent any future) SMP sharing of the given entry
Definition: Controller.cc:592
int64_t store_maxobjsize
static size_t inUseCount()
Definition: store.cc:176
virtual void init() override
Definition: MemStore.cc:176
const char * storeKeyText(const cache_key *key)
double mem_object_count
number of MemObject objects in existence
Definition: StoreStats.h:53
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition: store.cc:1997
Io io
current I/O state
Definition: MemObject.h:149
void freeMemorySpace(const int spaceRequired)
Definition: Controller.cc:497
class Ping::pingStats_ stats
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
static size_t inUseCount()
Definition: MemObject.cc:48
bool abortedByWriter
whether the entry was aborted
Definition: Transients.h:33
struct SquidConfig::@110 Store
bool dereferenceIdle(StoreEntry &, bool wantsLocalMemory)
Definition: Controller.cc:273
#define DBG_CRITICAL
Definition: Debug.h:45
static size_t StoreMemSize()
Definition: mem_node.cc:61
void referenceBusy(StoreEntry &e)
update reference counters of the recently touched entry
Definition: Controller.cc:248
Controller & Root()
safely access controller singleton
Definition: Controller.cc:877
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:13
int lowWaterMark
Definition: SquidConfig.h:80
double store_entry_count
number of StoreEntry objects in existence
Definition: StoreStats.h:52
double count
number of cached objects
Definition: StoreStats.h:21
void destroyMemObject()
Definition: store.cc:372
A const & max(A const &lhs, A const &rhs)
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:151
bool IamWorkerProcess()
whether the current process handles HTTP transactions and such
Definition: stub_tools.cc:49
time_t squid_curtime
Definition: stub_time.cc:17
void updateLimits()
slowly calculate (and cache) hi/lo watermarks and similar limits
Definition: Controller.cc:198
void transientsDisconnect(StoreEntry &)
disassociates the entry from the intransit table
Definition: Controller.cc:620
double capacity
the size limit
Definition: StoreStats.h:22
virtual uint64_t maxSize() const override
Definition: Controller.cc:163
int transientReaders(const StoreEntry &) const
number of the transient entry readers some time ago
Definition: Controller.cc:613
double doublePercent(const double, const double)
Definition: SquidMath.cc:25
void invokeHandlers()
Mem mem
all cache_dirs stats
Definition: StoreStats.h:49
int locked() const
Definition: store.cc:1249
static RefCount< Controller > TheRoot
Definition: Controller.cc:873
void hashInsert(const cache_key *)
Definition: store.cc:412
virtual void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: Controller.cc:93
virtual ~Controller() override
Definition: Controller.cc:45
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
bool updateOnNotModified(HttpReply const *other)
Definition: HttpReply.cc:256
static bool Enabled()
whether Squid is correctly configured to use a shared memory cache
Definition: MemStore.h:68
void abort()
Definition: store.cc:1107
bool collapsed
whether the entry allows collapsing
Definition: Transients.h:35
int store_swap_high
HttpReply const * getReply() const
Definition: store.cc:1670
void handleIdleEntry(StoreEntry &)
called when the entry is no longer needed by any transaction
Definition: Controller.cc:634
mem_status_t mem_status
Definition: Store.h:216
void(* Referenced)(RemovalPolicy *policy, const StoreEntry *entry, RemovalPolicyNode *node)
Definition: RemovalPolicy.h:48
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
Definition: hash.cc:147
void checkTransients(const StoreEntry &) const
Definition: Controller.cc:865
bool hasMemStore() const
whether there is a corresponding locked shared memory table entry
Definition: Store.h:189
void memoryEvictCached(StoreEntry &)
Definition: Controller.cc:573
static size_t InUseCount()
Definition: mem_node.cc:55
summary view of all disk caches (cache_dirs) combined
Definition: Disks.h:18
static bool SmpAware()
whether there are any SMP-aware storages
Definition: Controller.cc:859
uint16_t flags
Definition: Store.h:208
SQUIDCEXTERN void hashFreeItems(hash_table *, HASHFREE *)
Definition: hash.cc:256
virtual void getStats(StoreInfoStats &stats) const override
collect statistics
Definition: Controller.cc:115
int64_t accumulateMore(StoreEntry &) const
Definition: Controller.cc:447
signed_int32_t sfileno
Definition: forward.h:22
MemObject * mem_obj
Definition: Store.h:197
void addReading(StoreEntry *, const cache_key *)
Definition: Controller.cc:714
void allowSharing(StoreEntry &, const cache_key *)
indexes and adds SMP-tracking for an ephemeral peek() result
Definition: Controller.cc:346
bool transientsWriter(const StoreEntry &) const
whether the entry is in &quot;writing to Transients&quot; I/O state
Definition: Controller.cc:441
bool markedForDeletionAndAbandoned(const StoreEntry &) const
Definition: Controller.cc:310
#define SM_PAGE_SIZE
Definition: defines.h:102
virtual int callback() override
called once every main loop iteration; TODO: Move to UFS code.
Definition: Controller.cc:233
::Transients Transients
Definition: forward.h:52
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
bool shared
whether memory cache is shared among workers
Definition: StoreStats.h:42
static bool SmpAware()
whether any disk cache is SMP-aware
Definition: Disks.cc:548
void setCollapsingRequirement(const bool required)
allow or forbid collapsed requests feeding
Definition: store.cc:2071
bool makePublic(const KeyScope keyScope=ksDefault)
Definition: store.cc:144
static pid_t pid
Definition: IcmpSquid.cc:35
void memoryDisconnect(StoreEntry &)
disassociates the entry from the memory cache, preserving cached data
Definition: Controller.cc:584
int highWaterMark
Definition: SquidConfig.h:79
#define PRIu64
Definition: types.h:120
void transientsCompleteWriting(StoreEntry &)
marks the entry completed for collapsed requests
Definition: Controller.cc:602
StoreEntry * findCallbackXXX(const cache_key *)
Definition: Controller.cc:362
bool markedForDeletion(const cache_key *key) const
Definition: Controller.cc:303
virtual void create() override
create system resources needed for this store to operate in the future
Definition: Controller.cc:79
shared entry metadata, used for synchronization
Definition: Transients.h:30
#define PROF_start(probename)
Definition: Profiler.h:62
void addWriting(StoreEntry *, const cache_key *)
Definition: Controller.cc:722
void FreeMemory()
undo Init()
Definition: Controller.cc:890
void(* Dereferenced)(RemovalPolicy *policy, const StoreEntry *entry, RemovalPolicyNode *node)
Definition: RemovalPolicy.h:49
virtual void evictCached(StoreEntry &) override
Definition: Controller.cc:457
bool memoryCachable()
checkCachable() and can be cached in memory
Definition: store.cc:1339
virtual void evictIfFound(const cache_key *) override
Definition: Controller.cc:468
KeyScope
Definition: store_key_md5.h:18
bool hasReadableDiskEntry(const StoreEntry &) const
whether there is a disk entry with e.key
Definition: Controller.cc:319
bool hittingRequiresCollapsing() const
whether this entry can feed collapsed requests and only them
Definition: Store.h:192
size_t memMaxSize
Definition: SquidConfig.h:85
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:55
virtual uint64_t minSize() const override
the minimum size the store will shrink to via normal housekeeping
Definition: Controller.cc:170
StoreEntry * peekAtLocal(const cache_key *)
Definition: Controller.cc:378
int hot_obj_count
virtual void init() override
Definition: Controller.cc:59
#define PROF_stop(probename)
Definition: Profiler.h:63
void memoryOut(StoreEntry &, const bool preserveSwappable)
called to get rid of no longer needed entry data in RAM, if any
Definition: Controller.cc:556
StoreEntry * peek(const cache_key *)
Definition: Controller.cc:394
virtual uint64_t currentCount() const override
the total number of objects stored right now
Definition: Controller.cc:184
int store_swap_low
bool waitingToBeFreed
whether the entry was marked for deletion
Definition: Transients.h:34
static constexpr Io ioDone
Definition: MemObject.h:131
void updateOnNotModified(StoreEntry *old, const StoreEntry &newer)
update old entry metadata and HTTP headers using a newer entry
Definition: Controller.cc:680
bool keepForLocalMemoryCache(StoreEntry &e) const
whether e should be kept in local RAM for possible future caching
Definition: Controller.cc:539
bool transientsReader(const StoreEntry &) const
whether the entry is in &quot;reading from Transients&quot; I/O state
Definition: Controller.cc:435
void transientsClearCollapsingRequirement(StoreEntry &e)
removes collapsing requirement (for future hits)
Definition: Controller.cc:627
RemovalPurgeWalker *(* PurgeInit)(RemovalPolicy *policy, int max_scan)
Definition: RemovalPolicy.h:51
static bool Enabled()
Can we create and initialize Transients?
Definition: Transients.h:92
FREE destroyStoreEntry
bool swappedOut() const
whether the entire entry is now on disk (possibly marked for deletion)
Definition: Store.h:121
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:875
struct SquidConfig::@96 Swap
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
virtual void stat(StoreEntry &) const override
Definition: Controller.cc:141
virtual uint64_t currentSize() const override
current size
Definition: Controller.cc:177
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
virtual int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: Controller.cc:191
bool allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &)
tries to make the entry available for collapsing future requests
Definition: Controller.cc:697
int64_t expectedReplySize() const
Definition: MemObject.cc:242
void syncCollapsed(const sfileno)
Update local intransit entry after changes made by appending worker.
Definition: Controller.cc:734
A const & min(A const &lhs, A const &rhs)
void trimMemory(const bool preserveSwappable)
Definition: store.cc:1871
#define false
Definition: GnuRegex.c:233
StoreSearch * NewLocalSearch()
Definition: LocalSearch.cc:44
bool anchorToCache(StoreEntry &e, bool &inSync)
Definition: Controller.cc:833
void setMemStatus(mem_status_t)
Definition: store.cc:1558

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors