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>
This commit is contained in:
Chris Wilson
2014-04-03 09:43:58 +01:00
parent b8afe98004
commit e8869c4bc4
3 changed files with 45 additions and 3 deletions
+1
View File
@@ -61,6 +61,7 @@ void igt_wait_for_keypress(void);
/* These are separate to allow easier testing when porting, see the comment at
* the bottom of intel_os.c. */
uint64_t intel_get_avail_ram_mb(void);
uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void);
+34
View File
@@ -85,6 +85,40 @@ intel_get_total_ram_mb(void)
return retval / (1024*1024);
}
/**
* 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:
*