Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::SharedMemCacheData::Sector< kBlockSize > Class Template Reference

#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)
 
AbstractMutexmutex () 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())
 
CacheEntryEntryAt (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())
 
SectorStatssector_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)
 

Detailed Description

template<size_t kBlockSize>
class net_instaweb::SharedMemCacheData::Sector< kBlockSize >

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.

Constructor & Destructor Documentation

template<size_t kBlockSize>
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.

Member Function Documentation

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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).

template<size_t kBlockSize>
char* net_instaweb::SharedMemCacheData::Sector< kBlockSize >::BlockBytes ( BlockNum  block_num)
inline

Block ops.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
static size_t net_instaweb::SharedMemCacheData::Sector< kBlockSize >::BytesInPortion ( size_t  total_bytes,
size_t  b,
size_t  total 
)
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'.

template<size_t kBlockSize>
static size_t net_instaweb::SharedMemCacheData::Sector< kBlockSize >::DataBlocksForSize ( size_t  size)
inlinestatic

Number of blocks of data needed for size blocks.

Ops for lists of blocks corresponding to each directory entry, and related size computations

template<size_t kBlockSize>
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)

template<size_t kBlockSize>
CacheEntry* net_instaweb::SharedMemCacheData::Sector< kBlockSize >::EntryAt ( EntryNum  slot)
inline

Returns the given # entry.

Cache directory ops.

template<size_t kBlockSize>
BlockNum net_instaweb::SharedMemCacheData::Sector< kBlockSize >::GetBlockSuccessor ( BlockNum  block)
inline

Block successor list ops.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
void net_instaweb::SharedMemCacheData::Sector< kBlockSize >::LinkBlockSuccessors ( const BlockVector &  blocks)
inline

Links blocks in the vector in order, with later blocks being marked as successors of later ones.

template<size_t kBlockSize>
AbstractMutex* net_instaweb::SharedMemCacheData::Sector< kBlockSize >::mutex ( ) const
inline

Mutex ops.

The sector lock should be held while doing any metadata accesses.

template<size_t kBlockSize>
static size_t net_instaweb::SharedMemCacheData::Sector< kBlockSize >::RequiredSize ( AbstractSharedMem shmem_runtime,
size_t  cache_entries,
size_t  data_blocks 
)
static

Computes how much memory a sector will need for given number of entries. Also makes sure it's padded to proper alignment.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
SectorStats* net_instaweb::SharedMemCacheData::Sector< kBlockSize >::sector_stats ( )
inline

Statistics stuff


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