From 43cc60130cbf419d5bbf0c26e74da573fda94aab Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 5 Jul 2018 13:23:24 +0200 Subject: [SERVER] Don't keep bg replication blocks in fs cache Further improving cache handling, don't keep blocks in cache that have been requested via background replication. It's likely these aren't needed in the near future. --- src/server/uplink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index 26e5d4e..2bd6ed2 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -555,7 +555,7 @@ static void uplink_sendRequests(dnbd3_connection_t *link, bool newOnly) */ static void uplink_sendReplicationRequest(dnbd3_connection_t *link) { - if ( !_backgroundReplication ) return; // Don't do background replication + if ( !_backgroundReplication || link->cacheFd == -1 ) return; // Don't do background replication if ( link == NULL || link->fd == -1 ) return; dnbd3_image_t * const image = link->image; if ( image->realFilesize < DNBD3_BLOCK_SIZE ) return; @@ -738,6 +738,10 @@ static void uplink_handleReceive(dnbd3_connection_t *link) if ( start == link->replicationHandle ) { // Was our background replication link->replicationHandle = 0; + // Try to remove from fs cache if no client was interested in this data + if ( !served && link->cacheFd != -1 ) { + posix_fadvise( link->cacheFd, start, inReply.size, POSIX_FADV_DONTNEED ); + } } else { // Was some client -- reset idle counter link->idleCount = 0; -- cgit v1.2.3-55-g7522