diff src/lib/file-cache.c @ 2868:316756b50150 HEAD

Use madvise(MADV_DONTNEED) for invalidated pages to free memory.
author Timo Sirainen <tss@iki.fi>
date Mon, 08 Nov 2004 03:02:52 +0200
parents bf1e718e7370
children d1780331ad04
line wrap: on
line diff
--- a/src/lib/file-cache.c	Mon Nov 08 02:55:02 2004 +0200
+++ b/src/lib/file-cache.c	Mon Nov 08 03:02:52 2004 +0200
@@ -171,6 +171,15 @@
 	offset /= page_size;
 	size -= offset;
 
+	if (size != 1) {
+		/* tell operating system that we don't need the memory anymore
+		   and it may free it. don't bother to do it for single pages,
+		   there's a good chance that they get re-read back
+		   immediately. */
+		(void)madvise(PTR_OFFSET(cache->mmap_base, offset * page_size),
+			      size * page_size, MADV_DONTNEED);
+	}
+
 	bits = buffer_get_space_unsafe(cache->page_bitmask, offset / CHAR_BIT,
 				       (size + CHAR_BIT - 1) / CHAR_BIT);