Commit 5500a399 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

merge 3.0.5 -c 18481 to main refs[t:2467]

git-svn-id: file:///svn/toku/tokudb@18871 c7de825b-a66e-492c-adef-691d508d4ae1
parent e97dc367
...@@ -166,19 +166,33 @@ toku_os_write (int fd, const void *buf, size_t len) { ...@@ -166,19 +166,33 @@ toku_os_write (int fd, const void *buf, size_t len) {
return 0; return 0;
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// fsync logic:
// t_fsync exists for testing purposes only // t_fsync exists for testing purposes only
static int (*t_fsync)(int) = 0; static int (*t_fsync)(int) = 0;
static uint64_t toku_fsync_count; static uint64_t toku_fsync_count;
static uint64_t toku_fsync_time; static uint64_t toku_fsync_time;
static uint64_t sched_fsync_count;
static uint64_t sched_fsync_time;
int int
toku_set_func_fsync(int (*fsync_function)(int)) { toku_set_func_fsync(int (*fsync_function)(int)) {
t_fsync = fsync_function; t_fsync = fsync_function;
return 0; return 0;
} }
int static uint64_t get_tnow(void) {
toku_file_fsync_without_accounting (int fd) { struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
// keep trying if fsync fails because of EINTR
static int
file_fsync_internal (int fd, uint64_t *duration_p) {
uint64_t tstart = get_tnow();
int r = -1; int r = -1;
while (r != 0) { while (r != 0) {
if (t_fsync) if (t_fsync)
...@@ -191,6 +205,17 @@ toku_file_fsync_without_accounting (int fd) { ...@@ -191,6 +205,17 @@ toku_file_fsync_without_accounting (int fd) {
assert(rr==EINTR); assert(rr==EINTR);
} }
} }
toku_sync_fetch_and_increment_uint64(&toku_fsync_count);
uint64_t duration;
duration = get_tnow() - tstart;
toku_sync_fetch_and_add_uint64(&toku_fsync_time, duration);
if (duration_p) *duration_p = duration;
return r;
}
int
toku_file_fsync_without_accounting (int fd) {
int r = file_fsync_internal (fd, NULL);
return r; return r;
} }
...@@ -198,34 +223,34 @@ int ...@@ -198,34 +223,34 @@ int
toku_fsync_dirfd_without_accounting(DIR *dirp) { toku_fsync_dirfd_without_accounting(DIR *dirp) {
int r; int r;
int fd = dirfd(dirp); int fd = dirfd(dirp);
if (fd<0) { if (fd < 0) {
r = -1; r = -1;
} } else {
else {
r = toku_file_fsync_without_accounting(fd); r = toku_file_fsync_without_accounting(fd);
} }
return r; return r;
} }
static uint64_t get_tnow(void) { // include fsync in scheduling accounting
struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
// keep trying if fsync fails because of EINTR
int int
toku_file_fsync(int fd) { toku_file_fsync(int fd) {
uint64_t tstart = get_tnow(); uint64_t duration;
int r = toku_file_fsync_without_accounting(fd); int r = file_fsync_internal (fd, &duration);
toku_sync_fetch_and_increment_uint64(&toku_fsync_count); toku_sync_fetch_and_increment_uint64(&sched_fsync_count);
toku_sync_fetch_and_add_uint64(&toku_fsync_time, get_tnow() - tstart); toku_sync_fetch_and_add_uint64(&sched_fsync_time, duration);
return r; return r;
} }
// for real accounting
void void
toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time) { toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time) {
*fsync_count = toku_fsync_count; *fsync_count = toku_fsync_count;
*fsync_time = toku_fsync_time; *fsync_time = toku_fsync_time;
} }
// for scheduling algorithm only
void
toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time) {
*fsync_count = sched_fsync_count;
*fsync_time = sched_fsync_time;
}
...@@ -182,7 +182,7 @@ toku_ydb_lock(void) { ...@@ -182,7 +182,7 @@ toku_ydb_lock(void) {
} }
status.max_requested_sleep = u64max(status.max_requested_sleep, requested_sleep); status.max_requested_sleep = u64max(status.max_requested_sleep, requested_sleep);
toku_cachetable_get_miss_times(NULL, &ydb_big_lock.start_miss_count, &ydb_big_lock.start_miss_time); toku_cachetable_get_miss_times(NULL, &ydb_big_lock.start_miss_count, &ydb_big_lock.start_miss_time);
toku_get_fsync_times(&ydb_big_lock.start_fsync_count, &ydb_big_lock.start_fsync_time); toku_get_fsync_sched(&ydb_big_lock.start_fsync_count, &ydb_big_lock.start_fsync_time);
if (new_ydbtime) if (new_ydbtime)
toku_list_push(&ydb_big_lock.all_ydbtimes, &ydbtime->all_ydbtimes); toku_list_push(&ydb_big_lock.all_ydbtimes, &ydbtime->all_ydbtimes);
#endif #endif
...@@ -215,7 +215,7 @@ toku_ydb_unlock(void) { ...@@ -215,7 +215,7 @@ toku_ydb_unlock(void) {
disk_count = disk_count - ydb_big_lock.start_miss_count; // number of cache misses disk_count = disk_count - ydb_big_lock.start_miss_count; // number of cache misses
disk_time = disk_time - ydb_big_lock.start_miss_time; // usec spent waiting for disk reads disk_time = disk_time - ydb_big_lock.start_miss_time; // usec spent waiting for disk reads
uint64_t fsync_count, fsync_time; uint64_t fsync_count, fsync_time;
toku_get_fsync_times(&fsync_count, &fsync_time); // number of fsync operations toku_get_fsync_sched(&fsync_count, &fsync_time); // number of fsync operations
disk_count += fsync_count - ydb_big_lock.start_fsync_count; // time waiting for fsyncs to complete disk_count += fsync_count - ydb_big_lock.start_fsync_count; // time waiting for fsyncs to complete
disk_time += fsync_time - ydb_big_lock.start_fsync_time; disk_time += fsync_time - ydb_big_lock.start_fsync_time;
if (disk_count == 0) { if (disk_count == 0) {
......
...@@ -142,9 +142,12 @@ int toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibil ...@@ -142,9 +142,12 @@ int toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibil
int toku_file_fsync_without_accounting(int fd); int toku_file_fsync_without_accounting(int fd);
int toku_file_fsync(int fd); int toku_file_fsync(int fd);
// get the number of fsync calls and the fsync times // get the number of fsync calls and the fsync times (total)
void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time); void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time);
// get the number of fsync calls and the fsync times for use by scheduler (subset of total)
void toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time);
// set a new fsync function (for debugging) // set a new fsync function (for debugging)
int toku_set_func_fsync (int (*fsync_function)(int)); int toku_set_func_fsync (int (*fsync_function)(int));
......
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