drm/mm: optimize find_hole() as well
authorChristian König <christian.koenig@amd.com>
Tue, 9 Jun 2020 12:47:33 +0000 (14:47 +0200)
committerChristian König <christian.koenig@amd.com>
Tue, 23 Jun 2020 13:46:06 +0000 (15:46 +0200)
Abort early if there isn't enough space to allocate from a subtree.

Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Nirmoy Das <nirmoy.das@amd.com>
Link: https://patchwork.freedesktop.org/patch/370297/
drivers/gpu/drm/drm_mm.c
drivers/gpu/drm/selftests/test-drm_mm.c

index 425fcd3..177a5df 100644 (file)
@@ -325,7 +325,7 @@ static struct drm_mm_node *best_hole(struct drm_mm *mm, u64 size)
        return best;
 }
 
-static struct drm_mm_node *find_hole(struct drm_mm *mm, u64 addr)
+static struct drm_mm_node *find_hole_addr(struct drm_mm *mm, u64 addr, u64 size)
 {
        struct rb_node *rb = mm->holes_addr.rb_node;
        struct drm_mm_node *node = NULL;
@@ -333,6 +333,9 @@ static struct drm_mm_node *find_hole(struct drm_mm *mm, u64 addr)
        while (rb) {
                u64 hole_start;
 
+               if (rb_hole_addr_to_node(rb)->subtree_max_hole < size)
+                       break;
+
                node = rb_hole_addr_to_node(rb);
                hole_start = __drm_mm_hole_node_start(node);
 
@@ -358,10 +361,10 @@ first_hole(struct drm_mm *mm,
                return best_hole(mm, size);
 
        case DRM_MM_INSERT_LOW:
-               return find_hole(mm, start);
+               return find_hole_addr(mm, start, size);
 
        case DRM_MM_INSERT_HIGH:
-               return find_hole(mm, end);
+               return find_hole_addr(mm, end, size);
 
        case DRM_MM_INSERT_EVICT:
                return list_first_entry_or_null(&mm->hole_stack,
@@ -497,7 +500,7 @@ int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node)
                return -ENOSPC;
 
        /* Find the relevant hole to add our node to */
-       hole = find_hole(mm, node->start);
+       hole = find_hole_addr(mm, node->start, 0);
        if (!hole)
                return -ENOSPC;
 
index 3846b0f..910eac2 100644 (file)
@@ -1981,16 +1981,6 @@ static int __igt_once(unsigned int mode)
        }
 
        memset(&node, 0, sizeof(node));
-       err = drm_mm_insert_node_generic(&mm, &node,
-                                        2, 0, 0,
-                                        mode | DRM_MM_INSERT_ONCE);
-       if (!err) {
-               pr_err("Unexpectedly inserted the node into the wrong hole: node.start=%llx\n",
-                      node.start);
-               err = -EINVAL;
-               goto err_node;
-       }
-
        err = drm_mm_insert_node_generic(&mm, &node, 2, 0, 0, mode);
        if (err) {
                pr_err("Could not insert the node into the available hole!\n");
@@ -1998,7 +1988,6 @@ static int __igt_once(unsigned int mode)
                goto err_hi;
        }
 
-err_node:
        drm_mm_remove_node(&node);
 err_hi:
        drm_mm_remove_node(&rsvd_hi);