Commit 0b97764b authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

The first loader gets 1/2 of cachetable memory.

 * That's 2/3 of 3/4, which is calculated as 1/4 is unreservable.  The loader asks for 2/3 of what's reservable, getting one half.
The second loader gets 1/6 of cachetable memory.
 * That's 2/3 of 1/4: The loader asks for 2/3 of what's reservable.  1/2 has been reserved.  1/4 is unreservable.  1/4 is reservable.  2/3 of 1/4 is 1/6.
The third loader gets 1/18 of cachetable memory. 
 * That's 2/3 or 1/12.   (1/4 is unreservable. 1/2 was reserved by the first loader.  1/6 by the second.  That leaves 1/12)
Generally the next one gets 1/3 of what the previous one got.

Refs #2759. [t:2759]


git-svn-id: file:///svn/toku/tokudb@21564 c7de825b-a66e-492c-adef-691d508d4ae1
parent 53e33d98
...@@ -406,7 +406,7 @@ int toku_brt_loader_internal_init (/* out */ BRTLOADER *blp, ...@@ -406,7 +406,7 @@ int toku_brt_loader_internal_init (/* out */ BRTLOADER *blp,
bl->generate_row_for_put = g; bl->generate_row_for_put = g;
bl->cachetable = cachetable; bl->cachetable = cachetable;
if (bl->cachetable) if (bl->cachetable)
bl->reserved_memory = toku_cachetable_reserve_memory(bl->cachetable, 0.5); bl->reserved_memory = toku_cachetable_reserve_memory(bl->cachetable, 2.0/3.0); // allocate 2/3 of the unreserved part (which is 3/4 of the memory to start with).
else else
bl->reserved_memory = 512*1024*1024; // if no cache table use 512MB. bl->reserved_memory = 512*1024*1024; // if no cache table use 512MB.
//printf("Reserved memory=%ld\n", bl->reserved_memory); //printf("Reserved memory=%ld\n", bl->reserved_memory);
......
...@@ -277,6 +277,9 @@ u_int32_t toku_get_checkpoint_period (CACHETABLE ct) { ...@@ -277,6 +277,9 @@ u_int32_t toku_get_checkpoint_period (CACHETABLE ct) {
return toku_minicron_get_period(&ct->checkpointer); return toku_minicron_get_period(&ct->checkpointer);
} }
// reserve 25% as "unreservable". The loader cannot have it.
#define unreservable_memory(size) ((size)/4)
int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_lsn), TOKULOGGER logger) { int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_lsn), TOKULOGGER logger) {
TAGMALLOC(CACHETABLE, ct); TAGMALLOC(CACHETABLE, ct);
if (ct == 0) return ENOMEM; if (ct == 0) return ENOMEM;
...@@ -285,7 +288,7 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l ...@@ -285,7 +288,7 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l
rwlock_init(&ct->pending_lock); rwlock_init(&ct->pending_lock);
XCALLOC_N(ct->table_size, ct->table); XCALLOC_N(ct->table_size, ct->table);
ct->size_limit = size_limit; ct->size_limit = size_limit;
ct->size_reserved = 0; ct->size_reserved = unreservable_memory(size_limit);
ct->logger = logger; ct->logger = logger;
toku_init_workers(&ct->wq, &ct->threadpool); toku_init_workers(&ct->wq, &ct->threadpool);
ct->mutex = workqueue_lock_ref(&ct->wq); ct->mutex = workqueue_lock_ref(&ct->wq);
...@@ -299,7 +302,7 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l ...@@ -299,7 +302,7 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l
return 0; return 0;
} }
uint64_t toku_cachetable_reserve_memory(CACHETABLE ct, double fraction) { u_int64_t toku_cachetable_reserve_memory(CACHETABLE ct, double fraction) {
cachetable_lock(ct); cachetable_lock(ct);
cachetable_wait_write(ct); cachetable_wait_write(ct);
uint64_t reserved_memory = fraction*(ct->size_limit-ct->size_reserved); uint64_t reserved_memory = fraction*(ct->size_limit-ct->size_reserved);
...@@ -320,7 +323,7 @@ void toku_cachetable_release_reserved_memory(CACHETABLE ct, uint64_t reserved_me ...@@ -320,7 +323,7 @@ void toku_cachetable_release_reserved_memory(CACHETABLE ct, uint64_t reserved_me
cachetable_lock(ct); cachetable_lock(ct);
ct->size_current -= reserved_memory; ct->size_current -= reserved_memory;
ct->size_reserved -= reserved_memory; ct->size_reserved -= reserved_memory;
assert(ct->size_current >= 0); assert(ct->size_current >= unreservable_memory(ct->size_limit));
cachetable_unlock(ct); cachetable_unlock(ct);
} }
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
/* Test for #2755. The brtloader is using too much VM. */ /* Test for #2755. The brtloader is using too much VM. */
static void test_cachetable_reservation (void) { static void test_cachetable_reservation (long size) {
CACHETABLE ct; CACHETABLE ct;
long size = 1L<<28;
{ {
int r = toku_create_cachetable(&ct, size, ZERO_LSN, NULL); int r = toku_create_cachetable(&ct, size, ZERO_LSN, NULL);
assert(r==0); assert(r==0);
...@@ -21,11 +20,17 @@ static void test_cachetable_reservation (void) { ...@@ -21,11 +20,17 @@ static void test_cachetable_reservation (void) {
uint64_t r1_bound = r0_bound/2; uint64_t r1_bound = r0_bound/2;
uint64_t r2 = toku_cachetable_reserve_memory(ct, 0.5); uint64_t r2 = toku_cachetable_reserve_memory(ct, 0.5);
uint64_t r2_bound = r1_bound/2; uint64_t r2_bound = r1_bound/2;
assert(r0 < r0_bound); printf("%ld: r0=%ld r1=%ld r2=%ld\n", size, r0, r1, r2);
assert(r1 < r1_bound); assert(r0 <= r0_bound);
assert(r2 < r2_bound); assert(r1 <= r1_bound);
assert(r1 < r0); assert(r2 <= r2_bound);
assert(r2 < r1); assert(r1 <= r0);
assert(r2 <= r1);
long unreservable_part = size * 0.25;
assert(r0 <= (size - unreservable_part)*0.5);
assert(r1 <= (size - unreservable_part - r0)*0.5);
assert(r2 <= (size - unreservable_part - r0 -1)*0.5);
} }
{ {
int r = toku_cachetable_close(&ct); int r = toku_cachetable_close(&ct);
...@@ -35,6 +40,9 @@ static void test_cachetable_reservation (void) { ...@@ -35,6 +40,9 @@ static void test_cachetable_reservation (void) {
} }
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) { int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
test_cachetable_reservation(); test_cachetable_reservation(1L<<28);
test_cachetable_reservation(1LL<<33);
test_cachetable_reservation(3L<<28);
test_cachetable_reservation((3L<<28) - 107);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment