@nxtedition/rocksdb 13.5.12 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/binding.cc +33 -2
  2. package/binding.gyp +2 -2
  3. package/chained-batch.js +9 -16
  4. package/deps/rocksdb/rocksdb/BUCK +18 -1
  5. package/deps/rocksdb/rocksdb/CMakeLists.txt +10 -3
  6. package/deps/rocksdb/rocksdb/Makefile +20 -9
  7. package/deps/rocksdb/rocksdb/cache/cache_bench_tool.cc +90 -13
  8. package/deps/rocksdb/rocksdb/cache/clock_cache.cc +88 -75
  9. package/deps/rocksdb/rocksdb/cache/clock_cache.h +44 -36
  10. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.cc +184 -148
  11. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache.h +5 -11
  12. package/deps/rocksdb/rocksdb/cache/compressed_secondary_cache_test.cc +116 -47
  13. package/deps/rocksdb/rocksdb/cache/lru_cache_test.cc +1 -1
  14. package/deps/rocksdb/rocksdb/cache/secondary_cache_adapter.cc +3 -6
  15. package/deps/rocksdb/rocksdb/db/arena_wrapped_db_iter.h +1 -1
  16. package/deps/rocksdb/rocksdb/db/builder.cc +4 -2
  17. package/deps/rocksdb/rocksdb/db/c.cc +207 -0
  18. package/deps/rocksdb/rocksdb/db/c_test.c +72 -0
  19. package/deps/rocksdb/rocksdb/db/column_family.cc +3 -2
  20. package/deps/rocksdb/rocksdb/db/column_family.h +5 -0
  21. package/deps/rocksdb/rocksdb/db/compact_files_test.cc +4 -0
  22. package/deps/rocksdb/rocksdb/db/compaction/compaction.cc +2 -0
  23. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.cc +51 -38
  24. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator.h +29 -12
  25. package/deps/rocksdb/rocksdb/db/compaction/compaction_iterator_test.cc +5 -10
  26. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.cc +566 -366
  27. package/deps/rocksdb/rocksdb/db/compaction/compaction_job.h +131 -4
  28. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.cc +1 -0
  29. package/deps/rocksdb/rocksdb/db/compaction/compaction_outputs.h +7 -0
  30. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.cc +4 -4
  31. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker.h +13 -14
  32. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.cc +12 -7
  33. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_fifo.h +8 -10
  34. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_test.cc +97 -76
  35. package/deps/rocksdb/rocksdb/db/compaction/compaction_picker_universal.cc +11 -14
  36. package/deps/rocksdb/rocksdb/db/compaction/compaction_service_job.cc +1 -1
  37. package/deps/rocksdb/rocksdb/db/compaction/subcompaction_state.h +8 -0
  38. package/deps/rocksdb/rocksdb/db/compaction/tiered_compaction_test.cc +16 -3
  39. package/deps/rocksdb/rocksdb/db/db_basic_test.cc +1 -0
  40. package/deps/rocksdb/rocksdb/db/db_compaction_test.cc +448 -1
  41. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.cc +22 -20
  42. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +4 -1
  43. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_compaction_flush.cc +5 -5
  44. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +7 -3
  45. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -1
  46. package/deps/rocksdb/rocksdb/db/db_iter.cc +104 -0
  47. package/deps/rocksdb/rocksdb/db/db_iter.h +4 -11
  48. package/deps/rocksdb/rocksdb/db/db_iterator_test.cc +331 -58
  49. package/deps/rocksdb/rocksdb/db/db_memtable_test.cc +129 -0
  50. package/deps/rocksdb/rocksdb/db/db_sst_test.cc +64 -0
  51. package/deps/rocksdb/rocksdb/db/db_table_properties_test.cc +40 -0
  52. package/deps/rocksdb/rocksdb/db/db_test2.cc +25 -15
  53. package/deps/rocksdb/rocksdb/db/db_test_util.cc +42 -24
  54. package/deps/rocksdb/rocksdb/db/db_test_util.h +29 -14
  55. package/deps/rocksdb/rocksdb/db/db_universal_compaction_test.cc +69 -36
  56. package/deps/rocksdb/rocksdb/db/db_with_timestamp_basic_test.cc +0 -1
  57. package/deps/rocksdb/rocksdb/db/event_helpers.cc +1 -0
  58. package/deps/rocksdb/rocksdb/db/experimental.cc +5 -4
  59. package/deps/rocksdb/rocksdb/db/external_sst_file_basic_test.cc +8 -1
  60. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.cc +275 -79
  61. package/deps/rocksdb/rocksdb/db/external_sst_file_ingestion_job.h +23 -5
  62. package/deps/rocksdb/rocksdb/db/external_sst_file_test.cc +591 -175
  63. package/deps/rocksdb/rocksdb/db/flush_job.cc +3 -4
  64. package/deps/rocksdb/rocksdb/db/log_reader.cc +5 -2
  65. package/deps/rocksdb/rocksdb/db/memtable.cc +84 -35
  66. package/deps/rocksdb/rocksdb/db/memtable.h +39 -34
  67. package/deps/rocksdb/rocksdb/db/merge_helper.cc +1 -0
  68. package/deps/rocksdb/rocksdb/db/merge_operator.cc +1 -1
  69. package/deps/rocksdb/rocksdb/db/multi_scan.cc +11 -5
  70. package/deps/rocksdb/rocksdb/db/version_edit.cc +1 -1
  71. package/deps/rocksdb/rocksdb/db/version_edit.h +1 -1
  72. package/deps/rocksdb/rocksdb/db/version_edit_handler.cc +34 -14
  73. package/deps/rocksdb/rocksdb/db/version_edit_handler.h +28 -5
  74. package/deps/rocksdb/rocksdb/db/version_set.cc +159 -14
  75. package/deps/rocksdb/rocksdb/db/version_set.h +2 -0
  76. package/deps/rocksdb/rocksdb/db_stress_tool/CMakeLists.txt +1 -1
  77. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.cc +60 -0
  78. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_common.h +16 -1
  79. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_compaction_service.h +75 -10
  80. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_compression_manager.cc +28 -0
  81. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_compression_manager.h +2 -0
  82. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_driver.cc +31 -1
  83. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_gflags.cc +50 -2
  84. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_shared_state.h +57 -0
  85. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_stat.h +0 -4
  86. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.cc +266 -35
  87. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_test_base.h +5 -0
  88. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_tool.cc +0 -6
  89. package/deps/rocksdb/rocksdb/db_stress_tool/no_batched_ops_stress.cc +18 -2
  90. package/deps/rocksdb/rocksdb/env/env.cc +12 -0
  91. package/deps/rocksdb/rocksdb/env/env_test.cc +18 -0
  92. package/deps/rocksdb/rocksdb/env/file_system_tracer.cc +2 -0
  93. package/deps/rocksdb/rocksdb/env/fs_posix.cc +9 -5
  94. package/deps/rocksdb/rocksdb/env/io_posix.cc +4 -2
  95. package/deps/rocksdb/rocksdb/file/random_access_file_reader.cc +19 -0
  96. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_compression.h +33 -31
  97. package/deps/rocksdb/rocksdb/include/rocksdb/advanced_options.h +42 -9
  98. package/deps/rocksdb/rocksdb/include/rocksdb/c.h +93 -0
  99. package/deps/rocksdb/rocksdb/include/rocksdb/cache.h +43 -49
  100. package/deps/rocksdb/rocksdb/include/rocksdb/compaction_job_stats.h +4 -3
  101. package/deps/rocksdb/rocksdb/include/rocksdb/compression_type.h +8 -6
  102. package/deps/rocksdb/rocksdb/include/rocksdb/data_structure.h +487 -0
  103. package/deps/rocksdb/rocksdb/include/rocksdb/db.h +11 -12
  104. package/deps/rocksdb/rocksdb/include/rocksdb/env.h +135 -1
  105. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +5 -0
  106. package/deps/rocksdb/rocksdb/include/rocksdb/iostats_context.h +12 -0
  107. package/deps/rocksdb/rocksdb/include/rocksdb/iterator.h +1 -1
  108. package/deps/rocksdb/rocksdb/include/rocksdb/ldb_tool.h +8 -0
  109. package/deps/rocksdb/rocksdb/include/rocksdb/memtablerep.h +12 -8
  110. package/deps/rocksdb/rocksdb/include/rocksdb/metadata.h +3 -0
  111. package/deps/rocksdb/rocksdb/include/rocksdb/multi_scan.h +19 -9
  112. package/deps/rocksdb/rocksdb/include/rocksdb/options.h +219 -24
  113. package/deps/rocksdb/rocksdb/include/rocksdb/point_lock_bench_tool.h +14 -0
  114. package/deps/rocksdb/rocksdb/include/rocksdb/secondary_cache.h +2 -2
  115. package/deps/rocksdb/rocksdb/include/rocksdb/slice.h +1 -1
  116. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +7 -0
  117. package/deps/rocksdb/rocksdb/include/rocksdb/status.h +16 -0
  118. package/deps/rocksdb/rocksdb/include/rocksdb/table.h +16 -4
  119. package/deps/rocksdb/rocksdb/include/rocksdb/table_properties.h +13 -0
  120. package/deps/rocksdb/rocksdb/include/rocksdb/types.h +4 -0
  121. package/deps/rocksdb/rocksdb/include/rocksdb/universal_compaction.h +0 -2
  122. package/deps/rocksdb/rocksdb/include/rocksdb/user_defined_index.h +45 -0
  123. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/cache_dump_load.h +1 -1
  124. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/stackable_db.h +1 -1
  125. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/transaction.h +6 -1
  126. package/deps/rocksdb/rocksdb/include/rocksdb/utilities/transaction_db.h +21 -0
  127. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +2 -2
  128. package/deps/rocksdb/rocksdb/memory/memory_allocator_impl.h +3 -3
  129. package/deps/rocksdb/rocksdb/memtable/inlineskiplist.h +77 -51
  130. package/deps/rocksdb/rocksdb/memtable/skiplist.h +10 -13
  131. package/deps/rocksdb/rocksdb/memtable/skiplistrep.cc +16 -7
  132. package/deps/rocksdb/rocksdb/memtable/vectorrep.cc +9 -4
  133. package/deps/rocksdb/rocksdb/monitoring/iostats_context.cc +2 -0
  134. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +6 -0
  135. package/deps/rocksdb/rocksdb/options/cf_options.cc +13 -1
  136. package/deps/rocksdb/rocksdb/options/cf_options.h +6 -2
  137. package/deps/rocksdb/rocksdb/options/options.cc +2 -0
  138. package/deps/rocksdb/rocksdb/options/options_helper.cc +9 -8
  139. package/deps/rocksdb/rocksdb/options/options_settable_test.cc +9 -5
  140. package/deps/rocksdb/rocksdb/port/mmap.cc +1 -1
  141. package/deps/rocksdb/rocksdb/port/win/xpress_win.cc +51 -0
  142. package/deps/rocksdb/rocksdb/port/win/xpress_win.h +4 -0
  143. package/deps/rocksdb/rocksdb/src.mk +8 -2
  144. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.cc +1125 -765
  145. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_builder.h +35 -24
  146. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_factory.cc +29 -4
  147. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.cc +732 -256
  148. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_iterator.h +225 -16
  149. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.cc +102 -26
  150. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +1 -1
  151. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_sync_and_async.h +2 -75
  152. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +433 -141
  153. package/deps/rocksdb/rocksdb/table/block_based/block_builder.h +2 -0
  154. package/deps/rocksdb/rocksdb/table/block_based/flush_block_policy.cc +17 -10
  155. package/deps/rocksdb/rocksdb/table/block_based/flush_block_policy_impl.h +20 -0
  156. package/deps/rocksdb/rocksdb/table/block_based/index_builder.cc +112 -85
  157. package/deps/rocksdb/rocksdb/table/block_based/index_builder.h +191 -36
  158. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block.cc +2 -2
  159. package/deps/rocksdb/rocksdb/table/block_based/partitioned_filter_block_test.cc +1 -1
  160. package/deps/rocksdb/rocksdb/table/block_based/user_defined_index_wrapper.h +108 -31
  161. package/deps/rocksdb/rocksdb/table/external_table.cc +7 -3
  162. package/deps/rocksdb/rocksdb/table/format.cc +6 -12
  163. package/deps/rocksdb/rocksdb/table/format.h +10 -0
  164. package/deps/rocksdb/rocksdb/table/internal_iterator.h +1 -1
  165. package/deps/rocksdb/rocksdb/table/iterator_wrapper.h +1 -1
  166. package/deps/rocksdb/rocksdb/table/merging_iterator.cc +1 -1
  167. package/deps/rocksdb/rocksdb/table/meta_blocks.cc +5 -0
  168. package/deps/rocksdb/rocksdb/table/multiget_context.h +3 -1
  169. package/deps/rocksdb/rocksdb/table/sst_file_dumper.cc +118 -46
  170. package/deps/rocksdb/rocksdb/table/sst_file_dumper.h +9 -8
  171. package/deps/rocksdb/rocksdb/table/table_builder.h +5 -0
  172. package/deps/rocksdb/rocksdb/table/table_properties.cc +16 -0
  173. package/deps/rocksdb/rocksdb/table/table_test.cc +1540 -155
  174. package/deps/rocksdb/rocksdb/test_util/testutil.h +21 -5
  175. package/deps/rocksdb/rocksdb/tools/db_bench_tool.cc +26 -5
  176. package/deps/rocksdb/rocksdb/tools/ldb.cc +1 -2
  177. package/deps/rocksdb/rocksdb/tools/ldb_cmd.cc +2 -0
  178. package/deps/rocksdb/rocksdb/tools/ldb_tool.cc +9 -3
  179. package/deps/rocksdb/rocksdb/tools/sst_dump_test.cc +133 -165
  180. package/deps/rocksdb/rocksdb/tools/sst_dump_tool.cc +173 -64
  181. package/deps/rocksdb/rocksdb/util/aligned_buffer.h +69 -0
  182. package/deps/rocksdb/rocksdb/util/atomic.h +6 -0
  183. package/deps/rocksdb/rocksdb/util/auto_tune_compressor.cc +29 -20
  184. package/deps/rocksdb/rocksdb/util/auto_tune_compressor.h +10 -6
  185. package/deps/rocksdb/rocksdb/util/bit_fields.h +338 -0
  186. package/deps/rocksdb/rocksdb/util/coding.h +3 -3
  187. package/deps/rocksdb/rocksdb/util/compaction_job_stats_impl.cc +2 -2
  188. package/deps/rocksdb/rocksdb/util/compression.cc +777 -82
  189. package/deps/rocksdb/rocksdb/util/compression.h +5 -0
  190. package/deps/rocksdb/rocksdb/util/compression_test.cc +5 -3
  191. package/deps/rocksdb/rocksdb/util/dynamic_bloom.cc +2 -2
  192. package/deps/rocksdb/rocksdb/util/dynamic_bloom.h +15 -14
  193. package/deps/rocksdb/rocksdb/util/interval_test.cc +102 -0
  194. package/deps/rocksdb/rocksdb/util/semaphore.h +164 -0
  195. package/deps/rocksdb/rocksdb/util/simple_mixed_compressor.cc +10 -6
  196. package/deps/rocksdb/rocksdb/util/simple_mixed_compressor.h +4 -2
  197. package/deps/rocksdb/rocksdb/util/slice_test.cc +136 -0
  198. package/deps/rocksdb/rocksdb/util/status.cc +1 -0
  199. package/deps/rocksdb/rocksdb/util/string_util.cc +2 -16
  200. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.cc +1 -1
  201. package/deps/rocksdb/rocksdb/utilities/cache_dump_load_impl.h +1 -1
  202. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.cc +7 -4
  203. package/deps/rocksdb/rocksdb/utilities/fault_injection_fs.h +35 -14
  204. package/deps/rocksdb/rocksdb/utilities/persistent_cache/hash_table_test.cc +2 -0
  205. package/deps/rocksdb/rocksdb/utilities/transactions/lock/lock_manager.cc +5 -2
  206. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/any_lock_manager_test.h +244 -0
  207. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_bench.cc +18 -0
  208. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_bench_tool.cc +159 -0
  209. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager.cc +1244 -161
  210. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager.h +66 -12
  211. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager_stress_test.cc +103 -0
  212. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager_test.cc +1275 -8
  213. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager_test.h +40 -262
  214. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_manager_test_common.h +78 -0
  215. package/deps/rocksdb/rocksdb/utilities/transactions/lock/point/point_lock_validation_test_runner.h +469 -0
  216. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_locking_test.cc +2 -6
  217. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.cc +4 -0
  218. package/deps/rocksdb/rocksdb/utilities/transactions/pessimistic_transaction.h +9 -1
  219. package/deps/rocksdb/rocksdb/utilities/transactions/timestamped_snapshot_test.cc +18 -9
  220. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_base.h +2 -0
  221. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_db_mutex_impl.cc +2 -1
  222. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.cc +72 -44
  223. package/deps/rocksdb/rocksdb/utilities/transactions/transaction_test.h +92 -15
  224. package/deps/rocksdb/rocksdb/utilities/transactions/write_committed_transaction_ts_test.cc +6 -20
  225. package/deps/rocksdb/rocksdb/utilities/transactions/write_prepared_transaction_test.cc +143 -112
  226. package/deps/rocksdb/rocksdb/utilities/transactions/write_unprepared_transaction_test.cc +23 -16
  227. package/index.js +3 -3
  228. package/package.json +1 -1
  229. package/prebuilds/darwin-arm64/@nxtedition+rocksdb.node +0 -0
  230. package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
  231. package/util.h +38 -12
  232. package/deps/rocksdb/rocksdb/db_stress_tool/db_stress_stat.cc +0 -17
