All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib: Report file cache as available system memory
@ 2018-06-21 14:19 ` Chris Wilson
  0 siblings, 0 replies; 8+ messages in thread
From: Chris Wilson @ 2018-06-21 14:19 UTC (permalink / raw)
  To: igt-dev; +Cc: intel-gfx

sysinfo() doesn't include all reclaimable memory. In particular it
excludes the majority of global_node_page_state(NR_FILE_PAGES),
reclaimable pages that are a copy of on-disk files It seems the only way
to obtain this counter is by parsing /proc/meminfo. For comparison,
check vm_enough_memory() which includes NR_FILE_PAGES as available
(sadly there's no way to call vm_enough_memory() directly either!)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/intel_os.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/lib/intel_os.c b/lib/intel_os.c
index 885ffdcec..a44f153d3 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -96,17 +96,41 @@ intel_get_avail_ram_mb(void)
 	uint64_t retval;
 
 #ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
-	struct sysinfo sysinf;
+	char *info;
 	int fd;
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	intel_purge_vm_caches(fd);
 	close(fd);
 
-	igt_assert(sysinfo(&sysinf) == 0);
-	retval = sysinf.freeram;
-	retval += min(sysinf.freeswap, sysinf.bufferram);
-	retval *= sysinf.mem_unit;
+	fd = open("/proc", O_RDONLY);
+	info = igt_sysfs_get(fd, "meminfo");
+	close(fd);
+
+	if (info) {
+		long val;
+
+		sscanf("MemAvailable: %lu", &val);
+		retval = val << 10;
+
+		sscanf("Buffers: %lu", &val);
+		retval += val << 10;
+
+		sscanf("Cached: %lu", &val);
+		retval += val << 10;
+
+		sscanf("SwapCached: %lu", &val);
+		retval += val << 10;
+
+		free(info);
+	} else {
+		struct sysinfo sysinf;
+
+		igt_assert(sysinfo(&sysinf) == 0);
+		retval = sysinf.freeram;
+		retval += min(sysinf.freeswap, sysinf.bufferram);
+		retval *= sysinf.mem_unit;
+	}
 #elif defined(_SC_PAGESIZE) && defined(_SC_AVPHYS_PAGES) /* Solaris */
 	long pagesize, npages;
 
-- 
2.18.0.rc2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-06-21 21:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-21 14:19 [PATCH i-g-t] lib: Report file cache as available system memory Chris Wilson
2018-06-21 14:19 ` [igt-dev] " Chris Wilson
2018-06-21 14:43 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-06-21 15:01 ` [PATCH i-g-t] " Chris Wilson
2018-06-21 15:01   ` [igt-dev] " Chris Wilson
2018-06-21 15:23 ` [igt-dev] ✓ Fi.CI.BAT: success for lib: Report file cache as available system memory (rev2) Patchwork
2018-06-21 20:06 ` [igt-dev] ✓ Fi.CI.IGT: success for lib: Report file cache as available system memory Patchwork
2018-06-21 21:36 ` [igt-dev] ✓ Fi.CI.IGT: success for lib: Report file cache as available system memory (rev2) Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.