linux: Flush page/buffer cache before querying available memory
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 21 Jul 2014 15:15:24 +0000 (16:15 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 21 Jul 2014 15:32:42 +0000 (16:32 +0100)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
lib/intel_os.c

index 2a29cc0..0d4f43d 100644 (file)
@@ -98,7 +98,14 @@ intel_get_avail_ram_mb(void)
 
 #ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
        struct sysinfo sysinf;
-       int ret;
+       int fd, ret;
+
+       fd = open("/proc/sys/vm/drop_caches", O_RDWR);
+       if (fd != -1) {
+               ret = write(fd, "3", 2);
+               close(fd);
+               (void)ret;
+       }
 
        ret = sysinfo(&sysinf);
        assert(ret == 0);