MemStore.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 #ifndef SQUID_MEMSTORE_H
10 #define SQUID_MEMSTORE_H
11 
12 #include "ipc/mem/Page.h"
13 #include "ipc/mem/PageStack.h"
14 #include "ipc/StoreMap.h"
15 #include "Store.h"
16 #include "store/Controlled.h"
17 
18 // StoreEntry restoration info not already stored by Ipc::StoreMap
21 };
24 
25 class ShmWriter;
26 
30 {
31 public:
32  MemStore();
33  virtual ~MemStore();
34 
36  bool keepInLocalMemory(const StoreEntry &e) const;
37 
39  void write(StoreEntry &e);
40 
42  void completeWriting(StoreEntry &e);
43 
45  void disconnect(StoreEntry &e);
46 
47  /* Storage API */
48  virtual void create() override {}
49  virtual void init() override;
50  virtual StoreEntry *get(const cache_key *) override;
51  virtual uint64_t maxSize() const override;
52  virtual uint64_t minSize() const override;
53  virtual uint64_t currentSize() const override;
54  virtual uint64_t currentCount() const override;
55  virtual int64_t maxObjectSize() const override;
56  virtual void getStats(StoreInfoStats &stats) const override;
57  virtual void stat(StoreEntry &e) const override;
58  virtual void reference(StoreEntry &e) override;
59  virtual bool dereference(StoreEntry &e) override;
60  virtual void updateHeaders(StoreEntry *e) override;
61  virtual void maintain() override;
62  virtual bool anchorCollapsed(StoreEntry &e, bool &inSync) override;
63  virtual bool updateCollapsed(StoreEntry &e) override;
64  virtual void markForUnlink(StoreEntry &) override;
65  virtual void unlink(StoreEntry &e) override;
66  virtual bool smpAware() const override { return true; }
67 
68  static int64_t EntryLimit();
69 
70 protected:
71  friend ShmWriter;
72 
73  bool shouldCache(StoreEntry &e) const;
74  bool startCaching(StoreEntry &e);
75 
76  void copyToShm(StoreEntry &e);
78  bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor);
79  bool copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof);
80 
82 
83  void anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor);
84  bool updateCollapsedWith(StoreEntry &collapsed, const sfileno index, const Ipc::StoreMapAnchor &anchor);
85 
87  Ipc::StoreMap::Slice &nextAppendableSlice(const sfileno entryIndex, sfileno &sliceOffset);
89 
90  // Ipc::StoreMapCleaner API
91  virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
92 
93 private:
94  // TODO: move freeSlots into map
97 
100 
103 
106  {
107  public:
109  bool operator !() const { return !slot && !page; }
112  };
114 };
115 
116 // Why use Store as a base? MemStore and SwapDir are both "caches".
117 
118 // Why not just use a SwapDir API? That would not help much because Store has
119 // to check/update memory cache separately from the disk cache. And same API
120 // would hurt because we can support synchronous get/put, unlike the disks.
121 
122 #endif /* SQUID_MEMSTORE_H */
123 
virtual uint64_t minSize() const override
the minimum size the store will shrink to via normal housekeeping
Definition: MemStore.cc:267
virtual void unlink(StoreEntry &e) override
remove the entry from the store
Definition: MemStore.cc:921
virtual void getStats(StoreInfoStats &stats) const override
collect statistics
Definition: MemStore.cc:211
friend ShmWriter
Definition: MemStore.h:71
virtual bool updateCollapsed(StoreEntry &e) override
Definition: MemStore.cc:423
virtual uint64_t maxSize() const override
Definition: MemStore.cc:273
MemStoreMapExtras Extras
Definition: MemStore.h:98
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:146
SlotAndPage waitingFor
a cache for a single "hot" free slot and page
Definition: MemStore.h:113
void copyToShm(StoreEntry &e)
copies all local data to shared memory
Definition: MemStore.cc:679
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
unused map slot IDs
Definition: MemStore.h:95
unsigned char cache_key
Store key.
Definition: forward.h:29
void completeWriting(StoreEntry &e)
all data has been received; there will be no more write() calls
Definition: MemStore.cc:895
Ipc::Mem::PageId * slot
local slot variable, waiting to be filled
Definition: MemStore.h:110
Ipc::StoreMap MemStoreMap
Definition: MemStore.h:23
MemStoreMap * map
index of mem-cached entries
Definition: MemStore.h:96
virtual void init() override
Definition: MemStore.cc:180
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
Definition: MemStore.cc:363
MemStore()
Definition: MemStore.cc:170
bool shouldCache(StoreEntry &e) const
whether we should cache the entry
Definition: MemStore.cc:602
class Ping::pingStats_ stats
bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
copies the entire entry from shared to local memory
Definition: MemStore.cc:487
virtual uint64_t currentCount() const override
the total number of objects stored right now
Definition: MemStore.cc:286
virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override
adjust slice-linked state before a locked Readable slice is erased
Definition: MemStore.cc:834
Ipc::Mem::PageId * page
local page variable, waiting to be filled
Definition: MemStore.h:111
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:13
virtual int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: MemStore.cc:292
temporary storage for slot and page ID pointers; for the waiting cache
Definition: MemStore.h:105
virtual bool anchorCollapsed(StoreEntry &e, bool &inSync) override
Definition: MemStore.cc:406
Ipc::StoreMap::Slice & nextAppendableSlice(const sfileno entryIndex, sfileno &sliceOffset)
Definition: MemStore.cc:752
bool keepInLocalMemory(const StoreEntry &e) const
whether e should be kept in local RAM for possible future caching
void anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor)
anchors StoreEntry to an already locked map entry
Definition: MemStore.cc:451
virtual uint64_t currentSize() const override
current size
Definition: MemStore.cc:279
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:329
bool copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof)
imports one shared memory slice into local memory
Definition: MemStore.cc:564
bool startCaching(StoreEntry &e)
locks map anchor and preps to store the entry in shared memory
Definition: MemStore.cc:656
bool updateCollapsedWith(StoreEntry &collapsed, const sfileno index, const Ipc::StoreMapAnchor &anchor)
updates collapsed entry after its anchor has been located
Definition: MemStore.cc:442
virtual ~MemStore()
Definition: MemStore.cc:174
void write(StoreEntry &e)
copy non-shared entry data of the being-cached entry to our cache
Definition: MemStore.cc:856
virtual bool dereference(StoreEntry &e) override
Definition: MemStore.cc:303
virtual void stat(StoreEntry &e) const override
Definition: MemStore.cc:224
int32_t StoreMapSliceId
Definition: StoreMap.h:24
signed_int32_t sfileno
Definition: forward.h:22
bool operator!() const
Definition: MemStore.h:109
void disconnect(StoreEntry &e)
called when the entry is about to forget its association with mem cache
Definition: MemStore.cc:935
void const char * buf
Definition: stub_helper.cc:16
static int64_t EntryLimit()
calculates maximum number of entries we need to store and map
Definition: MemStore.cc:956
virtual bool smpAware() const override
Definition: MemStore.h:66
virtual void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: MemStore.cc:262
Ipc::StoreMapItems< MemStoreMapExtraItem > MemStoreMapExtras
Definition: MemStore.h:22
void copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor, Ipc::StoreMap::Slice &slice)
copies at most one slice worth of local memory to shared memory
Definition: MemStore.cc:721
Shared memory page identifier, address, or handler.
Definition: Page.h:21
sfileno reserveSapForWriting(Ipc::Mem::PageId &page)
finds a slot and a free page to fill or throws
Definition: MemStore.cc:799
Ipc::Mem::Pointer< Extras > extras
IDs of pages with slice data.
Definition: MemStore.h:99
virtual void reference(StoreEntry &e) override
somebody needs this entry (many cache replacement policies need to know)
Definition: MemStore.cc:298
virtual void markForUnlink(StoreEntry &) override
expect an unlink() call after the entry becomes idle
Definition: MemStore.cc:913
sfileno lastWritingSlice
the last allocate slice for writing a store entry (during copyToShm)
Definition: MemStore.h:102
virtual void updateHeaders(StoreEntry *e) override
make stored metadata and HTTP headers the same as in the given entry
Definition: MemStore.cc:343
virtual void create() override
create system resources needed for this store to operate in the future
Definition: MemStore.h:48
#define NULL
Definition: types.h:166
Ipc::Mem::PageId pageForSlice(Ipc::StoreMapSliceId sliceId)
safely returns a previously allocated memory page for the given entry slice
Definition: MemStore.cc:788
Ipc::Mem::PageId page
shared memory page with entry slice content
Definition: MemStore.h:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors