From patchwork Mon Dec 30 15:56:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 3419691 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6A3B9F37A for ; Mon, 30 Dec 2013 15:57:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F75620107 for ; Mon, 30 Dec 2013 15:57:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0235D200D7 for ; Mon, 30 Dec 2013 15:57:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F4AAFB749; Mon, 30 Dec 2013 07:57:10 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qc0-f170.google.com (mail-qc0-f170.google.com [209.85.216.170]) by gabe.freedesktop.org (Postfix) with ESMTP id C3022FB74E for ; Mon, 30 Dec 2013 07:57:08 -0800 (PST) Received: by mail-qc0-f170.google.com with SMTP id x13so11230451qcv.1 for ; Mon, 30 Dec 2013 07:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Cp6dXmuTQfjlH2SN0MaOtl0aT3UEK+bT/PacXFEVTss=; b=uFisdj5/zrjRntGzCrHUkvbun+JDEujz4pUSoo1HiDpYSO0q7wEn0oG7C8hQOEZpSc BJUtYTxNlWI/46dqQ2kK161s5lmpK1B8OdkzSuGg1PaZH43v0EZbmzo0FJ7bJcwiYSmk KEMYDcs4XegqhYLNN7QEcBxRmBHes69cTULqoKwU37CCsolD8Qs1T5gNHLM2SKj9ubNw 7LcuwdFybJg3M5QNK+oXkBxvgASyRmVQBCcWYWKSUcWnGmpLEWI9+RMMvchtby8VrPZr zNVe8gXVm/nS+aruJLaQGAhiMlGh+XhWNubPudwvO7sZStrl5Kn+PLQXEL8DP9EZx3pG 4ctA== X-Received: by 10.49.108.200 with SMTP id hm8mr111515951qeb.53.1388419026156; Mon, 30 Dec 2013 07:57:06 -0800 (PST) Received: from localhost.localdomain ([187.112.58.219]) by mx.google.com with ESMTPSA id o3sm66129491qak.5.2013.12.30.07.57.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Dec 2013 07:57:05 -0800 (PST) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Mon, 30 Dec 2013 13:56:48 -0200 Message-Id: <1388419013-17016-1-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 1.8.3.1 Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH 1/6] igt_kms: don't leak the mmap used for cairo X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni 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 --- 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 {