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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors