diff mbox

[3/4] drm/i915: Limit searching for PIN_HIGH

Message ID 20180513075010.23275-3-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson May 13, 2018, 7:50 a.m. UTC
To no surprise (since we've flip-flopped over the use of PIN_HIGH a few
times), doing a search by address over a pathologically fragmented
address space is exceeding slow. To protect ourselves from nearly
unbounded latency (think searching a million holes while under
struct_mutex), limit the search for the highest available hole and
fallback to best-fit if it fails.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Joonas Lahtinen May 18, 2018, 10:05 a.m. UTC | #1
Quoting Chris Wilson (2018-05-13 10:50:09)
> To no surprise (since we've flip-flopped over the use of PIN_HIGH a few
> times), doing a search by address over a pathologically fragmented
> address space is exceeding slow. To protect ourselves from nearly
> unbounded latency (think searching a million holes while under
> struct_mutex), limit the search for the highest available hole and
> fallback to best-fit if it fails.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Some testcase or measurement to quote before merging?

Code itself is;

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Regards, Joonas

> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index c01d6dbe269a..cc9eb5956c44 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -3967,7 +3967,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
>  
>         mode = DRM_MM_INSERT_BEST;
>         if (flags & PIN_HIGH)
> -               mode = DRM_MM_INSERT_HIGH;
> +               mode = DRM_MM_INSERT_HIGHEST;
>         if (flags & PIN_MAPPABLE)
>                 mode = DRM_MM_INSERT_LOW;
>  
> @@ -3987,6 +3987,15 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
>         if (err != -ENOSPC)
>                 return err;
>  
> +       if (mode & DRM_MM_INSERT_END) {
> +               err = drm_mm_insert_node_in_range(&vm->mm, node,
> +                                                 size, alignment, color,
> +                                                 start, end,
> +                                                 DRM_MM_INSERT_BEST);
> +               if (err != -ENOSPC)
> +                       return err;
> +       }
> +
>         if (flags & PIN_NOEVICT)
>                 return -ENOSPC;
>  
> -- 
> 2.17.0
>
Chris Wilson May 18, 2018, 10:07 a.m. UTC | #2
Quoting Joonas Lahtinen (2018-05-18 11:05:36)
> Quoting Chris Wilson (2018-05-13 10:50:09)
> > To no surprise (since we've flip-flopped over the use of PIN_HIGH a few
> > times), doing a search by address over a pathologically fragmented
> > address space is exceeding slow. To protect ourselves from nearly
> > unbounded latency (think searching a million holes while under
> > struct_mutex), limit the search for the highest available hole and
> > fallback to best-fit if it fails.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> 
> Some testcase or measurement to quote before merging?

igt/gem_ctx_thrash goes from hours to seconds.
-Chris
Joonas Lahtinen May 18, 2018, 10:31 a.m. UTC | #3
Quoting Chris Wilson (2018-05-18 13:07:16)
> Quoting Joonas Lahtinen (2018-05-18 11:05:36)
> > Quoting Chris Wilson (2018-05-13 10:50:09)
> > > To no surprise (since we've flip-flopped over the use of PIN_HIGH a few
> > > times), doing a search by address over a pathologically fragmented
> > > address space is exceeding slow. To protect ourselves from nearly
> > > unbounded latency (think searching a million holes while under
> > > struct_mutex), limit the search for the highest available hole and
> > > fallback to best-fit if it fails.
> > > 
> > > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > 
> > Some testcase or measurement to quote before merging?
> 
> igt/gem_ctx_thrash goes from hours to seconds.

Thats a good merit, do add it :)

Regards, Joonas

> -Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index c01d6dbe269a..cc9eb5956c44 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3967,7 +3967,7 @@  int i915_gem_gtt_insert(struct i915_address_space *vm,
 
 	mode = DRM_MM_INSERT_BEST;
 	if (flags & PIN_HIGH)
-		mode = DRM_MM_INSERT_HIGH;
+		mode = DRM_MM_INSERT_HIGHEST;
 	if (flags & PIN_MAPPABLE)
 		mode = DRM_MM_INSERT_LOW;
 
@@ -3987,6 +3987,15 @@  int i915_gem_gtt_insert(struct i915_address_space *vm,
 	if (err != -ENOSPC)
 		return err;
 
+	if (mode & DRM_MM_INSERT_END) {
+		err = drm_mm_insert_node_in_range(&vm->mm, node,
+						  size, alignment, color,
+						  start, end,
+						  DRM_MM_INSERT_BEST);
+		if (err != -ENOSPC)
+			return err;
+	}
+
 	if (flags & PIN_NOEVICT)
 		return -ENOSPC;