From 61370c601393d7327a64ae1e02d2468e56efd419 Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Mon, 30 Jun 2014 11:16:40 +0200 Subject: [PATCH] * msync is NOT necessary before munmap, the data gets synced automatically * remove WILLNEED madvise, this only slows the code down while the os des not seem todo anything sensible with the info --- configure.ac | 2 +- src/rrd_open.c | 31 ++----------------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/configure.ac b/configure.ac index 121ffa9e..ed5cda44 100644 --- a/configure.ac +++ b/configure.ac @@ -263,7 +263,7 @@ if test "x$enable_mmap" = "xyes"; then *) AC_CHECK_HEADERS(sys/mman.h) AC_FUNC_MMAP - AC_CHECK_FUNCS(mmap munmap msync) + AC_CHECK_FUNCS(mmap munmap) AC_CHECK_DECLS(madvise, [], [], [#ifdef HAVE_SYS_MMAN_H # include #endif]) diff --git a/src/rrd_open.c b/src/rrd_open.c index 5ba35fb0..63e56224 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -102,7 +102,6 @@ rrd_file_t *rrd_open( int version; #ifdef HAVE_MMAP - ssize_t _page_size = sysconf(_SC_PAGESIZE); char *data = MAP_FAILED; #endif off_t offset = 0; @@ -200,8 +199,8 @@ rrd_file_t *rrd_open( #ifdef HAVE_MMAP #ifdef HAVE_BROKEN_MS_ASYNC if (rdwr & RRD_READWRITE) { - /* some unices, the files mtime does not get update - on msync MS_ASYNC, in order to help them, + /* some unices, the files mtime does not get updated + on memory mapped files, in order to help them, we update the the timestamp at this point. The thing happens pretty 'close' to the open call so the chances of a race should be minimal. @@ -309,14 +308,10 @@ rrd_file_t *rrd_open( #ifdef USE_MADVISE if (rdwr & RRD_COPY) { /* We will read everything in a moment (copying) */ - madvise(data, rrd_file->file_len, MADV_WILLNEED ); madvise(data, rrd_file->file_len, MADV_SEQUENTIAL ); } else { /* We do not need to read anything in for the moment */ madvise(data, rrd_file->file_len, MADV_RANDOM); - /* the stat_head will be needed soonish, so hint accordingly */ - madvise(data, sizeof(stat_head_t), MADV_WILLNEED); - madvise(data, sizeof(stat_head_t), MADV_RANDOM); } #endif @@ -341,19 +336,9 @@ rrd_file_t *rrd_open( rrd->stat_head->version); goto out_nullify_head; } -#if defined USE_MADVISE - /* the ds_def will be needed soonish, so hint accordingly */ - madvise(data + PAGE_START(offset), - sizeof(ds_def_t) * rrd->stat_head->ds_cnt, MADV_WILLNEED); -#endif __rrd_read(rrd->ds_def, ds_def_t, rrd->stat_head->ds_cnt); -#if defined USE_MADVISE - /* the rra_def will be needed soonish, so hint accordingly */ - madvise(data + PAGE_START(offset), - sizeof(rra_def_t) * rrd->stat_head->rra_cnt, MADV_WILLNEED); -#endif __rrd_read(rrd->rra_def, rra_def_t, rrd->stat_head->rra_cnt); @@ -364,21 +349,12 @@ rrd_file_t *rrd_open( rrd_set_error("live_head_t malloc"); goto out_close; } -#if defined USE_MADVISE - /* the live_head will be needed soonish, so hint accordingly */ - madvise(data + PAGE_START(offset), sizeof(time_t), MADV_WILLNEED); -#endif __rrd_read(rrd->legacy_last_up, time_t, 1); rrd->live_head->last_up = *rrd->legacy_last_up; rrd->live_head->last_up_usec = 0; } else { -#if defined USE_MADVISE - /* the live_head will be needed soonish, so hint accordingly */ - madvise(data + PAGE_START(offset), - sizeof(live_head_t), MADV_WILLNEED); -#endif __rrd_read(rrd->live_head, live_head_t, 1); } @@ -617,9 +593,6 @@ int rrd_close( int ret; #ifdef HAVE_MMAP - ret = msync(rrd_simple_file->file_start, rrd_file->file_len, MS_ASYNC); - if (ret != 0) - rrd_set_error("msync rrd_file: %s", rrd_strerror(errno)); ret = munmap(rrd_simple_file->file_start, rrd_file->file_len); if (ret != 0) rrd_set_error("munmap rrd_file: %s", rrd_strerror(errno)); -- 2.47.2