From 1dbcfdd00ae69ecdb16256de816c4030646223dc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 29 Oct 2020 17:23:03 +0100 Subject: [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. --- src/server/image.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-55-g7522