From 925e5e1caef9b56bd53df457735514b644c7a399 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 29 Feb 2016 15:33:26 +0000 Subject: lib: Check required number of surfaces against VFS file limits If we want to create more file handles than VFS supports (itself often a memory limited value), report that we can not create that many objects via intel_require_memory(). Signed-off-by: Chris Wilson --- lib/intel_os.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib/intel_os.c') diff --git a/lib/intel_os.c b/lib/intel_os.c index 2851dba0..b6a61921 100644 --- a/lib/intel_os.c +++ b/lib/intel_os.c @@ -192,6 +192,20 @@ intel_get_total_swap_mb(void) return retval / (1024*1024); } +static uint64_t vfs_file_max(void) +{ + static long long unsigned max; + if (max == 0) { + FILE *file = fopen("/proc/sys/fs/file-max", "r"); + max = 80000; + if (file) { + igt_assert(fscanf(file, "%llu", &max) == 1); + fclose(file); + } + } + return max; +} + int __intel_check_memory(uint64_t count, uint64_t size, unsigned mode, uint64_t *out_required, uint64_t *out_total) { @@ -221,6 +235,9 @@ int __intel_check_memory(uint64_t count, uint64_t size, unsigned mode, if (out_total) *out_total = total; + if (count > vfs_file_max()) + return false; + return required < total; } @@ -253,11 +270,13 @@ void intel_require_memory(uint64_t count, uint64_t size, unsigned mode) igt_skip_on_f(!__intel_check_memory(count, size, mode, &required, &total), - "Estimated that we need %'llu MiB for the test, but only have %'llu MiB available (%s%s)\n", + "Estimated that we need %'llu objects and %'llu MiB for the test, but only have %'llu MiB available (%s%s) and a maximum of %'llu objects\n", + (long long)count, (long long)((required + ((1<<20) - 1)) >> 20), (long long)(total >> 20), mode & (CHECK_RAM | CHECK_SWAP) ? "RAM" : "", - mode & CHECK_SWAP ? " + swap": ""); + mode & CHECK_SWAP ? " + swap": "", + (long long)vfs_file_max()); igt_skip_on_simulation(); } -- cgit v1.2.3