Commit 271e7dec authored by Christian König's avatar Christian König

drm/mm: optimize find_hole() as well

Abort early if there isn't enough space to allocate from a subtree.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Acked-by: default avatarNirmoy Das <nirmoy.das@amd.com>
Link: https://patchwork.freedesktop.org/patch/370297/
parent 41c0e78a
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment