#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 ()
 
virtual ~MemStore ()
 
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...
 
virtual void create () override
 create system resources needed for this store to operate in the future More...
 
virtual void init () override
 
virtual StoreEntryget (const cache_key *) override
 
virtual uint64_t maxSize () const override
 
virtual uint64_t minSize () const override
 the minimum size the store will shrink to via normal housekeeping More...
 
virtual uint64_t currentSize () const override
 current size More...
 
virtual uint64_t currentCount () const override
 the total number of objects stored right now More...
 
virtual int64_t maxObjectSize () const override
 the maximum size of a storable object; -1 if unlimited More...
 
virtual void getStats (StoreInfoStats &stats) const override
 collect statistics More...
 
virtual void stat (StoreEntry &e) const override
 
virtual void reference (StoreEntry &e) override
 somebody needs this entry (many cache replacement policies need to know) More...
 
virtual bool dereference (StoreEntry &e) override
 
virtual void updateHeaders (StoreEntry *e) override
 make stored metadata and HTTP headers the same as in the given entry More...
 
virtual void maintain () override
 perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain More...
 
virtual bool anchorToCache (StoreEntry &e, bool &inSync) override
 
virtual bool updateAnchored (StoreEntry &) override
 
virtual void evictCached (StoreEntry &) override
 
virtual 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...
 
bool copyFromShmSlice (StoreEntry &e, const StoreIOBuffer &buf, bool eof)
 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...
 
virtual 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::PageStack
freeSlots
 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

Definition at line 102 of file MemStore.h.

Constructor & Destructor Documentation

MemStore::MemStore ( )

Definition at line 166 of file MemStore.cc.

MemStore::~MemStore ( )
virtual

Definition at line 170 of file MemStore.cc.

References map.

Member Function Documentation

bool MemStore::anchorToCache ( StoreEntry ,
bool &   
)
overridevirtual

If Transients entry cannot be attached to this storage, return false. If the entry is not found, return false. Otherwise, return true after tying the entry to this cache and setting inSync to updateAnchored().

Reimplemented from Store::Controlled.

Definition at line 401 of file MemStore.cc.

References anchorEntry(), hash_link::key, map, Ipc::StoreMap::openForReading(), and updateAnchoredWith().

virtual int Store::Storage::callback ( )
inlinevirtualinherited

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

Definition at line 72 of file Storage.h.

virtual void MemStore::create ( )
inlineoverridevirtual

Implements Store::Storage.

Definition at line 48 of file MemStore.h.

uint64_t MemStore::currentCount ( ) const
overridevirtual

Implements Store::Storage.

Definition at line 282 of file MemStore.cc.

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

Referenced by getStats(), and stat().

uint64_t MemStore::currentSize ( ) const
overridevirtual

Implements Store::Storage.

Definition at line 275 of file MemStore.cc.

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

Referenced by stat().

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 299 of file MemStore.cc.

static bool MemStore::Enabled ( )
inlinestatic
int64_t MemStore::EntryLimit ( )
static
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 885 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().

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 904 of file MemStore.cc.

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

Referenced by evictCached().

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 306 of file MemStore.cc.

References anchorEntry(), copyFromShm(), StoreEntry::createMemObject(), debugs, destroyStoreEntry, Ipc::StoreMap::freeEntry(), map, NULL, and Ipc::StoreMap::openForReading().

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 176 of file MemStore.cc.

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

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

bool MemStore::keepInLocalMemory ( const StoreEntry e) const
void MemStore::maintain ( )
overridevirtual

Implements Store::Storage.

Definition at line 258 of file MemStore.cc.

int64_t MemStore::maxObjectSize ( ) const
overridevirtual

Implements Store::Storage.

Definition at line 288 of file MemStore.cc.

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

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

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 269 of file MemStore.cc.

References Config, and SquidConfig::memMaxSize.

Referenced by stat().

uint64_t MemStore::minSize ( ) const
overridevirtual

Implements Store::Storage.

Definition at line 263 of file MemStore.cc.

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 724 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().

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

Definition at line 760 of file MemStore.cc.

References extras, and Must.

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

void MemStore::reference ( StoreEntry e)
overridevirtual

Implements Store::Controlled.

Definition at line 294 of file MemStore.cc.

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 931 of file MemStore.cc.

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

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

void MemStore::stat ( StoreEntry e) const
overridevirtual
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.

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 418 of file MemStore.cc.

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

bool MemStore::updateAnchoredWith ( StoreEntry entry,
const sfileno  index,
const Ipc::StoreMapAnchor anchor 
)
protected
void MemStore::updateHeaders ( StoreEntry )
overridevirtual

Member Data Documentation

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

Definition at line 99 of file MemStore.h.

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

sfileno MemStore::lastWritingSlice
private

Definition at line 106 of file MemStore.h.

Referenced by copyToShm(), and copyToShmSlice().

friend MemStore::ShmWriter
protected

Definition at line 75 of file MemStore.h.

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