summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-10-29 17:23:03 +0100
committerSimon Rettberg2020-10-29 17:23:03 +0100
commit1dbcfdd00ae69ecdb16256de816c4030646223dc (patch)
tree9a6878b39afc2ea7fbc31e511b499e02c11c14f4
parent[BUILD] do not print verbose CMake messages in unsupported CMake versions (diff)
downloaddnbd3-1dbcfdd00ae69ecdb16256de816c4030646223dc.tar.gz
dnbd3-1dbcfdd00ae69ecdb16256de816c4030646223dc.tar.xz
dnbd3-1dbcfdd00ae69ecdb16256de816c4030646223dc.zip
[SERVER] Update nextSave timestamp at start of function
saveLoadAllCacheMaps() is called frequently, and a 'full' run can take some time. If we only update the nextSave timestamp when we're done, we might already have a concurrent call to the function, which will also do a 'full' run, since the timestamp is not updated yet. This doesn't break anything, but leads to even more disk activity, which is probably already high, given that the previous run is not done yet.
-rw-r--r--src/server/image.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/server/image.c b/src/server/image.c
index de6217f..96f27d4 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -1879,8 +1879,13 @@ static void* saveLoadAllCacheMaps(void* nix UNUSED)
static ticks nextSave;
declare_now;
bool full = timing_reached( &nextSave, &now );
- time_t walltime = full ? time( NULL ) : 0;
+ time_t walltime = 0;
setThreadName( "cache-mapper" );
+ if ( full ) {
+ walltime = time( NULL );
+ // Update at start to avoid concurrent runs
+ timing_addSeconds( &nextSave, &now, CACHE_MAP_MAX_SAVE_DELAY );
+ }
mutex_lock( &imageListLock );
for ( int i = 0; i < _num_images; ++i ) {
dnbd3_image_t * const image = _images[i];
@@ -1950,9 +1955,6 @@ static void* saveLoadAllCacheMaps(void* nix UNUSED)
mutex_lock( &imageListLock );
}
mutex_unlock( &imageListLock );
- if ( full ) {
- timing_addSeconds( &nextSave, &now, CACHE_MAP_MAX_SAVE_DELAY );
- }
return NULL;
}