#include <MemStore.h>

Inheritance diagram for MemStore:
Collaboration diagram for MemStore:


class  SlotAndPage
 temporary storage for slot and page ID pointers; for the waiting cache More...

Public Member Functions

 MemStore ()
 ~MemStore () override
bool keepInLocalMemory (const StoreEntry &e) const
 whether e should be kept in local RAM for possible future caching More...
void write (StoreEntry &e)
 copy non-shared entry data of the being-cached entry to our cache More...
void completeWriting (StoreEntry &e)
 all data has been received; there will be no more write() calls More...
void disconnect (StoreEntry &e)
 called when the entry is about to forget its association with mem cache More...
void create () override
 create system resources needed for this store to operate in the future More...
void init () override
StoreEntryget (const cache_key *) override
uint64_t maxSize () const override
uint64_t minSize () const override
 the minimum size the store will shrink to via normal housekeeping More...
uint64_t currentSize () const override
 current size More...
uint64_t currentCount () const override
 the total number of objects stored right now More...
int64_t maxObjectSize () const override
 the maximum size of a storable object; -1 if unlimited More...
void getStats (StoreInfoStats &stats) const override
 collect statistics More...
void stat (StoreEntry &e) const override
void reference (StoreEntry &e) override
 somebody needs this entry (many cache replacement policies need to know) More...
bool dereference (StoreEntry &e) override
void updateHeaders (StoreEntry *e) override
 make stored metadata and HTTP headers the same as in the given entry More...
void maintain () override
 perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain More...
bool anchorToCache (StoreEntry &) override
bool updateAnchored (StoreEntry &) override
void evictCached (StoreEntry &) override
void evictIfFound (const cache_key *) override
virtual int callback ()
 called once every main loop iteration; TODO: Move to UFS code. More...
virtual void sync ()
 prepare for shutdown More...

Static Public Member Functions

static bool Enabled ()
 whether Squid is correctly configured to use a shared memory cache More...
static int64_t EntryLimit ()
 calculates maximum number of entries we need to store and map More...
static bool Requested ()

Protected Member Functions

bool shouldCache (StoreEntry &e) const
 whether we should cache the entry More...
bool startCaching (StoreEntry &e)
 locks map anchor and preps to store the entry in shared memory More...
void copyToShm (StoreEntry &e)
 copies all local data to shared memory More...
void copyToShmSlice (StoreEntry &e, Ipc::StoreMapAnchor &anchor, Ipc::StoreMap::Slice &slice)
 copies at most one slice worth of local memory to shared memory More...
bool copyFromShm (StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
 copies the entire entry from shared to local memory More...
void copyFromShmSlice (StoreEntry &, const StoreIOBuffer &)
 imports one shared memory slice into local memory More...
void updateHeadersOrThrow (Ipc::StoreMapUpdate &update)
void anchorEntry (StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
 anchors StoreEntry to an already locked map entry More...
bool updateAnchoredWith (StoreEntry &, const sfileno, const Ipc::StoreMapAnchor &)
 updates Transients entry after its anchor has been located More...
Ipc::Mem::PageId pageForSlice (Ipc::StoreMapSliceId sliceId)
 safely returns a previously allocated memory page for the given entry slice More...
Ipc::StoreMap::SlicenextAppendableSlice (const sfileno entryIndex, sfileno &sliceOffset)
sfileno reserveSapForWriting (Ipc::Mem::PageId &page)
 finds a slot and a free page to fill or throws More...
void noteFreeMapSlice (const Ipc::StoreMapSliceId sliceId) override
 adjust slice-linked state before a locked Readable slice is erased More...

Protected Attributes

friend ShmWriter

Private Types

typedef MemStoreMapExtras Extras

Private Attributes

Ipc::Mem::Pointer< Ipc::Mem::PageStackfreeSlots
 unused map slot IDs More...
 index of mem-cached entries More...
Ipc::Mem::Pointer< Extrasextras
 IDs of pages with slice data. More...
sfileno lastWritingSlice
 the last allocate slice for writing a store entry (during copyToShm) More...
SlotAndPage waitingFor
 a cache for a single "hot" free slot and page More...

Detailed Description

Stores HTTP entities in RAM. Current implementation uses shared memory. Unlike a disk store (SwapDir), operations are synchronous (and fast).

Definition at line 29 of file MemStore.h.

Member Typedef Documentation

◆ Extras

Definition at line 102 of file MemStore.h.

Constructor & Destructor Documentation

◆ MemStore()

MemStore::MemStore ( )

Definition at line 163 of file MemStore.cc.

◆ ~MemStore()

MemStore::~MemStore ( )

Definition at line 167 of file MemStore.cc.

References map.

Member Function Documentation

◆ anchorEntry()

◆ anchorToCache()

bool MemStore::anchorToCache ( StoreEntry )

tie StoreEntry to this storage if this storage has a matching entry

Return values
trueif this storage has a matching entry

Reimplemented from Store::Controlled.

Definition at line 401 of file MemStore.cc.

References anchorEntry(), Assure, StoreEntry::hasMemStore(), Here, MemObject::MemCache::io, MemObject::ioDone, hash_link::key, map, StoreEntry::mem(), MemObject::memCache, Ipc::StoreMap::openForReading(), and updateAnchoredWith().

◆ callback()

virtual int Store::Storage::callback ( )

Reimplemented in Fs::Ufs::UFSSwapDir, Store::Controller, Store::Disks, and StoreControllerStub.

Definition at line 72 of file Storage.h.

◆ completeWriting()

◆ copyFromShm()

◆ copyFromShmSlice()

void MemStore::copyFromShmSlice ( StoreEntry e,
const StoreIOBuffer buf 

◆ copyToShm()

◆ copyToShmSlice()

◆ create()

void MemStore::create ( )

Implements Store::Storage.

Definition at line 48 of file MemStore.h.

◆ currentCount()

uint64_t MemStore::currentCount ( ) const

Implements Store::Storage.

Definition at line 279 of file MemStore.cc.

References Ipc::StoreMap::entryCount(), and map.

Referenced by getStats(), and stat().

◆ currentSize()

uint64_t MemStore::currentSize ( ) const

Implements Store::Storage.

Definition at line 272 of file MemStore.cc.

References Ipc::Mem::PageId::cachePage, Ipc::Mem::PageLevel(), and Ipc::Mem::PageSize().

Referenced by stat().

◆ dereference()

bool MemStore::dereference ( StoreEntry e)

somebody no longer needs this entry (usually after calling reference()) return false iff the idle entry should be destroyed

Implements Store::Controlled.

Definition at line 296 of file MemStore.cc.

◆ disconnect()

◆ Enabled()

static bool MemStore::Enabled ( )

◆ EntryLimit()

int64_t MemStore::EntryLimit ( )

◆ evictCached()

void MemStore::evictCached ( StoreEntry e)

Prevent new get() calls from returning the matching entry. If the matching entry is unused, it may be removed from the store now. The store entry is matched using either e attachment info or e.key.

Implements Store::Storage.

Definition at line 903 of file MemStore.cc.

References CollapsedForwarding::Broadcast(), debugs, StoreEntry::destroyMemObject(), disconnect(), evictIfFound(), Ipc::StoreMap::freeEntry(), StoreEntry::hasMemStore(), MemObject::MemCache::index, StoreEntry::locked(), map, StoreEntry::mem_obj, MemObject::memCache, and StoreEntry::publicKey().

◆ evictIfFound()

void MemStore::evictIfFound ( const cache_key )

An evictCached() equivalent for callers that did not get() a StoreEntry. Callers with StoreEntry objects must use evictCached() instead.

Implements Store::Storage.

Definition at line 922 of file MemStore.cc.

References Ipc::StoreMap::freeEntryByKey(), and map.

Referenced by evictCached().

◆ get()

StoreEntry * MemStore::get ( const cache_key )
a possibly unlocked/unregistered stored entry with key (or nil) The returned entry might not match the caller's Store ID or method. The caller must abandon()/release() the entry or register it with Root(). This method must not trigger slow I/O operations (e.g., disk swap in).

Implements Store::Controlled.

Definition at line 303 of file MemStore.cc.

References anchorEntry(), copyFromShm(), StoreEntry::createMemObject(), CurrentException(), DBG_IMPORTANT, debugs, destroyStoreEntry, Debug::Extra(), Ipc::StoreMap::freeEntry(), map, and Ipc::StoreMap::openForReading().

◆ getStats()

void MemStore::getStats ( StoreInfoStats stats) const

◆ init()

void MemStore::init ( )

Start preparing the store for use. To check readiness, callers should use readable() and writable() methods.

Implements Store::Storage.

Definition at line 173 of file MemStore.cc.

References SquidConfig::cacheSwap, Ipc::StoreMap::cleaner, Config, DBG_IMPORTANT, debugs, EntryLimit(), extras, ExtrasLabel, freeSlots, map, MapLabel, maxObjectSize(), Store::Controller::maxObjectSize(), Must, Store::DiskConfig::n_configured, Store::Root(), shm_old, and SpaceLabel.

Referenced by Store::Controller::init().

◆ keepInLocalMemory()

bool MemStore::keepInLocalMemory ( const StoreEntry e) const

◆ maintain()

void MemStore::maintain ( )

Implements Store::Storage.

Definition at line 255 of file MemStore.cc.

◆ maxObjectSize()

int64_t MemStore::maxObjectSize ( ) const

Implements Store::Storage.

Definition at line 285 of file MemStore.cc.

References Config, SquidConfig::maxInMemObjSize, SquidConfig::memMaxSize, min(), and SquidConfig::Store.

Referenced by copyToShm(), init(), and shouldCache().

◆ maxSize()

uint64_t MemStore::maxSize ( ) const

The maximum size the store will support in normal use. Inaccuracy is permitted, but may throw estimates for memory etc out of whack.

Implements Store::Storage.

Definition at line 266 of file MemStore.cc.

References Config, and SquidConfig::memMaxSize.

Referenced by stat().

◆ minSize()

uint64_t MemStore::minSize ( ) const

Implements Store::Storage.

Definition at line 260 of file MemStore.cc.

◆ nextAppendableSlice()

Ipc::StoreMap::Slice & MemStore::nextAppendableSlice ( const sfileno  fileNo,
sfileno sliceOffset 

starts checking with the entry chain slice at a given offset and returns a not-full (but not necessarily empty) slice, updating sliceOffset

Definition at line 738 of file MemStore.cc.

References debugs, extras, map, Must, Ipc::StoreMapSlice::next, Ipc::Mem::PageSize(), reserveSapForWriting(), Ipc::StoreMapSlice::size, Ipc::StoreMapAnchor::start, Ipc::StoreMap::writeableEntry(), and Ipc::StoreMap::writeableSlice().

Referenced by ShmWriter::copyToShm(), and copyToShm().

◆ noteFreeMapSlice()

◆ pageForSlice()

Ipc::Mem::PageId MemStore::pageForSlice ( Ipc::StoreMapSliceId  sliceId)

Definition at line 774 of file MemStore.cc.

References extras, and Must.

Referenced by ShmWriter::copyToShmSlice(), and copyToShmSlice().

◆ reference()

void MemStore::reference ( StoreEntry e)

Implements Store::Controlled.

Definition at line 291 of file MemStore.cc.

◆ Requested()

bool MemStore::Requested ( )

whether Squid is configured to use a shared memory cache (it may still be disabled due to the implicit minimum entry size limit)

Definition at line 950 of file MemStore.cc.

References Config, SquidConfig::memMaxSize, and SquidConfig::memShared.

Referenced by EntryLimit(), and MemStoreRr::finalizeConfig().

◆ reserveSapForWriting()

◆ shouldCache()

◆ startCaching()

◆ stat()

void MemStore::stat ( StoreEntry e) const

◆ sync()

virtual void Store::Storage::sync ( void  )

Reimplemented in Fs::Ufs::UFSSwapDir, Store::Controller, and Store::Disks.

Definition at line 78 of file Storage.h.

◆ updateAnchored()

bool MemStore::updateAnchored ( StoreEntry )

Update a local Transients entry with fresh info from this cache (if any). Return true iff the cache supports Transients entries and the given local Transients entry is now in sync with this storage.

Reimplemented from Store::Controlled.

Definition at line 422 of file MemStore.cc.

References assert, StoreEntry::hasMemStore(), MemObject::MemCache::index, map, StoreEntry::mem_obj, MemObject::memCache, Ipc::StoreMap::readableEntry(), and updateAnchoredWith().

◆ updateAnchoredWith()

bool MemStore::updateAnchoredWith ( StoreEntry entry,
const sfileno  index,
const Ipc::StoreMapAnchor anchor 

◆ updateHeaders()

void MemStore::updateHeaders ( StoreEntry )

◆ updateHeadersOrThrow()

◆ write()

Member Data Documentation

◆ extras

Ipc::Mem::Pointer<Extras> MemStore::extras

◆ freeSlots

Ipc::Mem::Pointer<Ipc::Mem::PageStack> MemStore::freeSlots

Definition at line 99 of file MemStore.h.

Referenced by init(), noteFreeMapSlice(), and reserveSapForWriting().

◆ lastWritingSlice

sfileno MemStore::lastWritingSlice

Definition at line 106 of file MemStore.h.

Referenced by copyToShm(), and copyToShmSlice().

◆ map

◆ ShmWriter

friend MemStore::ShmWriter

Definition at line 75 of file MemStore.h.

◆ waitingFor

SlotAndPage MemStore::waitingFor

Definition at line 117 of file MemStore.h.

Referenced by noteFreeMapSlice(), and reserveSapForWriting().

The documentation for this class was generated from the following files:






Web Site Translations