From patchwork Thu Dec 6 14:54:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 1845211 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id C173A400ED for ; Thu, 6 Dec 2012 15:25:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D026E684F for ; Thu, 6 Dec 2012 07:25:50 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 1288 seconds by postgrey-1.32 at gabe; Thu, 06 Dec 2012 07:17:46 PST Received: from fireflyinternet.com (server109-228-6-235.live-servers.net [109.228.6.235]) by gabe.freedesktop.org (Postfix) with ESMTP id AB45CE68C6 for ; Thu, 6 Dec 2012 07:17:46 -0800 (PST) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.73.22; Received: from arrandale.alporthouse.com (unverified [78.156.73.22]) by fireflyinternet.com (Firefly Internet SMTP) with ESMTP id 125535870-1500050 for multiple; Thu, 06 Dec 2012 14:56:14 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Subject: [PATCH] drm: Preallocate mm node for GTT mmap offset Date: Thu, 6 Dec 2012 14:54:30 +0000 Message-Id: <1354805670-302-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.7.10.4 X-Originating-IP: 78.156.73.22 Cc: Dave Airlie , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org As the shrinker may be invoked for the allocation, and it may reap neighbouring objects in the offset range mm, we need to be careful in the order in which we allocate the node, search for free space and then insert the node into the mmap offset range manager. Signed-off-by: Chris Wilson Cc: Dave Airlie Cc: dri-devel@lists.freedesktop.org Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_gem.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 24efae4..3a2d594 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -353,19 +353,17 @@ drm_gem_create_mmap_offset(struct drm_gem_object *obj) map->handle = obj; /* Get a DRM GEM mmap offset allocated... */ - list->file_offset_node = drm_mm_search_free(&mm->offset_manager, - obj->size / PAGE_SIZE, 0, false); - - if (!list->file_offset_node) { - DRM_ERROR("failed to allocate offset for bo %d\n", obj->name); - ret = -ENOSPC; + list->file_offset_node = kzalloc(sizeof(struct drm_mm_node), GFP_KERNEL); + if (list->file_offset_node == NULL) { + ret = -ENOMEM; goto out_free_list; } - list->file_offset_node = drm_mm_get_block(list->file_offset_node, - obj->size / PAGE_SIZE, 0); - if (!list->file_offset_node) { - ret = -ENOMEM; + ret = drm_mm_insert_node(&mm->offset_manager, list->file_offset_node, + obj->size / PAGE_SIZE, 0); + if (ret) { + DRM_ERROR("failed to allocate offset for bo\n"); + kfree(list->file_offset_node); goto out_free_list; }