24
24
#include " table/two_level_iterator.h"
25
25
#include " table/plain_table_factory.h"
26
26
27
+ #include " util/arena.h"
27
28
#include " util/coding.h"
28
29
#include " util/dynamic_bloom.h"
29
30
#include " util/hash.h"
@@ -95,7 +96,8 @@ PlainTableReader::PlainTableReader(
95
96
const Options& options, unique_ptr<RandomAccessFile>&& file,
96
97
const EnvOptions& storage_options, const InternalKeyComparator& icomparator,
97
98
uint64_t file_size, int bloom_bits_per_key, double hash_table_ratio,
98
- size_t index_sparseness, const TableProperties* table_properties)
99
+ size_t index_sparseness, const TableProperties* table_properties,
100
+ size_t huge_page_tlb_size)
99
101
: options_(options),
100
102
soptions_ (storage_options),
101
103
file_(std::move(file)),
@@ -106,19 +108,23 @@ PlainTableReader::PlainTableReader(
106
108
kIndexIntervalForSamePrefixKeys(index_sparseness),
107
109
table_properties_(nullptr ),
108
110
data_end_offset_(table_properties->data_size),
109
- user_key_len_(table_properties->fixed_key_len) {
111
+ user_key_len_(table_properties->fixed_key_len),
112
+ huge_page_tlb_size_(huge_page_tlb_size) {
110
113
assert (kHashTableRatio >= 0.0 );
111
114
}
112
115
113
116
PlainTableReader::~PlainTableReader () {
114
117
}
115
118
116
- Status PlainTableReader::Open (
117
- const Options& options, const EnvOptions& soptions,
118
- const InternalKeyComparator& internal_comparator,
119
- unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
120
- unique_ptr<TableReader>* table_reader, const int bloom_bits_per_key,
121
- double hash_table_ratio, size_t index_sparseness) {
119
+ Status PlainTableReader::Open (const Options& options,
120
+ const EnvOptions& soptions,
121
+ const InternalKeyComparator& internal_comparator,
122
+ unique_ptr<RandomAccessFile>&& file,
123
+ uint64_t file_size,
124
+ unique_ptr<TableReader>* table_reader,
125
+ const int bloom_bits_per_key,
126
+ double hash_table_ratio, size_t index_sparseness,
127
+ size_t huge_page_tlb_size) {
122
128
assert (options.allow_mmap_reads );
123
129
124
130
if (file_size > kMaxFileSize ) {
@@ -134,7 +140,8 @@ Status PlainTableReader::Open(
134
140
135
141
std::unique_ptr<PlainTableReader> new_reader (new PlainTableReader (
136
142
options, std::move (file), soptions, internal_comparator, file_size,
137
- bloom_bits_per_key, hash_table_ratio, index_sparseness, props));
143
+ bloom_bits_per_key, hash_table_ratio, index_sparseness, props,
144
+ huge_page_tlb_size));
138
145
139
146
// -- Populate Index
140
147
s = new_reader->PopulateIndex (props);
@@ -261,12 +268,11 @@ Status PlainTableReader::PopulateIndexRecordList(IndexRecordList* record_list,
261
268
}
262
269
263
270
void PlainTableReader::AllocateIndexAndBloom (int num_prefixes) {
264
- index_.reset ();
265
-
266
271
if (options_.prefix_extractor .get () != nullptr ) {
267
272
uint32_t bloom_total_bits = num_prefixes * kBloomBitsPerKey ;
268
273
if (bloom_total_bits > 0 ) {
269
- bloom_.reset (new DynamicBloom (bloom_total_bits, options_.bloom_locality ));
274
+ bloom_.reset (new DynamicBloom (bloom_total_bits, options_.bloom_locality ,
275
+ 6 , nullptr , huge_page_tlb_size_));
270
276
}
271
277
}
272
278
@@ -278,7 +284,6 @@ void PlainTableReader::AllocateIndexAndBloom(int num_prefixes) {
278
284
double hash_table_size_multipier = 1.0 / kHashTableRatio ;
279
285
index_size_ = num_prefixes * hash_table_size_multipier + 1 ;
280
286
}
281
- index_.reset (new uint32_t [index_size_]);
282
287
}
283
288
284
289
size_t PlainTableReader::BucketizeIndexesAndFillBloom (
@@ -322,7 +327,12 @@ void PlainTableReader::FillIndexes(
322
327
const std::vector<uint32_t >& entries_per_bucket) {
323
328
Log (options_.info_log , " Reserving %zu bytes for plain table's sub_index" ,
324
329
kSubIndexSize );
325
- sub_index_.reset (new char [kSubIndexSize ]);
330
+ auto total_allocate_size = sizeof (uint32_t ) * index_size_ + kSubIndexSize ;
331
+ char * allocated =
332
+ arena_.AllocateAligned (total_allocate_size, huge_page_tlb_size_);
333
+ index_ = reinterpret_cast <uint32_t *>(allocated);
334
+ sub_index_ = allocated + sizeof (uint32_t ) * index_size_;
335
+
326
336
size_t sub_index_offset = 0 ;
327
337
for (int i = 0 ; i < index_size_; i++) {
328
338
uint32_t num_keys_for_bucket = entries_per_bucket[i];
@@ -387,7 +397,8 @@ Status PlainTableReader::PopulateIndex(TableProperties* props) {
387
397
if (IsTotalOrderMode ()) {
388
398
uint32_t num_bloom_bits = table_properties_->num_entries * kBloomBitsPerKey ;
389
399
if (num_bloom_bits > 0 ) {
390
- bloom_.reset (new DynamicBloom (num_bloom_bits, options_.bloom_locality ));
400
+ bloom_.reset (new DynamicBloom (num_bloom_bits, options_.bloom_locality , 6 ,
401
+ nullptr , huge_page_tlb_size_));
391
402
}
392
403
}
393
404
0 commit comments