Page Speed Optimization Libraries
1.13.35.1
|
#include "shared_mem_cache_data.h"
Public Member Functions | |
Sector (AbstractSharedMemSegment *segment, size_t sector_offset, size_t cache_entries, size_t data_blocks) | |
bool | Attach (MessageHandler *handler) |
bool | Initialize (MessageHandler *handler) |
AbstractMutex * | mutex () const LOCK_RETURNED(mutex_) |
Mutex ops. More... | |
BlockNum | GetBlockSuccessor (BlockNum block) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
void | SetBlockSuccessor (BlockNum block, BlockNum next) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
void | LinkBlockSuccessors (const BlockVector &blocks) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
int | AllocBlocksFromFreeList (int goal, BlockVector *blocks) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
void | ReturnBlocksToFreeList (const BlockVector &blocks) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
CacheEntry * | EntryAt (EntryNum slot) |
Returns the given # entry. More... | |
void | InsertEntryIntoLRU (EntryNum entry_num) |
void | UnlinkEntryFromLRU (EntryNum entry_num) |
Removes from the LRU. Safe to call if not in the LRU already. | |
EntryNum | OldestEntryNum () |
char * | BlockBytes (BlockNum block_num) |
int | BlockListForEntry (CacheEntry *entry, BlockVector *out_blocks) EXCLUSIVE_LOCKS_REQUIRED(mutex()) |
SectorStats * | sector_stats () |
void | DumpStats (MessageHandler *handler) |
Static Public Member Functions | |
static size_t | RequiredSize (AbstractSharedMem *shmem_runtime, size_t cache_entries, size_t data_blocks) |
static size_t | DataBlocksForSize (size_t size) |
Number of blocks of data needed for size blocks. More... | |
static size_t | BytesInPortion (size_t total_bytes, size_t b, size_t total) |
Helper for operating on a given sector's data structures; helping access them, lay them out in memory, and initialize them. It does not implement the actual cache operations, however. In particular, its methods affect only a single data structure at the time and do not do anything to preserve cross-structure invariants.
net_instaweb::SharedMemCacheData::Sector< kBlockSize >::Sector | ( | AbstractSharedMemSegment * | segment, |
size_t | sector_offset, | ||
size_t | cache_entries, | ||
size_t | data_blocks | ||
) |
Creates a wrapper to help operate on cache sectors in a given region of memory with given geometry. The sector should have had as much memory allocated for it as returned by a call to RequiredSize with the same arguments.
Note that this doesn't do any imperative initialization; you must call Initialize() in the parent process, and Attach() in child processes, and check their results as well. Also, segment is assumed to be owned separately, with lifetime longer than ours.
int net_instaweb::SharedMemCacheData::Sector< kBlockSize >::AllocBlocksFromFreeList | ( | int | goal, |
BlockVector * | blocks | ||
) |
Freelist ops.Allocates as close to the goal blocks from freelist as it can, and appends their numbers to blocks. Returns how much it allocated. Does not adjust block successor lists.
Note that this doesn't attempt to free blocks that are in use by some entries.
bool net_instaweb::SharedMemCacheData::Sector< kBlockSize >::Attach | ( | MessageHandler * | handler | ) |
This should be called from child processes to initialize client state for the cache already formatted by a call to Initialize() in the parent.
Returns if successful (which it should be if the parent process successfully create the memory and Initialize()'d it).
|
inline |
Block ops.
int net_instaweb::SharedMemCacheData::Sector< kBlockSize >::BlockListForEntry | ( | CacheEntry * | entry, |
BlockVector * | out_blocks | ||
) |
Appends the list of blocks used by the entry to 'blocks'. Returns the number of items appended.
|
static |
The # of bytes stored in block 'b' out of 'total' blocks for file of size 'total_bytes'. Precondition: 'total' is appropriate for 'total_bytes'.
|
inlinestatic |
Number of blocks of data needed for size blocks.
Ops for lists of blocks corresponding to each directory entry, and related size computations
void net_instaweb::SharedMemCacheData::Sector< kBlockSize >::DumpStats | ( | MessageHandler * | handler | ) |
Prints out all statistics in the header (some of which are maintained by the higher-level)
|
inline |
Returns the given # entry.
Cache directory ops.
|
inline |
Block successor list ops.
bool net_instaweb::SharedMemCacheData::Sector< kBlockSize >::Initialize | ( | MessageHandler * | handler | ) |
This should be called from the initial/parent process before the children start. It initializes the data structures in this sector, including mutexes. Returns true on success.
void net_instaweb::SharedMemCacheData::Sector< kBlockSize >::InsertEntryIntoLRU | ( | EntryNum | entry_num | ) |
Inserts the given entry into the LRU, at front. Precondition: must not be in LRU.
|
inline |
Links blocks in the vector in order, with later blocks being marked as successors of later ones.
|
inline |
Mutex ops.
The sector lock should be held while doing any metadata accesses.
|
static |
Computes how much memory a sector will need for given number of entries. Also makes sure it's padded to proper alignment.
void net_instaweb::SharedMemCacheData::Sector< kBlockSize >::ReturnBlocksToFreeList | ( | const BlockVector & | blocks | ) |
Puts all the passed in blocks onto this sector's freelist. Does not read successors for passed in blocks, but does set them for freelist membership.
|
inline |
Statistics stuff