public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH 1/6] igt_kms: don't leak the mmap used for cairo
@ 2013-12-30 15:56 Paulo Zanoni
  2013-12-30 15:56 ` [PATCH 2/6] drmtest: don't leak memory when parsing the arguments Paulo Zanoni
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Paulo Zanoni @ 2013-12-30 15:56 UTC (permalink / raw)
  To: intel-gfx; +Cc: Paulo Zanoni

From: Paulo Zanoni <paulo.r.zanoni@intel.com>

When we call kmstest_get_cairo_ctx() and create a context, we do a
gem_mmap. The problem is that we lose the mmap pointer, so we leak it.
This patch stores the pointer and frees it at kmstest_remove_fb.

Huge test suites like kms_flip do this operation thousands of times,
which makes the virtual memory size increase until the test suite gets
killed. Today, without this patch, we can't even run 50% of the
kms_flip tests due to this problem. To test this, just "./kms_flip",
then run "top" and sort it by the VIRT column.

Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
---
 lib/igt_kms.c | 15 ++++++++++-----
 lib/igt_kms.h |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 57795b1..f032cd3 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -303,6 +303,7 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 	fb->height = height;
 	fb->tiling = tiled;
 	fb->drm_format = bpp_depth_to_drm_format(bpp, depth);
+	fb->fb_ptr = NULL;
 
 	return fb->fb_id;
 }
@@ -353,6 +354,7 @@ unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
 	fb->tiling = tiled;
 	fb->drm_format = format;
 	fb->fb_id = fb_id;
+	fb->fb_ptr = NULL;
 
 	return fb_id;
 }
@@ -372,13 +374,14 @@ static cairo_surface_t *create_image_surface(int fd, struct kmstest_fb *fb)
 {
 	cairo_surface_t *surface;
 	cairo_format_t cformat;
-	void *fb_ptr;
 
 	cformat = drm_format_to_cairo(fb->drm_format);
-	fb_ptr = gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
-	surface = cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
-						   cformat, fb->width,
-						   fb->height, fb->stride);
+	fb->fb_ptr = gem_mmap(fd, fb->gem_handle, fb->size,
+			      PROT_READ | PROT_WRITE);
+	surface = cairo_image_surface_create_for_data(
+						(unsigned char *)fb->fb_ptr,
+						cformat, fb->width,
+						fb->height, fb->stride);
 	assert(surface);
 
 	return surface;
@@ -423,6 +426,8 @@ void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
 {
 	if (fb->cairo_ctx)
 		cairo_destroy(fb->cairo_ctx);
+	if (fb->fb_ptr)
+		munmap(fb->fb_ptr, fb->size);
 	do_or_die(drmModeRmFB(fd, fb->fb_id));
 	gem_close(fd, fb->gem_handle);
 }
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index f61f8e5..f9494d0 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -55,6 +55,7 @@ struct kmstest_fb {
 	unsigned tiling;
 	unsigned size;
 	cairo_t *cairo_ctx;
+	void *fb_ptr;
 };
 
 enum kmstest_text_align {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-01-07  7:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-30 15:56 [PATCH 1/6] igt_kms: don't leak the mmap used for cairo Paulo Zanoni
2013-12-30 15:56 ` [PATCH 2/6] drmtest: don't leak memory when parsing the arguments Paulo Zanoni
2013-12-30 15:56 ` [PATCH 3/6] tests/kms_flip: don't leak the connector when setting DPMS Paulo Zanoni
2013-12-30 15:56 ` [PATCH 4/6] tests/kms_flip: don't leak the CRTC Paulo Zanoni
2013-12-30 15:56 ` [PATCH 5/6] tests/kms_flip: don't leak the connector_config struct Paulo Zanoni
2013-12-30 15:56 ` [PATCH 6/6] tests/kms_flip: free the test_output struct when counting modes Paulo Zanoni
2014-01-07  7:16   ` Daniel Vetter
2013-12-30 17:40 ` [PATCH 1/6] igt_kms: don't leak the mmap used for cairo Chris Wilson
2013-12-30 17:53   ` Paulo Zanoni
2013-12-30 18:16     ` Chris Wilson
2013-12-31 12:32       ` Chris Wilson
2014-01-02 16:44         ` Paulo Zanoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox