From a5a7d45355f8114d27d69ef137d31673a265ed8d Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 28 May 2013 14:16:49 +0100 Subject: [PATCH] flexnbd: Add more madvise() hints, both for mirroring out and normal operation. This is hopefully going to reduce flexnbd rss --- src/client.c | 6 ++++++ src/mirror.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/client.c b/src/client.c index 19a0ac9..5ca276c 100644 --- a/src/client.c +++ b/src/client.c @@ -551,6 +551,12 @@ void* client_serve(void* client_uncast) ), "Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno ) ); + + FATAL_IF_NEGATIVE( + madvise( client->mapped, client->serve->size, MADV_SEQUENTIAL ), + SHOW_ERRNO( "Failed to madvise() %s", client->serve->filename ) + ); + debug( "Opened client file fd %d", client->fileno); debug("client: sending hello"); client_send_hello(client); diff --git a/src/mirror.c b/src/mirror.c index 1a26811..d61ea57 100644 --- a/src/mirror.c +++ b/src/mirror.c @@ -89,6 +89,11 @@ void mirror_init( struct mirror * mirror, const char * filename ) filename ); + FATAL_IF_NEGATIVE( + madvise( mirror->mapped, size, MADV_SEQUENTIAL ), + SHOW_ERRNO( "Failed to madvise() %s", filename ) + ); + mirror->dirty_map = bitset_alloc(size, 4096); } @@ -193,8 +198,8 @@ int mirror_pass(struct server * serve, int is_last_pass, uint64_t *written) 0, serve->mirror->mapped + current, MS_REQUEST_LIMIT_SECS); - madvise( serve->mirror->mapped + current, - run, + madvise( serve->mirror->mapped + current, + run, MADV_DONTNEED ); /* now mark it clean */