* [PATCH] drm/i915: optionally disable shrinker lock stealing
@ 2012-12-19 12:08 Daniel Vetter
2012-12-19 12:22 ` Chris Wilson
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2012-12-19 12:08 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
commit 5774506f157a91400c587b85d1ce4de56f0d32f6
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date: Wed Nov 21 13:04:04 2012 +0000
drm/i915: Borrow our struct_mutex for the direct reclaim
added a nice trick to steal the struct_mutex lock in the shrinker if
it's the current task holding it. But this also caused the requirement
that every place which allocates memory needs to be careful about the
gem state of objects, since the shrinker could have pulled the rug out
from under it. We've usually solved this by carefully preallocating
things or ensure that buffers are pinned already.
But the shrinker also reaps mmap offset, so allocating those needs to
be careful, too. Now that code has been factored out into some common
helpers, so either we have fragile code depending upon the common
helper not doing something we don't want it to do. Or we need to
reimplement the mmap offset creation and so also leak implementation
details into our code.
Since this all results in leaky abstraction, cop out by disabling the
lock borrowing trick while calling down into the helpers. That way our
craziness is nicely confined to files in drm/i915.
This should fix igt/gem_tiled_swapping.
Reported-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/i915/i915_drv.h | 1 +
drivers/gpu/drm/i915/i915_gem.c | 16 +++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2ab476d..87747da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -807,6 +807,7 @@ typedef struct drm_i915_private {
struct i915_hw_ppgtt *aliasing_ppgtt;
struct shrinker inactive_shrinker;
+ bool shrinker_no_lock_stealing;
/**
* List of objects currently involved in rendering.
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 9530592..4d3605c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1514,9 +1514,11 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
if (obj->base.map_list.map)
return 0;
+ dev_priv->mm.shrinker_no_lock_stealing = true;
+
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
/* Badly fragmented mmap space? The only way we can recover
* space is by destroying unwanted objects. We can't randomly release
@@ -1528,10 +1530,15 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
i915_gem_purge(dev_priv, obj->base.size >> PAGE_SHIFT);
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
i915_gem_shrink_all(dev_priv);
- return drm_gem_create_mmap_offset(&obj->base);
+ ret = drm_gem_create_mmap_offset(&obj->base);
+
+ dev_priv->mm.shrinker_no_lock_stealing = false;
+
+out:
+ return ret;
}
static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj)
@@ -4400,6 +4407,9 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
if (!mutex_is_locked_by(&dev->struct_mutex, current))
return 0;
+ if (dev_priv->mm.shrinker_no_lock_stealing)
+ return 0;
+
unlock = false;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/i915: optionally disable shrinker lock stealing
2012-12-19 12:08 [PATCH] drm/i915: optionally disable shrinker lock stealing Daniel Vetter
@ 2012-12-19 12:22 ` Chris Wilson
2012-12-19 13:33 ` [PATCH 1/2] " Daniel Vetter
0 siblings, 1 reply; 7+ messages in thread
From: Chris Wilson @ 2012-12-19 12:22 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
On Wed, 19 Dec 2012 13:08:35 +0100, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> commit 5774506f157a91400c587b85d1ce4de56f0d32f6
> Author: Chris Wilson <chris@chris-wilson.co.uk>
> Date: Wed Nov 21 13:04:04 2012 +0000
>
> drm/i915: Borrow our struct_mutex for the direct reclaim
If you choose to take this path, do it as two patches so that we can
simply remove the mmap_offset wrapping. I still think this is a much
greater kludge than fixing the search/allocation ordering.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] drm/i915: optionally disable shrinker lock stealing
2012-12-19 12:22 ` Chris Wilson
@ 2012-12-19 13:33 ` Daniel Vetter
2012-12-19 13:33 ` [PATCH 2/2] drm/i915: disable shrinker lock stealing for create_mmap_offset Daniel Vetter
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2012-12-19 13:33 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
commit 5774506f157a91400c587b85d1ce4de56f0d32f6
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date: Wed Nov 21 13:04:04 2012 +0000
drm/i915: Borrow our struct_mutex for the direct reclaim
added a nice trick to steal the struct_mutex lock in the shrinker if
it's the current task holding it. But this also caused the requirement
that every place which allocates memory needs to be careful about the
gem state of objects, since the shrinker could have pulled the rug out
from under it. We've usually solved this by carefully preallocating
things or ensure that buffers are pinned already.
But the shrinker also reaps mmap offset, so allocating those needs to
be careful, too. Now that code has been factored out into some common
helpers, so either we have fragile code depending upon the common
helper not doing something we don't want it to do. Or we need to
reimplement the mmap offset creation and so also leak implementation
details into our code.
Since this all results in leaky abstraction, cop out by disabling the
lock borrowing trick while calling down into the helpers. That way our
craziness is nicely confined to files in drm/i915.
v2: Split out the change to create_mmap_offset as request by Chris Wilson.
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/i915/i915_drv.h | 1 +
drivers/gpu/drm/i915/i915_gem.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2ab476d..87747da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -807,6 +807,7 @@ typedef struct drm_i915_private {
struct i915_hw_ppgtt *aliasing_ppgtt;
struct shrinker inactive_shrinker;
+ bool shrinker_no_lock_stealing;
/**
* List of objects currently involved in rendering.
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 9530592..db4b470 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4400,6 +4400,9 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
if (!mutex_is_locked_by(&dev->struct_mutex, current))
return 0;
+ if (dev_priv->mm.shrinker_no_lock_stealing)
+ return 0;
+
unlock = false;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] drm/i915: disable shrinker lock stealing for create_mmap_offset
2012-12-19 13:33 ` [PATCH 1/2] " Daniel Vetter
@ 2012-12-19 13:33 ` Daniel Vetter
2012-12-19 13:49 ` Chris Wilson
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2012-12-19 13:33 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
The mmap offset structure is not part of the drm/i915 code, but
provided by gem helpers. To avoid leaky abstractions (by either
depending upon implementation details of said helper wrt to
preallocations, or reimplementing it in our code and so fuzzing
around in internal details of that helpr) simply disable
the shrinker lock stealing accross calls into the helper functions.
This should fix igt/gem_tiled_swapping.
Reported-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/i915/i915_gem.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index db4b470..4d3605c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1514,9 +1514,11 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
if (obj->base.map_list.map)
return 0;
+ dev_priv->mm.shrinker_no_lock_stealing = true;
+
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
/* Badly fragmented mmap space? The only way we can recover
* space is by destroying unwanted objects. We can't randomly release
@@ -1528,10 +1530,15 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
i915_gem_purge(dev_priv, obj->base.size >> PAGE_SHIFT);
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
i915_gem_shrink_all(dev_priv);
- return drm_gem_create_mmap_offset(&obj->base);
+ ret = drm_gem_create_mmap_offset(&obj->base);
+
+ dev_priv->mm.shrinker_no_lock_stealing = false;
+
+out:
+ return ret;
}
static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] drm/i915: disable shrinker lock stealing for create_mmap_offset
2012-12-19 13:33 ` [PATCH 2/2] drm/i915: disable shrinker lock stealing for create_mmap_offset Daniel Vetter
@ 2012-12-19 13:49 ` Chris Wilson
[not found] ` <1355928016-15701-1-git-send-email-daniel.vetter@ffwll.ch>
2012-12-20 14:11 ` Daniel Vetter
0 siblings, 2 replies; 7+ messages in thread
From: Chris Wilson @ 2012-12-19 13:49 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
On Wed, 19 Dec 2012 14:33:46 +0100, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> The mmap offset structure is not part of the drm/i915 code, but
> provided by gem helpers. To avoid leaky abstractions (by either
> depending upon implementation details of said helper wrt to
> preallocations, or reimplementing it in our code and so fuzzing
> around in internal details of that helpr) simply disable
> the shrinker lock stealing accross calls into the helper functions.
>
> This should fix igt/gem_tiled_swapping.
Proving that if we just fixed the code stolen from us, we'd run less
chance of introducing bugs.... :-p
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/i915: disable shrinker lock stealing for create_mmap_offset
[not found] ` <f5ae8a$7um44j@fmsmga002.fm.intel.com>
@ 2012-12-20 14:03 ` Daniel Vetter
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Vetter @ 2012-12-20 14:03 UTC (permalink / raw)
To: Chris Wilson, intel-gfx
On Wed, Dec 19, 2012 at 4:02 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Wed, 19 Dec 2012 15:40:16 +0100, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>> The mmap offset structure is not part of the drm/i915 code, but
>> provided by gem helpers. To avoid leaky abstractions (by either
>> depending upon implementation details of said helper wrt to
>> preallocations, or reimplementing it in our code and so fuzzing
>> around in internal details of that helpr) simply disable
>> the shrinker lock stealing accross calls into the helper functions.
>>
>> This should fix igt/gem_tiled_swapping.
>>
>> v2: Fix cleanup path confusion bemoaned by Chris Wilson.
>>
>> Reported-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
>> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>
> You can have a Reviewed-by for the flag, and a
> This-works-but-I-do-not-think-it-addresses-the-bug for this kludge.
Merged both - I agree that this here is not a beauty, but it removes a
tricky dependency on the helper code while that one seems to be a bit
in flux. Beating the helper code a bit into shape cane be done on top,
and if we embed the drm_mm_node (as we should imo) all allocations
disapper. So this patch here would then have no effect any longer and
we could drop it again.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] drm/i915: disable shrinker lock stealing for create_mmap_offset
2012-12-19 13:49 ` Chris Wilson
[not found] ` <1355928016-15701-1-git-send-email-daniel.vetter@ffwll.ch>
@ 2012-12-20 14:11 ` Daniel Vetter
1 sibling, 0 replies; 7+ messages in thread
From: Daniel Vetter @ 2012-12-20 14:11 UTC (permalink / raw)
To: Intel Graphics Development; +Cc: Daniel Vetter
The mmap offset structure is not part of the drm/i915 code, but
provided by gem helpers. To avoid leaky abstractions (by either
depending upon implementation details of said helper wrt to
preallocations, or reimplementing it in our code and so fuzzing
around in internal details of that helpr) simply disable
the shrinker lock stealing accross calls into the helper functions.
This should fix igt/gem_tiled_swapping.
v2: Fix cleanup path confusion bemoaned by Chris Wilson.
Reported-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/i915/i915_gem.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index db4b470..51df4ee 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1514,9 +1514,11 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
if (obj->base.map_list.map)
return 0;
+ dev_priv->mm.shrinker_no_lock_stealing = true;
+
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
/* Badly fragmented mmap space? The only way we can recover
* space is by destroying unwanted objects. We can't randomly release
@@ -1528,10 +1530,14 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
i915_gem_purge(dev_priv, obj->base.size >> PAGE_SHIFT);
ret = drm_gem_create_mmap_offset(&obj->base);
if (ret != -ENOSPC)
- return ret;
+ goto out;
i915_gem_shrink_all(dev_priv);
- return drm_gem_create_mmap_offset(&obj->base);
+ ret = drm_gem_create_mmap_offset(&obj->base);
+out:
+ dev_priv->mm.shrinker_no_lock_stealing = false;
+
+ return ret;
}
static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-12-20 14:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-19 12:08 [PATCH] drm/i915: optionally disable shrinker lock stealing Daniel Vetter
2012-12-19 12:22 ` Chris Wilson
2012-12-19 13:33 ` [PATCH 1/2] " Daniel Vetter
2012-12-19 13:33 ` [PATCH 2/2] drm/i915: disable shrinker lock stealing for create_mmap_offset Daniel Vetter
2012-12-19 13:49 ` Chris Wilson
[not found] ` <1355928016-15701-1-git-send-email-daniel.vetter@ffwll.ch>
[not found] ` <f5ae8a$7um44j@fmsmga002.fm.intel.com>
2012-12-20 14:03 ` [PATCH] " Daniel Vetter
2012-12-20 14:11 ` Daniel Vetter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.