Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t 01/17] lib: Report file cache as available system memory
@ 2018-07-02  9:07 Chris Wilson
  2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 02/17] igt/gem_tiled_partial_pwrite_pread: Check for known swizzling Chris Wilson
                   ` (18 more replies)
  0 siblings, 19 replies; 35+ messages in thread
From: Chris Wilson @ 2018-07-02  9:07 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!)

v2: Pay attention to what one writes.

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

diff --git a/lib/intel_os.c b/lib/intel_os.c
index 885ffdcec..5bd18fc52 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -84,6 +84,18 @@ intel_get_total_ram_mb(void)
 	return retval / (1024*1024);
 }
 
+static uint64_t get_meminfo(const char *info, const char *tag)
+{
+	const char *str;
+	unsigned long val;
+
+	str = strstr(info, tag);
+	if (str && sscanf(str + strlen(tag), " %lu", &val) == 1)
+		return (uint64_t)val << 10;
+
+	return 0;
+}
+
 /**
  * intel_get_avail_ram_mb:
  *
@@ -96,17 +108,31 @@ 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) {
+		retval  = get_meminfo(info, "MemAvailable: ");
+		retval += get_meminfo(info, "Buffers: ");
+		retval += get_meminfo(info, "Cached: ");
+		retval += get_meminfo(info, "SwapCached: ");
+		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

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

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

end of thread, other threads:[~2018-07-05 15:55 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-02  9:07 [Intel-gfx] [PATCH i-g-t 01/17] lib: Report file cache as available system memory Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 02/17] igt/gem_tiled_partial_pwrite_pread: Check for known swizzling Chris Wilson
2018-07-02 12:00   ` Tvrtko Ursulin
2018-07-05 11:14     ` [Intel-gfx] " Chris Wilson
2018-07-05 12:30       ` Tvrtko Ursulin
2018-07-05 12:35         ` Chris Wilson
2018-07-05 15:26           ` Tvrtko Ursulin
2018-07-05 15:55             ` Chris Wilson
2018-07-02  9:07 ` [Intel-gfx] [PATCH i-g-t 03/17] igt/gem_set_tiling_vs_pwrite: Show the erroneous value Chris Wilson
2018-07-02 12:00   ` [igt-dev] " Tvrtko Ursulin
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 04/17] lib: Convert spin batch constructor to a factory Chris Wilson
2018-07-02 15:34   ` Tvrtko Ursulin
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 05/17] lib: Spin fast, retire early Chris Wilson
2018-07-02 15:36   ` [Intel-gfx] " Tvrtko Ursulin
2018-07-05 11:23     ` [igt-dev] " Chris Wilson
2018-07-05 12:33       ` Tvrtko Ursulin
2018-07-05 12:42         ` [igt-dev] " Chris Wilson
2018-07-05 15:29           ` Tvrtko Ursulin
2018-07-05 15:52             ` Chris Wilson
2018-07-02  9:07 ` [Intel-gfx] [PATCH i-g-t 06/17] igt/gem_sync: Alternate stress for nop+sync Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 07/17] igt/gem_sync: Double the wakeups, twice the pain Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 08/17] igt/gem_sync: Show the baseline poll latency for wakeups Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 09/17] igt/gem_userptr: Check read-only mappings Chris Wilson
2018-07-02  9:07 ` [Intel-gfx] [PATCH i-g-t 10/17] igt: Exercise creating context with shared GTT Chris Wilson
2018-07-02  9:07 ` [Intel-gfx] [PATCH i-g-t 11/17] igt/gem_ctx_switch: Exercise queues Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 12/17] igt/gem_exec_whisper: Fork all-engine tests one-per-engine Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 13/17] igt: Add gem_ctx_engines Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 14/17] igt: Add gem_exec_balancer Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 15/17] benchmarks/wsim: Simulate and interpret .wsim Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 16/17] tools: capture execution pathways Chris Wilson
2018-07-02  9:07 ` [igt-dev] [PATCH i-g-t 17/17] igt/gem_exec_latency: Robustify measurements Chris Wilson
2018-07-02 11:54 ` [igt-dev] [PATCH i-g-t 01/17] lib: Report file cache as available system memory Tvrtko Ursulin
2018-07-02 12:08   ` Chris Wilson
2018-07-02 13:09 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/17] " Patchwork
2018-07-02 14:16 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox