@@ -239,26 +239,15 @@ class ChainedHashTable {
239239
240240 // @param bucketsPower number of buckets in base 2 logarithm
241241 // @param locksPower number of locks in base 2 logarithm
242- // @param pageSize page size
243- Config (unsigned int bucketsPower,
244- unsigned int locksPower,
245- PageSize pageSize = PageSize())
246- : Config(bucketsPower,
247- locksPower,
248- std::make_shared<MurmurHash2>(),
249- std::move (pageSize)) {}
242+ Config (unsigned int bucketsPower, unsigned int locksPower)
243+ : Config(bucketsPower, locksPower, std::make_shared<MurmurHash2>()) {}
250244
251245 // @param bucketsPower number of buckets in base 2 logarithm
252246 // @param locksPower number of locks in base 2 logarithm
253247 // @param hasher the key hash function
254- // @param pageSize page size
255- Config (unsigned int bucketsPower,
256- unsigned int locksPower,
257- Hasher hasher,
258- PageSize pageSize = PageSize())
248+ Config (unsigned int bucketsPower, unsigned int locksPower, Hasher hasher)
259249 : bucketsPower_(bucketsPower),
260250 locksPower_ (locksPower),
261- pageSize_(std::move(pageSize)),
262251 hasher_(std::move(hasher)) {
263252 if (bucketsPower_ > kMaxBucketPower || locksPower_ > kMaxLockPower ||
264253 locksPower_ > bucketsPower_) {
@@ -314,8 +303,6 @@ class ChainedHashTable {
314303 return configMap;
315304 }
316305
317- const PageSize& getPageSize () const { return pageSize_; }
318-
319306 private:
320307 // 4 billion buckets should be good enough for everyone.
321308 static constexpr unsigned int kMaxBucketPower = 32 ;
@@ -330,8 +317,6 @@ class ChainedHashTable {
330317 // total number of locks for the hashtable expressed as a power of two.
331318 unsigned int locksPower_{5 };
332319
333- PageSize pageSize_{};
334-
335320 Hasher hasher_ = std::make_shared<MurmurHash2>();
336321 };
337322
@@ -392,6 +377,8 @@ class ChainedHashTable {
392377 // @param memSegment shared memory segment for the hash table
393378 // @param compressor object used to compress/decompress node pointers
394379 // @param hm the functor that creates a Handle from T*
380+ // @param hugePageSize page size the segment was backed with (bytes), used
381+ // to validate the mapped segment size.
395382 //
396383 // @throw std::invalid argument if the bucket power in new config does not
397384 // match the previous state or the size of the memSegment does not
@@ -400,7 +387,8 @@ class ChainedHashTable {
400387 const Config& newConfig,
401388 ShmAddr memSegment,
402389 const PtrCompressor& compressor,
403- HandleMaker hm = kDefaultHandleMaker );
390+ HandleMaker hm = kDefaultHandleMaker ,
391+ PageSize hugePageSize = PageSize());
404392
405393 // restore hash table from previous state. This only works when the
406394 // hash table memory is managed by the user.
@@ -411,6 +399,8 @@ class ChainedHashTable {
411399 // @param nBytes size of memory allocation pointed to by memStart
412400 // @param compressor object used to compress/decompress node pointers
413401 // @param hm the functor that creates a Handle from T*
402+ // @param hugePageSize page size the segment was backed with (bytes), used
403+ // to validate the mapped segment size.
414404 //
415405 // @throw std::invalid argument if the bucket power in new config does not
416406 // match the previous state or the size of the memSegment does not
@@ -420,7 +410,8 @@ class ChainedHashTable {
420410 void * memStart,
421411 size_t nBytes,
422412 const PtrCompressor& compressor,
423- HandleMaker hm = kDefaultHandleMaker );
413+ HandleMaker hm = kDefaultHandleMaker ,
414+ PageSize hugePageSize = PageSize());
424415
425416 Container (const Container&) = delete ;
426417 Container& operator =(const Container&) = delete ;
@@ -1024,13 +1015,15 @@ ChainedHashTable::Container<T, HookPtr, LockT>::Container(
10241015 const Config& config,
10251016 ShmAddr memSegment,
10261017 const PtrCompressor& compressor,
1027- HandleMaker hm)
1018+ HandleMaker hm,
1019+ PageSize hugePageSize)
10281020 : Container(object,
10291021 config,
10301022 memSegment.addr,
10311023 memSegment.size,
10321024 compressor,
1033- std::move (hm)) {}
1025+ std::move (hm),
1026+ hugePageSize) {}
10341027
10351028template <typename T,
10361029 typename ChainedHashTable::Hook<T> T::* HookPtr,
@@ -1041,7 +1034,8 @@ ChainedHashTable::Container<T, HookPtr, LockT>::Container(
10411034 void * memStart,
10421035 size_t nBytes,
10431036 const PtrCompressor& compressor,
1044- HandleMaker hm)
1037+ HandleMaker hm,
1038+ PageSize hugePageSize)
10451039 : config_{config},
10461040 handleMaker_ (std::move(hm)),
10471041 ht_{config_.getNumBuckets (), memStart, compressor, config_.getHasher (),
@@ -1058,8 +1052,7 @@ ChainedHashTable::Container<T, HookPtr, LockT>::Container(
10581052
10591053 // Take page alignment into consideration when comparing the size of the
10601054 // shared memory and the size of the hashtable.
1061- if (nBytes !=
1062- util::getAlignedSize (ht_.size (), config_.getPageSize ().getPageSize ())) {
1055+ if (nBytes != util::getAlignedSize (ht_.size (), hugePageSize.getPageSize ())) {
10631056 throw std::invalid_argument (
10641057 fmt::format (" Hashtable size not compatible. old = {}, new = {}" ,
10651058 ht_.size (),
0 commit comments