#include <MemStore.h>

Inheritance diagram for MemStore:
Collaboration diagram for MemStore:

Classes

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...
 
MemStoreMapmap
 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 ( )
override

Definition at line 167 of file MemStore.cc.

References map.

Member Function Documentation

◆ anchorEntry()

◆ anchorToCache()

bool MemStore::anchorToCache ( StoreEntry )
overridevirtual

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 ( )
inlinevirtualinherited

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 
)
protected

◆ copyToShm()

◆ copyToShmSlice()

◆ create()

void MemStore::create ( )
inlineoverridevirtual

Implements Store::Storage.

Definition at line 48 of file MemStore.h.

◆ currentCount()

uint64_t MemStore::currentCount ( ) const
overridevirtual

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
overridevirtual

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)
overridevirtual

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 ( )
inlinestatic

◆ EntryLimit()

int64_t MemStore::EntryLimit ( )
static

◆ evictCached()

void MemStore::evictCached ( StoreEntry e)
overridevirtual

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 )
overridevirtual

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 )
overridevirtual
Returns
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
overridevirtual

◆ init()

void MemStore::init ( )
overridevirtual

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 ( )
overridevirtual

Implements Store::Storage.

Definition at line 255 of file MemStore.cc.

◆ maxObjectSize()

int64_t MemStore::maxObjectSize ( ) const
overridevirtual

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
overridevirtual

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
overridevirtual

Implements Store::Storage.

Definition at line 260 of file MemStore.cc.

◆ nextAppendableSlice()

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

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)
protected

Definition at line 774 of file MemStore.cc.

References extras, and Must.

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

◆ reference()

void MemStore::reference ( StoreEntry e)
overridevirtual

Implements Store::Controlled.

Definition at line 291 of file MemStore.cc.

◆ Requested()

bool MemStore::Requested ( )
static

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
overridevirtual

◆ sync()

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

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

Definition at line 78 of file Storage.h.

◆ updateAnchored()

bool MemStore::updateAnchored ( StoreEntry )
overridevirtual

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 
)
protected

◆ updateHeaders()

void MemStore::updateHeaders ( StoreEntry )
overridevirtual

◆ updateHeadersOrThrow()

◆ write()

Member Data Documentation

◆ extras

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

◆ freeSlots

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

Definition at line 99 of file MemStore.h.

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

◆ lastWritingSlice

sfileno MemStore::lastWritingSlice
private

Definition at line 106 of file MemStore.h.

Referenced by copyToShm(), and copyToShmSlice().

◆ map

◆ ShmWriter

friend MemStore::ShmWriter
protected

Definition at line 75 of file MemStore.h.

◆ waitingFor

SlotAndPage MemStore::waitingFor
private

Definition at line 117 of file MemStore.h.

Referenced by noteFreeMapSlice(), and reserveSapForWriting().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors