Commit 009e2316 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

refs #5802, merge probabilistic PAIR clock decrementing from tokudb.fb to main.

git-svn-id: file:///svn/toku/tokudb@51187 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3b853c9a
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "background_job_manager.h" #include "background_job_manager.h"
#include <portability/toku_random.h>
#include <util/frwlock.h> #include <util/frwlock.h>
#include <util/kibbutz.h> #include <util/kibbutz.h>
#include <util/nb_mutex.h> #include <util/nb_mutex.h>
...@@ -420,6 +421,10 @@ private: ...@@ -420,6 +421,10 @@ private:
int64_t m_high_size_watermark; // if cachetable grows to this size, client threads sleep upon adding data int64_t m_high_size_watermark; // if cachetable grows to this size, client threads sleep upon adding data
int64_t m_high_size_hysteresis; // if > cachetable size, then sleeping client threads may wake up int64_t m_high_size_hysteresis; // if > cachetable size, then sleeping client threads may wake up
// used to calculate random numbers
struct random_data m_random_data;
char m_random_statebuf[64];
// mutex that protects fields listed immedietly below // mutex that protects fields listed immedietly below
toku_mutex_t m_ev_thread_lock; toku_mutex_t m_ev_thread_lock;
// the eviction thread // the eviction thread
......
...@@ -3484,10 +3484,14 @@ void evictor::init(long _size_limit, pair_list* _pl, KIBBUTZ _kibbutz, uint32_t ...@@ -3484,10 +3484,14 @@ void evictor::init(long _size_limit, pair_list* _pl, KIBBUTZ _kibbutz, uint32_t
m_ev_thread_is_running = false; m_ev_thread_is_running = false;
m_period_in_seconds = eviction_period; m_period_in_seconds = eviction_period;
unsigned int seed = (unsigned int) time(NULL);
int r = myinitstate_r(seed, m_random_statebuf, sizeof m_random_statebuf, &m_random_data);
assert_zero(r);
// start the background thread // start the background thread
m_run_thread = true; m_run_thread = true;
m_num_eviction_thread_runs = 0; m_num_eviction_thread_runs = 0;
int r = toku_pthread_create(&m_ev_thread, NULL, eviction_thread, this); r = toku_pthread_create(&m_ev_thread, NULL, eviction_thread, this);
assert_zero(r); assert_zero(r);
} }
...@@ -3727,6 +3731,7 @@ exit: ...@@ -3727,6 +3731,7 @@ exit:
// on exit, the same conditions must apply // on exit, the same conditions must apply
// //
bool evictor::run_eviction_on_pair(PAIR curr_in_clock) { bool evictor::run_eviction_on_pair(PAIR curr_in_clock) {
double avg_pair_size;
bool ret_val = false; bool ret_val = false;
// function meant to be called on PAIR that is not being accessed right now // function meant to be called on PAIR that is not being accessed right now
CACHEFILE cf = curr_in_clock->cachefile; CACHEFILE cf = curr_in_clock->cachefile;
...@@ -3742,16 +3747,25 @@ bool evictor::run_eviction_on_pair(PAIR curr_in_clock) { ...@@ -3742,16 +3747,25 @@ bool evictor::run_eviction_on_pair(PAIR curr_in_clock) {
bjm_remove_background_job(cf->bjm); bjm_remove_background_job(cf->bjm);
goto exit; goto exit;
} }
avg_pair_size = m_size_current / m_pl->m_n_in_table;
// now that we have the pair mutex we care about, we can // now that we have the pair mutex we care about, we can
// release the read list lock and reacquire it at the end of the function // release the read list lock and reacquire it at the end of the function
m_pl->read_list_unlock(); m_pl->read_list_unlock();
ret_val = true; ret_val = true;
if (curr_in_clock->count > 0) { if (curr_in_clock->count > 0) {
curr_in_clock->count--; if (curr_in_clock->attr.size >= avg_pair_size) {
curr_in_clock->count--;
} else {
int32_t rnd = myrandom_r(&m_random_data);
double prob = curr_in_clock->attr.size / avg_pair_size;
if ((prob * 10000) < (rnd % 10000)) {
curr_in_clock->count--;
}
}
// call the partial eviction callback // call the partial eviction callback
curr_in_clock->value_rwlock.write_lock(true); curr_in_clock->value_rwlock.write_lock(true);
void *value = curr_in_clock->value_data; void *value = curr_in_clock->value_data;
void* disk_data = curr_in_clock->disk_data; void* disk_data = curr_in_clock->disk_data;
void *write_extraargs = curr_in_clock->write_extraargs; void *write_extraargs = curr_in_clock->write_extraargs;
......
...@@ -35,7 +35,7 @@ myrandom_r(struct random_data *buf) ...@@ -35,7 +35,7 @@ myrandom_r(struct random_data *buf)
struct random_data { struct random_data {
unsigned short xsubi[3]; unsigned short xsubi[3];
}; };
static int static inline int
myinitstate_r(unsigned int seed, char *UU(statebuf), size_t UU(statelen), struct random_data *buf) myinitstate_r(unsigned int seed, char *UU(statebuf), size_t UU(statelen), struct random_data *buf)
{ {
buf->xsubi[0] = (seed & 0xffff0000) >> 16; buf->xsubi[0] = (seed & 0xffff0000) >> 16;
......
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