Skip to contentSkip to conversation

tests/gem_fence_thrash.c: Reduce memory usage

PATCH Superseded Derek Morton 2 participants 3 messages Jun 23, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tests/gem_fence_thrash.c: Reduce memory usage

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.

---
 tests/gem_fence_thrash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/gem_fence_thrash.c +4 -1
index 6447e13..e2ed024 100644
@@ -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;
 }
@@ -188,6 +189,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);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 6 lines · Derek Morton

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.

Urm. We allocate the surfaces from the test.fd, and we close(test.fd) at the end of every test. We munmap all the pointers (except bo_copy has a leak of the mmaps), so we should not have been leaking any bo between tests. This should not be improving the memory footprint at all, but suggests something is wrong in your kernel.

Did you track the kernel objects throughout the test runs? -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by
#2 lore raw
Quoted 8 lines · Chris Wilson
Quoted 6 lines · Derek Morton

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.

Quoted 5 lines

Urm. We allocate the surfaces from the test.fd, and we close(test.fd) at the end of every test. We munmap all the pointers (except bo_copy has a leak of the mmaps), so we should not have been leaking any bo between tests. This should not be improving the memory footprint at all, but suggests something is wrong in your kernel.

Spotted it, _bo_write_verify inflates the memory footprint by 1000%. Ok, all's happy now!

You also want

tests/gem_fence_thrash.c +3 -0
index 6447e13..cada526 100644
@@ -100,6 +100,9 @@ bo_copy (void *_arg)
                sched_yield ();
        }
 
+       munmap(a, OBJECT_SIZE);
+       munmap(b, OBJECT_SIZE);
+
        return NULL;
 }
 

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx