public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Paulo Zanoni <przanoni@gmail.com>
To: intel-gfx@lists.freedesktop.org
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Subject: [PATCH 1/6] igt_kms: don't leak the mmap used for cairo
Date: Mon, 30 Dec 2013 13:56:48 -0200	[thread overview]
Message-ID: <1388419013-17016-1-git-send-email-przanoni@gmail.com> (raw)

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

             reply	other threads:[~2013-12-30 15:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-30 15:56 Paulo Zanoni [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388419013-17016-1-git-send-email-przanoni@gmail.com \
    --to=przanoni@gmail.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=paulo.r.zanoni@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox