Skip to content

Commit f94e36a

Browse files
committed
FT-309 Default padded fit alignment should be 4096
1 parent bade886 commit f94e36a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ft/serialize/block_allocator_strategy.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ PATENT RIGHTS GRANT:
8888

8989
#include <algorithm>
9090

91+
#include <string.h>
92+
9193
#include "portability/toku_assert.h"
9294

9395
#include "ft/serialize/block_allocator_strategy.h"
@@ -96,7 +98,7 @@ static uint64_t _align(uint64_t value, uint64_t ba_alignment) {
9698
return ((value + ba_alignment - 1) / ba_alignment) * ba_alignment;
9799
}
98100

99-
static uint64_t _next_power_of_two(uint64_t value) {
101+
static uint64_t _roundup_to_power_of_two(uint64_t value) {
100102
uint64_t r = 4096;
101103
while (r < value) {
102104
r *= 2;
@@ -158,23 +160,24 @@ block_allocator_strategy::best_fit(struct block_allocator::blockpair *blocks_arr
158160
return best_bp;
159161
}
160162

161-
static uint64_t padded_fit_alignment = 64 * 1024;
163+
static uint64_t padded_fit_alignment = 4096;
162164

163165
// TODO: These compiler specific directives should be abstracted in a portability header
164166
// portability/toku_compiler.h?
165167
__attribute__((__constructor__))
166168
static void determine_padded_fit_alignment_from_env(void) {
167169
// TODO: Should be in portability as 'toku_os_getenv()?'
168170
const char *s = getenv("TOKU_BA_PADDED_FIT_ALIGNMENT");
169-
if (s != nullptr) {
171+
if (s != nullptr && strlen(s) > 0) {
170172
const int64_t alignment = strtoll(s, nullptr, 10);
171-
if (alignment < 0) {
173+
if (alignment <= 0) {
172174
fprintf(stderr, "tokuft: error: block allocator padded fit alignment found in environment (%s), "
173-
"but it's out of range (should be an integer > 0). defaulting to 10\n", s);
174-
padded_fit_alignment = 64 * 1024;
175+
"but it's out of range (should be an integer > 0). defaulting to %" PRIu64 "\n",
176+
s, padded_fit_alignment);
175177
} else {
176-
padded_fit_alignment = _next_power_of_two(alignment);
177-
fprintf(stderr, "tokuft: setting block allocator padded fit alignment to %" PRIu64 "\n", padded_fit_alignment);
178+
padded_fit_alignment = _roundup_to_power_of_two(alignment);
179+
fprintf(stderr, "tokuft: setting block allocator padded fit alignment to %" PRIu64 "\n",
180+
padded_fit_alignment);
178181
}
179182
}
180183
}
@@ -196,7 +199,7 @@ __attribute__((__constructor__))
196199
static void determine_hot_zone_threshold_from_env(void) {
197200
// TODO: Should be in portability as 'toku_os_getenv()?'
198201
const char *s = getenv("TOKU_BA_HOT_ZONE_THRESHOLD");
199-
if (s != nullptr) {
202+
if (s != nullptr && strlen(s) > 0) {
200203
const double hot_zone = strtod(s, nullptr);
201204
if (hot_zone < 1 || hot_zone > 99) {
202205
fprintf(stderr, "tokuft: error: block allocator hot zone threshold found in environment (%s), "

0 commit comments

Comments
 (0)