[PATCH] drm: Preallocate mm node for GTT mmap offset

Chris Wilson chris at chris-wilson.co.uk
Thu Dec 6 06:54:30 PST 2012


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 <chris at chris-wilson.co.uk>
Cc: Dave Airlie <airlied at redhat.com>
Cc: dri-devel at lists.freedesktop.org
---
 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;
 	}
 
-- 
1.7.10.4



More information about the dri-devel mailing list