18 #ifndef FOEDUS_CACHE_CACHE_HASHTABLE_HPP_
19 #define FOEDUS_CACHE_CACHE_HASHTABLE_HPP_
98 explicit HashFunc(BucketId physical_buckets);
112 uint32_t quotient = bucket_div_.
div32(seed);
113 uint32_t bucket = bucket_div_.
rem32(seed, logical_buckets_, quotient);
114 ASSERT_ND(bucket == seed % logical_buckets_);
143 void reset(ContentId
id = 0, PageIdTag tag = 0) {
144 data_ = (
static_cast<uint64_t
>(tag) << 32) | id;
152 void set_content_id(ContentId
id) { data_ = (data_ & 0xFFFFFFFF00000000ULL) |
id; }
155 PageIdTag
get_tag()
const {
return static_cast<PageIdTag
>(data_ >> 32); }
158 data_ = (data_ & 0x00000000FFFFFFFFULL) | (static_cast<uint64_t>(tag) << 32);
167 if (count_ < 0xFFFFU) {
173 if (count_ >= subtract) {
274 ContentId* out)
const;
311 void evict(EvictArgs* args);
390 uint32_t seed = snapshot_id * 0x5a2948074497175aULL;
391 seed += numa_node * 0xc30a95f6e63dd908ULL;
396 uint8_t highest_bits =
static_cast<uint8_t
>(local_page_id >> 32);
397 uint32_t folded_local_page_id = local_page_id + highest_bits * 0xd3561f5bedac324cULL;
401 uint32_t swaped_page_id = __builtin_bswap32(folded_local_page_id);
402 seed ^= swaped_page_id;
407 PageIdTag high_bits =
static_cast<PageIdTag
>(page_id >> 32);
408 PageIdTag tag = high_bits * 0x8e1d76486c3e638dULL +
static_cast<PageIdTag
>(page_id);
450 #endif // FOEDUS_CACHE_CACHE_HASHTABLE_HPP_
void set_tag(PageIdTag tag)
same note as set_content_id()
void evict_overflow_loop(EvictArgs *args, uint16_t loop)
BucketId clockhand_
We previously stopped eviction here for usual buckets.
soc::SharedMutex overflow_free_buckets_mutex_
The mutex to protect free overflow entries.
Definitions of IDs in this package and a few related constant values.
SnapshotLocalPageId extract_local_page_id_from_snapshot_pointer(SnapshotPagePointer pointer)
CacheOverflowEntry * overflow_buckets_
An entry in the overflow linked list for snapshot cache.
uint32_t BucketId
Offset in hashtable bucket.
memory::AlignedMemory buckets_memory_
ErrorCode install(storage::SnapshotPagePointer page_id, ContentId content)
Called when a cached page is not found.
memory::AlignedMemory refcounts_memory_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
ContentId * evicted_contents_
[Out] Array of ContentId evicted.
static PageIdTag get_tag(storage::SnapshotPagePointer page_id) __attribute__((always_inline))
Returns another hash value used to differentiate IDs with similar hash values.
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
const BucketId logical_buckets_
Number of logical (actually used) buckets in this table.
BucketId get_physical_buckets() const __attribute__((always_inline))
uint32_t OverflowPointer
Position in the overflow buckets.
Brings error stacktrace information as return value of functions.
void add_evicted(ContentId content)
HashFunc(BucketId physical_buckets)
void prefetch_cachelines(const void *address, int cacheline_count)
Prefetch multiple contiguous cachelines to L1 cache.
Definitions of IDs in this package and a few related constant values.
A simple hash function logic used in snasphot cache.
void set_content_id(ContentId id)
The pre-calculated p-m pair for optimized integer division by constant.
void increment() __attribute__((always_inline))
Forward declarations of classes in cache package.
OverflowPointer overflow_free_buckets_head_
This forms another singly-linked list of free overflow entries.
PageIdTag get_tag() const
A mutex that can be placed in shared memory and used from multiple processes.
uint64_t evicted_count_
[Out] Number of entries that were actually evicted
friend std::ostream & operator<<(std::ostream &o, const CacheHashtable &v)
CacheHashtable(BucketId physical_buckets, uint16_t numa_node)
void evict(EvictArgs *args)
Evict some entries from the hashtable.
ErrorCode find_batch(uint16_t batch_size, const storage::SnapshotPagePointer *page_ids, ContentId *out) const
Batched version of find().
uint32_t rem32(uint32_t n, uint32_t d, uint32_t q) const
Calculate remainder.
bool decrement(uint16_t subtract) __attribute__((always_inline))
returns whether the counter is still non-zero
Max size for find_batch()
BucketId evict_main_loop(EvictArgs *args, BucketId cur, uint16_t loop)
uint32_t PageIdTag
This is a lossy-compressed representation of SnapshotPagePointer used to quickly identify whether the...
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
ErrorStack verify_single_thread() const
only for debugging.
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Constants and methods related to CPU cacheline and its prefetching.
memory::PagePoolOffset ContentId
Offset of the actual page image in PagePool for snapshot pages.
uint16_t extract_snapshot_id_from_snapshot_pointer(SnapshotPagePointer pointer)
const uint32_t overflow_buckets_count_
CacheRefCount * refcounts_
A NUMA-local hashtable of cached snapshot pages.
memory::AlignedMemory overflow_buckets_memory_
const CacheBucket & get_bucket(BucketId bucket_id) const
const uint16_t kHopNeighbors
Starting from the given position, we consider this many buckets for the entry.
uint8_t extract_numa_node_from_snapshot_pointer(SnapshotPagePointer pointer)
BucketId get_bucket_number(storage::SnapshotPagePointer page_id) const __attribute__((always_inline))
Returns a bucket number the given snapshot page ID should belong to.
uint64_t target_count_
[In] Evicts entries up to about target_count (maybe a bit more or less)
ContentId get_content_id() const
Forward declarations of classes in memory package.
Hash bucket in cache table.
BucketId get_logical_buckets() const __attribute__((always_inline))
uint32_t overflow_entries_
Represents one memory block aligned to actual OS/hardware pages.
const uint16_t numa_node_
const HashFunc hash_func_
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
Stat get_stat_single_thread() const
only for debugging.
friend std::ostream & operator<<(std::ostream &o, const HashFunc &v)
void reset(ContentId id=0, PageIdTag tag=0)
static uint32_t get_hash(storage::SnapshotPagePointer page_id) __attribute__((always_inline))
Returns a hash value for the given snapshot page ID.
const assorted::ConstDiv bucket_div_
to efficiently divide a number by bucket_div_.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Forward declarations of classes in thread package.
const BucketId physical_buckets_
Number of buckets that are physically allocated, at least kHopNeighbors more than logical...
uint32_t div32(uint32_t n) const
32-bit integer division that outputs both quotient and remainder.
BucketId get_bucket_number(storage::SnapshotPagePointer page_id) const __attribute__((always_inline))
Returns a bucket number the given page ID should belong to.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
OverflowPointer next_
Note that we don't have to atomically maintain/follow this pointer thanks to the loose requirements...
OverflowPointer overflow_buckets_head_
This forms a singly-linked list of active overflow entries.
ErrorCode
Enum of error codes defined in error_code.xmacro.
bool is_content_set() const
A loosely maintained reference count for CLOCK algorithm.
ContentId find(storage::SnapshotPagePointer page_id) const __attribute__((always_inline))
Returns an offset for the given page ID opportunistically.