mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
Reserve memory. Refs #2613. [t:2613].
git-svn-id: file:///svn/toku/tokudb@20241 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
eaa5564cbd
commit
c20a422a93
4 changed files with 36 additions and 1 deletions
|
@ -136,6 +136,8 @@ struct brtloader_s {
|
|||
const char *temp_file_template;
|
||||
|
||||
CACHETABLE cachetable;
|
||||
uint64_t reserved_memory; // how much memory are we allowed to use?
|
||||
|
||||
/* To make it easier to recover from errors, we don't use FILE*, instead we use an index into the file_infos. */
|
||||
struct file_infos file_infos;
|
||||
|
||||
|
|
|
@ -267,8 +267,11 @@ static void brtloader_destroy (BRTLOADER bl, BOOL is_error) {
|
|||
toku_free(bl->fractal_queues);
|
||||
toku_free(bl->fractal_threads_live);
|
||||
|
||||
toku_cachetable_release_reserved_memory(bl->cachetable, bl->reserved_memory);
|
||||
|
||||
brt_loader_destroy_error_callback(&bl->error_callback);
|
||||
brt_loader_destroy_poll_callback(&bl->poll_callback);
|
||||
|
||||
toku_free(bl);
|
||||
}
|
||||
|
||||
|
@ -311,6 +314,7 @@ int toku_brt_loader_open (/* out */ BRTLOADER *blp,
|
|||
|
||||
bl->generate_row_for_put = g;
|
||||
bl->cachetable = cachetable;
|
||||
bl->reserved_memory = toku_cachetable_reserve_memory(cachetable, 0.5);
|
||||
|
||||
bl->src_db = src_db;
|
||||
bl->N = N;
|
||||
|
|
|
@ -119,6 +119,7 @@ struct ctpair {
|
|||
static void * const zero_value = 0;
|
||||
static int const zero_size = 0;
|
||||
|
||||
static int maybe_flush_some (CACHETABLE ct, long size);
|
||||
|
||||
static inline void
|
||||
ctpair_add_ref(PAIR p) {
|
||||
|
@ -296,6 +297,29 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint64_t toku_cachetable_reserve_memory(CACHETABLE ct, double fraction) {
|
||||
cachetable_lock(ct);
|
||||
cachetable_wait_write(ct);
|
||||
uint64_t reserved_memory = fraction*ct->size_limit;
|
||||
{
|
||||
int r = maybe_flush_some(ct, reserved_memory);
|
||||
if (r) {
|
||||
cachetable_unlock(ct);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
ct->size_current += reserved_memory;
|
||||
cachetable_unlock(ct);
|
||||
return reserved_memory;
|
||||
}
|
||||
|
||||
void toku_cachetable_release_reserved_memory(CACHETABLE ct, uint64_t reserved_memory) {
|
||||
cachetable_lock(ct);
|
||||
ct->size_current -= reserved_memory;
|
||||
assert(ct->size_current >= 0);
|
||||
cachetable_unlock(ct);
|
||||
}
|
||||
|
||||
void
|
||||
toku_cachetable_set_env_dir(CACHETABLE ct, char *env_dir) {
|
||||
assert(!ct->set_env_dir);
|
||||
|
|
|
@ -82,7 +82,6 @@ int toku_cachetable_openf (CACHEFILE *,CACHETABLE, const char */*fname_in_env*/,
|
|||
// Returns the limit on the cachetable size
|
||||
uint64_t toku_cachetable_get_size_limit(CACHETABLE ct);
|
||||
|
||||
|
||||
// Bind a file to a new cachefile object.
|
||||
int toku_cachetable_openfd (CACHEFILE *,CACHETABLE, int /*fd*/,
|
||||
const char *fname_relative_to_env); /*(used for logging)*/
|
||||
|
@ -97,6 +96,12 @@ int toku_cachetable_reserve_filenum (CACHETABLE ct, FILENUM *reserved_filenum, B
|
|||
|
||||
void toku_cachetable_unreserve_filenum (CACHETABLE ct, FILENUM reserved_filenum);
|
||||
|
||||
// Effect: Reserve a fraction of the cachetable memory.
|
||||
// Returns the amount reserved.
|
||||
// To return the memory to the cachetable, call toku_cachetable_release_reserved_memory
|
||||
// Requires 0<fraction<1.
|
||||
uint64_t toku_cachetable_reserve_memory(CACHETABLE, double fraction);
|
||||
void toku_cachetable_release_reserved_memory(CACHETABLE, uint64_t);
|
||||
|
||||
// Get access to the asynchronous work queue
|
||||
// Returns: a pointer to the work queue
|
||||
|
|
Loading…
Add table
Reference in a new issue