summaryrefslogtreecommitdiff
path: root/lib/intel_os.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2014-04-03 09:43:58 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2014-04-03 09:45:55 +0100
commite8869c4bc439de941be399d156323620a2d6ecda (patch)
treeb69153bb370b5af960c0296b4c1ed0aa1a6d920f /lib/intel_os.c
parentb8afe98004ed0e082bf5d019a86f27a5909f0e4d (diff)
gem_tiled_swapping: Limit to available memory
If there is not enough free RAM+swap for us to execute our test, we will hit OOM, so check first. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/intel_os.c')
-rw-r--r--lib/intel_os.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/intel_os.c b/lib/intel_os.c
index fb9f19cb..6f0621c7 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -86,6 +86,40 @@ intel_get_total_ram_mb(void)
}
/**
+ * intel_get_avail_ram_mb:
+ *
+ * Returns:
+ * The amount of unused system RAM available in MB.
+ */
+uint64_t
+intel_get_avail_ram_mb(void)
+{
+ uint64_t retval;
+
+#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
+ struct sysinfo sysinf;
+ int ret;
+
+ ret = sysinfo(&sysinf);
+ assert(ret == 0);
+
+ retval = sysinf.freeram;
+ retval *= sysinf.mem_unit;
+#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) /* Solaris */
+ long pagesize, npages;
+
+ pagesize = sysconf(_SC_PAGESIZE);
+ npages = sysconf(_SC_AVPHYS_PAGES);
+
+ retval = (uint64_t) pagesize * npages;
+#else
+#error "Unknown how to get available RAM for this OS"
+#endif
+
+ return retval / (1024*1024);
+}
+
+/**
* intel_get_total_swap_mb:
*
* Returns: