[i-g-t,v3] tests/gem_fence_thrash.c: Reduce memory usage
diff mbox

Message ID 1435138931-9496-1-git-send-email-derek.j.morton@intel.com
State New
Headers show

Commit Message

Derek Morton June 24, 2015, 9:42 a.m. UTC
On android platforms with 1Gb RAM gem_fence_thrash was failing
with an out of memory error.
This patch causes gem_close() to be called when a handle is
no longer required rather than relying on the cleanup when
the fd is closed. This greatly improves the memory footprint
of the test allowing it to run on 1Mb systems.

Also fixed a leak of the 'threads' variable.

v2: Simplified as per Chris Wilson's suggestion.
v3: Added calls to munmap() from bo_copy()

Signed-off-by: Derek Morton <derek.j.morton@intel.com>
---
 tests/gem_fence_thrash.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/tests/gem_fence_thrash.c b/tests/gem_fence_thrash.c
index 6447e13..f4ccfc0 100644
--- a/tests/gem_fence_thrash.c
+++ b/tests/gem_fence_thrash.c
@@ -63,7 +63,7 @@  static void *
 bo_create (int fd, int tiling)
 {
 	void *ptr;
-	int handle;
+	uint32_t handle;
 
 	handle = gem_create(fd, OBJECT_SIZE);
 
@@ -80,6 +80,7 @@  bo_create (int fd, int tiling)
 
 	/* XXX: mmap_gtt pulls the bo into the GTT read domain. */
 	gem_sync(fd, handle);
+	gem_close(fd, handle);
 
 	return ptr;
 }
@@ -100,6 +101,9 @@  bo_copy (void *_arg)
 		sched_yield ();
 	}
 
+	munmap(a, OBJECT_SIZE);
+	munmap(b, OBJECT_SIZE);
+
 	return NULL;
 }
 
@@ -188,6 +192,8 @@  static int run_test(int threads_per_fence, void *f, int tiling,
 
 		for (n = 0; n < num_threads; n++)
 			pthread_join (threads[n], NULL);
+
+		free(threads);
 	} else {
 		void *(*func)(void *) = f;
 		igt_assert(func(&t) == (void *)0);