@@ -10,12 +10,12 @@
10
10
  #include "cache/clock_cache.h"
11
11
 
12
12
  #include <algorithm>
13
- #include <atomic>
14
13
  #include <bitset>
15
14
  #include <cassert>
16
15
  #include <cinttypes>
17
16
  #include <cstddef>
18
17
  #include <cstdint>
18
+ #include <cstdio>
19
19
  #include <exception>
20
20
  #include <functional>
21
21
  #include <numeric>
@@ -26,10 +26,9 @@
26
26
  #include "cache/cache_key.h"
27
27
  #include "cache/secondary_cache_adapter.h"
28
28
  #include "logging/logging.h"
29
- #include "monitoring/perf_context_imp.h"
30
- #include "monitoring/statistics_impl.h"
31
- #include "port/lang.h"
29
+ #include "port/likely.h"
32
30
  #include "rocksdb/env.h"
31
+ #include "util/autovector.h"
33
32
  #include "util/hash.h"
34
33
  #include "util/math.h"
35
34
  #include "util/random.h"
@@ -361,16 +360,9 @@ void ConstApplyToEntriesRange(const Func& func, const HandleImpl* begin,
361
360
  }
362
361
  }
363
362
 
364
- constexpr uint32_t kStrictCapacityLimitBit = 1u << 31;
365
-
366
- uint32_t SanitizeEncodeEecAndScl(int eviction_effort_cap,
367
- bool strict_capacit_limit) {
363
+ uint32_t SanitizeEvictionEffortCap(int eviction_effort_cap) {
368
364
  eviction_effort_cap = std::max(int{1}, eviction_effort_cap);
369
- eviction_effort_cap =
370
- std::min(static_cast<int>(~kStrictCapacityLimitBit), eviction_effort_cap);
371
- uint32_t eec_and_scl = static_cast<uint32_t>(eviction_effort_cap);
372
- eec_and_scl |= strict_capacit_limit ? kStrictCapacityLimitBit : 0;
373
- return eec_and_scl;
365
+ return static_cast<uint32_t>(eviction_effort_cap);
374
366
  }
375
367
 
376
368
  } // namespace
@@ -381,6 +373,22 @@ void ClockHandleBasicData::FreeData(MemoryAllocator* allocator) const {
381
373
  }
382
374
  }
383
375
 
376
+ BaseClockTable::BaseClockTable(size_t capacity, bool strict_capacity_limit,
377
+ int eviction_effort_cap,
378
+ CacheMetadataChargePolicy metadata_charge_policy,
379
+ MemoryAllocator* allocator,
380
+ const Cache::EvictionCallback* eviction_callback,
381
+ const uint32_t* hash_seed)
382
+ : capacity_(capacity),
383
+ eec_and_scl_(EecAndScl{}
384
+ .With<EvictionEffortCap>(
385
+ SanitizeEvictionEffortCap(eviction_effort_cap))
386
+ .With<StrictCapacityLimit>(strict_capacity_limit)),
387
+ metadata_charge_policy_(metadata_charge_policy),
388
+ allocator_(allocator),
389
+ eviction_callback_(*eviction_callback),
390
+ hash_seed_(*hash_seed) {}
391
+
384
392
  template <class HandleImpl>
385
393
  HandleImpl* BaseClockTable::StandaloneInsert(
386
394
  const ClockHandleBasicData& proto) {
@@ -402,8 +410,7 @@ HandleImpl* BaseClockTable::StandaloneInsert(
402
410
 
403
411
  template <class Table>
404
412
  typename Table::HandleImpl* BaseClockTable::CreateStandalone(
405
- ClockHandleBasicData& proto, size_t capacity, uint32_t eec_and_scl,
406
- bool allow_uncharged) {
413
+ ClockHandleBasicData& proto, bool allow_uncharged) {
407
414
  Table& derived = static_cast<Table&>(*this);
408
415
  typename Table::InsertState state;
409
416
  derived.StartInsert(state);
@@ -412,10 +419,10 @@ typename Table::HandleImpl* BaseClockTable::CreateStandalone(
412
419
  // NOTE: we can use eec_and_scl as eviction_effort_cap below because
413
420
  // strict_capacity_limit=true is supposed to disable the limit on eviction
414
421
  // effort, and a large value effectively does that.
415
- if (eec_and_scl & kStrictCapacityLimitBit) {
422
+ if (eec_and_scl_.LoadRelaxed().Get<StrictCapacityLimit>()) {
416
423
  Status s = ChargeUsageMaybeEvictStrict<Table>(
417
- total_charge, capacity,
418
- /*need_evict_for_occupancy=*/false, eec_and_scl, state);
424
+ total_charge,
425
+ /*need_evict_for_occupancy=*/false, state);
419
426
  if (!s.ok()) {
420
427
  if (allow_uncharged) {
421
428
  proto.total_charge = 0;
@@ -426,8 +433,8 @@ typename Table::HandleImpl* BaseClockTable::CreateStandalone(
426
433
  } else {
427
434
  // Case strict_capacity_limit == false
428
435
  bool success = ChargeUsageMaybeEvictNonStrict<Table>(
429
- total_charge, capacity,
430
- /*need_evict_for_occupancy=*/false, eec_and_scl, state);
436
+ total_charge,
437
+ /*need_evict_for_occupancy=*/false, state);
431
438
  if (!success) {
432
439
  // Force the issue
433
440
  usage_.FetchAddRelaxed(total_charge);
@@ -439,8 +446,9 @@ typename Table::HandleImpl* BaseClockTable::CreateStandalone(
439
446
 
440
447
  template <class Table>
441
448
  Status BaseClockTable::ChargeUsageMaybeEvictStrict(
442
- size_t total_charge, size_t capacity, bool need_evict_for_occupancy,
443
- uint32_t eviction_effort_cap, typename Table::InsertState& state) {
449
+ size_t total_charge, bool need_evict_for_occupancy,
450
+ typename Table::InsertState& state) {
451
+ const size_t capacity = capacity_.LoadRelaxed();
444
452
  if (total_charge > capacity) {
445
453
  return Status::MemoryLimit(
446
454
  "Cache entry too large for a single cache shard: " +
@@ -465,8 +473,7 @@ Status BaseClockTable::ChargeUsageMaybeEvictStrict(
465
473
  }
466
474
  if (request_evict_charge > 0) {
467
475
  EvictionData data;
468
- static_cast<Table*>(this)->Evict(request_evict_charge, state, &data,
469
- eviction_effort_cap);
476
+ static_cast<Table*>(this)->Evict(request_evict_charge, state, &data);
470
477
  occupancy_.FetchSub(data.freed_count);
471
478
  if (LIKELY(data.freed_charge > need_evict_charge)) {
472
479
  assert(data.freed_count > 0);
@@ -495,8 +502,8 @@ Status BaseClockTable::ChargeUsageMaybeEvictStrict(
495
502
 
496
503
  template <class Table>
497
504
  inline bool BaseClockTable::ChargeUsageMaybeEvictNonStrict(
498
- size_t total_charge, size_t capacity, bool need_evict_for_occupancy,
499
- uint32_t eviction_effort_cap, typename Table::InsertState& state) {
505
+ size_t total_charge, bool need_evict_for_occupancy,
506
+ typename Table::InsertState& state) {
500
507
  // For simplicity, we consider that either the cache can accept the insert
501
508
  // with no evictions, or we must evict enough to make (at least) enough
502
509
  // space. It could lead to unnecessary failures or excessive evictions in
@@ -506,7 +513,8 @@ inline bool BaseClockTable::ChargeUsageMaybeEvictNonStrict(
506
513
  // charge. Thus, we should evict some extra if it's not a signifcant
507
514
  // portion of the shard capacity. This can have the side benefit of
508
515
  // involving fewer threads in eviction.
509
- size_t old_usage = usage_.LoadRelaxed();
516
+ const size_t old_usage = usage_.LoadRelaxed();
517
+ const size_t capacity = capacity_.LoadRelaxed();
510
518
  size_t need_evict_charge;
511
519
  // NOTE: if total_charge > old_usage, there isn't yet enough to evict
512
520
  // `total_charge` amount. Even if we only try to evict `old_usage` amount,
@@ -532,8 +540,7 @@ inline bool BaseClockTable::ChargeUsageMaybeEvictNonStrict(
532
540
  }
533
541
  EvictionData data;
534
542
  if (need_evict_charge > 0) {
535
- static_cast<Table*>(this)->Evict(need_evict_charge, state, &data,
536
- eviction_effort_cap);
543
+ static_cast<Table*>(this)->Evict(need_evict_charge, state, &data);
537
544
  // Deal with potential occupancy deficit
538
545
  if (UNLIKELY(need_evict_for_occupancy) && data.freed_count == 0) {
539
546
  assert(data.freed_charge == 0);
@@ -569,8 +576,10 @@ void BaseClockTable::TrackAndReleaseEvictedEntry(ClockHandle* h) {
569
576
  MarkEmpty(*h);
570
577
  }
571
578
 
572
- bool IsEvictionEffortExceeded(const BaseClockTable::EvictionData& data,
573
- uint32_t eviction_effort_cap) {
579
+ bool BaseClockTable::IsEvictionEffortExceeded(
580
+ const BaseClockTable::EvictionData& data) const {
581
+ auto eviction_effort_cap =
582
+ eec_and_scl_.LoadRelaxed().GetEffectiveEvictionEffortCap();
574
583
  // Basically checks whether the ratio of useful effort to wasted effort is
575
584
  // too low, with a start-up allowance for wasted effort before any useful
576
585
  // effort.
@@ -581,8 +590,7 @@ bool IsEvictionEffortExceeded(const BaseClockTable::EvictionData& data,
581
590
  template <class Table>
582
591
  Status BaseClockTable::Insert(const ClockHandleBasicData& proto,
583
592
  typename Table::HandleImpl** handle,
584
- Cache::Priority priority, size_t capacity,
585
- uint32_t eec_and_scl) {
593
+ Cache::Priority priority) {
586
594
  using HandleImpl = typename Table::HandleImpl;
587
595
  Table& derived = static_cast<Table&>(*this);
588
596
 
@@ -603,9 +611,9 @@ Status BaseClockTable::Insert(const ClockHandleBasicData& proto,
603
611
  // NOTE: we can use eec_and_scl as eviction_effort_cap below because
604
612
  // strict_capacity_limit=true is supposed to disable the limit on eviction
605
613
  // effort, and a large value effectively does that.
606
- if (eec_and_scl & kStrictCapacityLimitBit) {
614
+ if (eec_and_scl_.LoadRelaxed().Get<StrictCapacityLimit>()) {
607
615
  Status s = ChargeUsageMaybeEvictStrict<Table>(
608
- total_charge, capacity, need_evict_for_occupancy, eec_and_scl, state);
616
+ total_charge, need_evict_for_occupancy, state);
609
617
  if (!s.ok()) {
610
618
  // Revert occupancy
611
619
  occupancy_.FetchSubRelaxed(1);
@@ -614,7 +622,7 @@ Status BaseClockTable::Insert(const ClockHandleBasicData& proto,
614
622
  } else {
615
623
  // Case strict_capacity_limit == false
616
624
  bool success = ChargeUsageMaybeEvictNonStrict<Table>(
617
- total_charge, capacity, need_evict_for_occupancy, eec_and_scl, state);
625
+ total_charge, need_evict_for_occupancy, state);
618
626
  if (!success) {
619
627
  // Revert occupancy
620
628
  occupancy_.FetchSubRelaxed(1);
@@ -718,11 +726,13 @@ void BaseClockTable::TEST_ReleaseNMinus1(ClockHandle* h, size_t n) {
718
726
  #endif
719
727
 
720
728
  FixedHyperClockTable::FixedHyperClockTable(
721
- size_t capacity, CacheMetadataChargePolicy metadata_charge_policy,
729
+ size_t capacity, bool strict_capacity_limit,
730
+ CacheMetadataChargePolicy metadata_charge_policy,
722
731
  MemoryAllocator* allocator,
723
732
  const Cache::EvictionCallback* eviction_callback, const uint32_t* hash_seed,
724
733
  const Opts& opts)
725
- : BaseClockTable(metadata_charge_policy, allocator, eviction_callback,
734
+ : BaseClockTable(capacity, strict_capacity_limit, opts.eviction_effort_cap,
735
+ metadata_charge_policy, allocator, eviction_callback,
726
736
  hash_seed),
727
737
  length_bits_(CalcHashBits(capacity, opts.estimated_value_size,
728
738
  metadata_charge_policy)),
@@ -1113,8 +1123,7 @@ inline void FixedHyperClockTable::ReclaimEntryUsage(size_t total_charge) {
1113
1123
  }
1114
1124
 
1115
1125
  inline void FixedHyperClockTable::Evict(size_t requested_charge, InsertState&,
1116
- EvictionData* data,
1117
- uint32_t eviction_effort_cap) {
1126
+ EvictionData* data) {
1118
1127
  // precondition
1119
1128
  assert(requested_charge > 0);
1120
1129
 
@@ -1149,7 +1158,7 @@ inline void FixedHyperClockTable::Evict(size_t requested_charge, InsertState&,
1149
1158
  if (old_clock_pointer >= max_clock_pointer) {
1150
1159
  return;
1151
1160
  }
1152
- if (IsEvictionEffortExceeded(*data, eviction_effort_cap)) {
1161
+ if (IsEvictionEffortExceeded(*data)) {
1153
1162
  eviction_effort_exceeded_count_.FetchAddRelaxed(1);
1154
1163
  return;
1155
1164
  }
@@ -1167,14 +1176,11 @@ ClockCacheShard<Table>::ClockCacheShard(
1167
1176
  const Cache::EvictionCallback* eviction_callback, const uint32_t* hash_seed,
1168
1177
  const typename Table::Opts& opts)
1169
1178
  : CacheShardBase(metadata_charge_policy),
1170
- table_(capacity, metadata_charge_policy, allocator, eviction_callback,
1171
- hash_seed, opts),
1172
- capacity_(capacity),
1173
- eec_and_scl_(SanitizeEncodeEecAndScl(opts.eviction_effort_cap,
1174
- strict_capacity_limit)) {
1179
+ table_(capacity, strict_capacity_limit, metadata_charge_policy, allocator,
1180
+ eviction_callback, hash_seed, opts) {
1175
1181
  // Initial charge metadata should not exceed capacity
1176
- assert(table_.GetUsage() <= capacity_.LoadRelaxed() ||
1177
- capacity_.LoadRelaxed() < sizeof(HandleImpl));
1182
+ assert(table_.GetUsage() <= table_.GetCapacity() ||
1183
+ table_.GetCapacity() < sizeof(HandleImpl));
1178
1184
  }
1179
1185
 
1180
1186
  template <class Table>
@@ -1240,18 +1246,14 @@ int FixedHyperClockTable::CalcHashBits(
1240
1246
 
1241
1247
  template <class Table>
1242
1248
  void ClockCacheShard<Table>::SetCapacity(size_t capacity) {
1243
- capacity_.StoreRelaxed(capacity);
1249
+ table_.SetCapacity(capacity);
1244
1250
  // next Insert will take care of any necessary evictions
1245
1251
  }
1246
1252
 
1247
1253
  template <class Table>
1248
1254
  void ClockCacheShard<Table>::SetStrictCapacityLimit(
1249
1255
  bool strict_capacity_limit) {
1250
- if (strict_capacity_limit) {
1251
- eec_and_scl_.FetchOrRelaxed(kStrictCapacityLimitBit);
1252
- } else {
1253
- eec_and_scl_.FetchAndRelaxed(~kStrictCapacityLimitBit);
1254
- }
1256
+ table_.SetStrictCapacityLimit(strict_capacity_limit);
1255
1257
  // next Insert will take care of any necessary evictions
1256
1258
  }
1257
1259
 
@@ -1271,9 +1273,7 @@ Status ClockCacheShard<Table>::Insert(const Slice& key,
1271
1273
  proto.value = value;
1272
1274
  proto.helper = helper;
1273
1275
  proto.total_charge = charge;
1274
- return table_.template Insert<Table>(proto, handle, priority,
1275
- capacity_.LoadRelaxed(),
1276
- eec_and_scl_.LoadRelaxed());
1276
+ return table_.template Insert<Table>(proto, handle, priority);
1277
1277
  }
1278
1278
 
1279
1279
  template <class Table>
@@ -1288,9 +1288,7 @@ typename Table::HandleImpl* ClockCacheShard<Table>::CreateStandalone(
1288
1288
  proto.value = obj;
1289
1289
  proto.helper = helper;
1290
1290
  proto.total_charge = charge;
1291
- return table_.template CreateStandalone<Table>(proto, capacity_.LoadRelaxed(),
1292
- eec_and_scl_.LoadRelaxed(),
1293
- allow_uncharged);
1291
+ return table_.template CreateStandalone<Table>(proto, allow_uncharged);
1294
1292
  }
1295
1293
 
1296
1294
  template <class Table>
@@ -1359,7 +1357,7 @@ size_t ClockCacheShard<Table>::GetStandaloneUsage() const {
1359
1357
 
1360
1358
  template <class Table>
1361
1359
  size_t ClockCacheShard<Table>::GetCapacity() const {
1362
- return capacity_.LoadRelaxed();
1360
+ return table_.GetCapacity();
1363
1361
  }
1364
1362
 
1365
1363
  template <class Table>
@@ -1727,10 +1725,13 @@ inline uint64_t UsedLengthToLengthInfo(size_t used_length) {
1727
1725
  return length_info;
1728
1726
  }
1729
1727
 
1728
+ // Avoid potential initialization order race with port::kPageSize
1729
+ constexpr size_t kPresumedPageSize = 4096;
1730
+
1730
1731
  inline size_t GetStartingLength(size_t capacity) {
1731
- if (capacity > port::kPageSize) {
1732
+ if (capacity > kPresumedPageSize) {
1732
1733
  // Start with one memory page
1733
- return port::kPageSize / sizeof(AutoHyperClockTable::HandleImpl);
1734
+ return kPresumedPageSize / sizeof(AutoHyperClockTable::HandleImpl);
1734
1735
  } else {
1735
1736
  // Mostly to make unit tests happy
1736
1737
  return 4;
@@ -1969,11 +1970,13 @@ class AutoHyperClockTable::ChainRewriteLock {
1969
1970
  };
1970
1971
 
1971
1972
  AutoHyperClockTable::AutoHyperClockTable(
1972
- size_t capacity, CacheMetadataChargePolicy metadata_charge_policy,
1973
+ size_t capacity, bool strict_capacity_limit,
1974
+ CacheMetadataChargePolicy metadata_charge_policy,
1973
1975
  MemoryAllocator* allocator,
1974
1976
  const Cache::EvictionCallback* eviction_callback, const uint32_t* hash_seed,
1975
1977
  const Opts& opts)
1976
- : BaseClockTable(metadata_charge_policy, allocator, eviction_callback,
1978
+ : BaseClockTable(capacity, strict_capacity_limit, opts.eviction_effort_cap,
1979
+ metadata_charge_policy, allocator, eviction_callback,
1977
1980
  hash_seed),
1978
1981
  array_(MemMapping::AllocateLazyZeroed(
1979
1982
  sizeof(HandleImpl) * CalcMaxUsableLength(capacity,
@@ -1985,6 +1988,11 @@ AutoHyperClockTable::AutoHyperClockTable(
1985
1988
  grow_frontier_(GetTableSize()),
1986
1989
  clock_pointer_mask_(
1987
1990
  BottomNBits(UINT64_MAX, LengthInfoToMinShift(length_info_.Load()))) {
1991
+ if (array_.Get() == nullptr) {
1992
+ fprintf(stderr,
1993
+ "Anonymous mmap for RocksDB HyperClockCache failed. Aborting.\n");
1994
+ std::terminate();
1995
+ }
1988
1996
  if (metadata_charge_policy ==
1989
1997
  CacheMetadataChargePolicy::kFullChargeCacheMetadata) {
1990
1998
  // NOTE: ignoring page boundaries for simplicity
@@ -2052,15 +2060,21 @@ AutoHyperClockTable::~AutoHyperClockTable() {
2052
2060
  HandleImpl::kUnusedMarker) {
2053
2061
  used_end++;
2054
2062
  }
2055
- #ifndef NDEBUG
2056
- for (size_t i = used_end; i < array_.Count(); i++) {
2063
+ // This check can be extra expensive for a cache that is just created,
2064
+ // maybe used for a small number of entries, as in a unit test, and then
2065
+ // destroyed. Only do this in rare modes. REVISED: Don't scan the whole mmap,
2066
+ // just a reasonable frontier past what we expect to have written.
2067
+ #ifdef MUST_FREE_HEAP_ALLOCATIONS
2068
+ for (size_t i = used_end; i < array_.Count() && i < used_end + 64U; i++) {
2057
2069
  assert(array_[i].head_next_with_shift.LoadRelaxed() == 0);
2058
2070
  assert(array_[i].chain_next_with_shift.LoadRelaxed() == 0);
2059
2071
  assert(array_[i].meta.LoadRelaxed() == 0);
2060
2072
  }
2073
+ #endif // MUST_FREE_HEAP_ALLOCATIONS
2074
+ #ifndef NDEBUG // Extra invariant checking
2061
2075
  std::vector<bool> was_populated(used_end);
2062
2076
  std::vector<bool> was_pointed_to(used_end);
2063
- #endif
2077
+ #endif // !NDEBUG
2064
2078
  for (size_t i = 0; i < used_end; i++) {
2065
2079
  HandleImpl& h = array_[i];
2066
2080
  switch (h.meta.LoadRelaxed() >> ClockHandle::kStateShift) {
@@ -2083,7 +2097,7 @@ AutoHyperClockTable::~AutoHyperClockTable() {
2083
2097
  assert(!was_pointed_to[next]);
2084
2098
  was_pointed_to[next] = true;
2085
2099
  }
2086
- #endif
2100
+ #endif // !NDEBUG
2087
2101
  break;
2088
2102
  // otherwise
2089
2103
  default:
@@ -2097,7 +2111,7 @@ AutoHyperClockTable::~AutoHyperClockTable() {
2097
2111
  assert(!was_pointed_to[next]);
2098
2112
  was_pointed_to[next] = true;
2099
2113
  }
2100
- #endif
2114
+ #endif // !NDEBUG
2101
2115
  }
2102
2116
  #ifndef NDEBUG // Extra invariant checking
2103
2117
  // This check is not perfect, but should detect most reasonable cases
@@ -2110,7 +2124,7 @@ AutoHyperClockTable::~AutoHyperClockTable() {
2110
2124
  assert(!was_pointed_to[i]);
2111
2125
  }
2112
2126
  }
2113
- #endif
2127
+ #endif // !NDEBUG
2114
2128
 
2115
2129
  // Metadata charging only follows the published table size
2116
2130
  assert(usage_.LoadRelaxed() == 0 ||
@@ -3468,8 +3482,7 @@ void AutoHyperClockTable::EraseUnRefEntries() {
3468
3482
  }
3469
3483
 
3470
3484
  void AutoHyperClockTable::Evict(size_t requested_charge, InsertState& state,
3471
- EvictionData* data,
3472
- uint32_t eviction_effort_cap) {
3485
+ EvictionData* data) {
3473
3486
  // precondition
3474
3487
  assert(requested_charge > 0);
3475
3488
 
@@ -3561,7 +3574,7 @@ void AutoHyperClockTable::Evict(size_t requested_charge, InsertState& state,
3561
3574
  return;
3562
3575
  }
3563
3576
 
3564
- if (IsEvictionEffortExceeded(*data, eviction_effort_cap)) {
3577
+ if (IsEvictionEffortExceeded(*data)) {
3565
3578
  eviction_effort_exceeded_count_.FetchAddRelaxed(1);
3566
3579
  return;
3567
3580
  }
@@ -3579,7 +3592,7 @@ size_t AutoHyperClockTable::CalcMaxUsableLength(
3579
3592
  size_t num_slots =
3580
3593
  static_cast<size_t>(capacity / min_avg_slot_charge + 0.999999);
3581
3594
 
3582
- const size_t slots_per_page = port::kPageSize / sizeof(HandleImpl);
3595
+ const size_t slots_per_page = kPresumedPageSize / sizeof(HandleImpl);
3583
3596
 
3584
3597
  // Round up to page size
3585
3598
  return ((num_slots + slots_per_page - 1) / slots_per_page) * slots_per_page;
@@ -9,8 +9,6 @@
9
9
 
10
10
  #pragma once
11
11
 
12
- #include <array>
13
- #include <atomic>
14
12
  #include <climits>
15
13
  #include <cstddef>
16
14
  #include <cstdint>
@@ -19,14 +17,10 @@
19
17
 
20
18
  #include "cache/cache_key.h"
21
19
  #include "cache/sharded_cache.h"
22
- #include "port/lang.h"
23
- #include "port/malloc.h"
24
20
  #include "port/mmap.h"
25
- #include "port/port.h"
26
21
  #include "rocksdb/cache.h"
27
- #include "rocksdb/secondary_cache.h"
28
22
  #include "util/atomic.h"
29
- #include "util/autovector.h"
23
+ #include "util/bit_fields.h"
30
24
  #include "util/math.h"
31
25
 
32
26
  namespace ROCKSDB_NAMESPACE {
@@ -383,25 +377,20 @@ class BaseClockTable {
383
377
  int eviction_effort_cap;
384
378
  };
385
379
 
386
- BaseClockTable(CacheMetadataChargePolicy metadata_charge_policy,
380
+ BaseClockTable(size_t capacity, bool strict_capacity_limit,
381
+ int eviction_effort_cap,
382
+ CacheMetadataChargePolicy metadata_charge_policy,
387
383
  MemoryAllocator* allocator,
388
384
  const Cache::EvictionCallback* eviction_callback,
389
- const uint32_t* hash_seed)
390
- : metadata_charge_policy_(metadata_charge_policy),
391
- allocator_(allocator),
392
- eviction_callback_(*eviction_callback),
393
- hash_seed_(*hash_seed) {}
385
+ const uint32_t* hash_seed);
394
386
 
395
387
  template <class Table>
396
388
  typename Table::HandleImpl* CreateStandalone(ClockHandleBasicData& proto,
397
- size_t capacity,
398
- uint32_t eec_and_scl,
399
389
  bool allow_uncharged);
400
390
 
401
391
  template <class Table>
402
392
  Status Insert(const ClockHandleBasicData& proto,
403
- typename Table::HandleImpl** handle, Cache::Priority priority,
404
- size_t capacity, uint32_t eec_and_scl);
393
+ typename Table::HandleImpl** handle, Cache::Priority priority);
405
394
 
406
395
  void Ref(ClockHandle& handle);
407
396
 
@@ -411,6 +400,18 @@ class BaseClockTable {
411
400
 
412
401
  size_t GetStandaloneUsage() const { return standalone_usage_.LoadRelaxed(); }
413
402
 
403
+ size_t GetCapacity() const { return capacity_.LoadRelaxed(); }
404
+
405
+ void SetCapacity(size_t capacity) { capacity_.StoreRelaxed(capacity); }
406
+
407
+ void SetStrictCapacityLimit(bool strict_capacity_limit) {
408
+ if (strict_capacity_limit) {
409
+ eec_and_scl_.ApplyRelaxed(StrictCapacityLimit::SetTransform());
410
+ } else {
411
+ eec_and_scl_.ApplyRelaxed(StrictCapacityLimit::ClearTransform());
412
+ }
413
+ }
414
+
414
415
  uint32_t GetHashSeed() const { return hash_seed_; }
415
416
 
416
417
  uint64_t GetYieldCount() const { return yield_count_.LoadRelaxed(); }
@@ -427,6 +428,7 @@ class BaseClockTable {
427
428
 
428
429
  void TrackAndReleaseEvictedEntry(ClockHandle* h);
429
430
 
431
+ bool IsEvictionEffortExceeded(const BaseClockTable::EvictionData& data) const;
430
432
  #ifndef NDEBUG
431
433
  // Acquire N references
432
434
  void TEST_RefN(ClockHandle& handle, size_t n);
@@ -448,9 +450,8 @@ class BaseClockTable {
448
450
  // required, and the operation should fail if not possible.
449
451
  // NOTE: Otherwise, occupancy_ is not managed in this function
450
452
  template <class Table>
451
- Status ChargeUsageMaybeEvictStrict(size_t total_charge, size_t capacity,
453
+ Status ChargeUsageMaybeEvictStrict(size_t total_charge,
452
454
  bool need_evict_for_occupancy,
453
- uint32_t eviction_effort_cap,
454
455
  typename Table::InsertState& state);
455
456
 
456
457
  // Helper for updating `usage_` for new entry with given `total_charge`
@@ -462,9 +463,8 @@ class BaseClockTable {
462
463
  // true, indicating success.
463
464
  // NOTE: occupancy_ is not managed in this function
464
465
  template <class Table>
465
- bool ChargeUsageMaybeEvictNonStrict(size_t total_charge, size_t capacity,
466
+ bool ChargeUsageMaybeEvictNonStrict(size_t total_charge,
466
467
  bool need_evict_for_occupancy,
467
- uint32_t eviction_effort_cap,
468
468
  typename Table::InsertState& state);
469
469
 
470
470
  protected: // data
@@ -497,6 +497,25 @@ class BaseClockTable {
497
497
  // Part of usage by standalone entries (not in table)
498
498
  AcqRelAtomic<size_t> standalone_usage_{};
499
499
 
500
+ // Maximum total charge of all elements stored in the table.
501
+ // (Relaxed: eventual consistency/update is OK)
502
+ RelaxedAtomic<size_t> capacity_;
503
+
504
+ // Encodes eviction_effort_cap (bottom 31 bits) and strict_capacity_limit
505
+ // (top bit). See HyperClockCacheOptions::eviction_effort_cap etc.
506
+ struct EecAndScl : public BitFields<uint32_t, EecAndScl> {
507
+ uint32_t GetEffectiveEvictionEffortCap() const {
508
+ // Because setting strict_capacity_limit is supposed to imply infinite
509
+ // cap on eviction effort, we can let the bit for strict_capacity_limit
510
+ // in the upper-most bit position to used as part of the effective cap.
511
+ return underlying;
512
+ }
513
+ };
514
+ using EvictionEffortCap = UnsignedBitField<EecAndScl, 31, NoPrevBitField>;
515
+ using StrictCapacityLimit = BoolBitField<EecAndScl, EvictionEffortCap>;
516
+ // (Relaxed: eventual consistency/update is OK)
517
+ RelaxedBitFieldsAtomic<EecAndScl> eec_and_scl_;
518
+
500
519
  ALIGN_AS(CACHE_LINE_SIZE)
501
520
  const CacheMetadataChargePolicy metadata_charge_policy_;
502
521
 
@@ -551,7 +570,7 @@ class FixedHyperClockTable : public BaseClockTable {
551
570
  size_t estimated_value_size;
552
571
  };
553
572
 
554
- FixedHyperClockTable(size_t capacity,
573
+ FixedHyperClockTable(size_t capacity, bool strict_capacity_limit,
555
574
  CacheMetadataChargePolicy metadata_charge_policy,
556
575
  MemoryAllocator* allocator,
557
576
  const Cache::EvictionCallback* eviction_callback,
@@ -573,8 +592,7 @@ class FixedHyperClockTable : public BaseClockTable {
573
592
  // Runs the clock eviction algorithm trying to reclaim at least
574
593
  // requested_charge. Returns how much is evicted, which could be less
575
594
  // if it appears impossible to evict the requested amount without blocking.
576
- void Evict(size_t requested_charge, InsertState& state, EvictionData* data,
577
- uint32_t eviction_effort_cap);
595
+ void Evict(size_t requested_charge, InsertState& state, EvictionData* data);
578
596
 
579
597
  HandleImpl* Lookup(const UniqueId64x2& hashed_key);
580
598
 
@@ -841,7 +859,7 @@ class AutoHyperClockTable : public BaseClockTable {
841
859
  size_t min_avg_value_size;
842
860
  };
843
861
 
844
- AutoHyperClockTable(size_t capacity,
862
+ AutoHyperClockTable(size_t capacity, bool strict_capacity_limit,
845
863
  CacheMetadataChargePolicy metadata_charge_policy,
846
864
  MemoryAllocator* allocator,
847
865
  const Cache::EvictionCallback* eviction_callback,
@@ -868,8 +886,7 @@ class AutoHyperClockTable : public BaseClockTable {
868
886
  // Runs the clock eviction algorithm trying to reclaim at least
869
887
  // requested_charge. Returns how much is evicted, which could be less
870
888
  // if it appears impossible to evict the requested amount without blocking.
871
- void Evict(size_t requested_charge, InsertState& state, EvictionData* data,
872
- uint32_t eviction_effort_cap);
889
+ void Evict(size_t requested_charge, InsertState& state, EvictionData* data);
873
890
 
874
891
  HandleImpl* Lookup(const UniqueId64x2& hashed_key);
875
892
 
@@ -1102,15 +1119,6 @@ class ALIGN_AS(CACHE_LINE_SIZE) ClockCacheShard final : public CacheShardBase {
1102
1119
 
1103
1120
  private: // data
1104
1121
  Table table_;
1105
-
1106
- // Maximum total charge of all elements stored in the table.
1107
- // (Relaxed: eventual consistency/update is OK)
1108
- RelaxedAtomic<size_t> capacity_;
1109
-
1110
- // Encodes eviction_effort_cap (bottom 31 bits) and strict_capacity_limit
1111
- // (top bit). See HyperClockCacheOptions::eviction_effort_cap etc.
1112
- // (Relaxed: eventual consistency/update is OK)
1113
- RelaxedAtomic<uint32_t> eec_and_scl_;
1114
1122
  }; // class ClockCacheShard
1115
1123
 
1116
1124
  template <class Table>