From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/shrinker: Refactor common uninterruptible locking
Date: Tue, 05 Apr 2016 13:02:14 +0300 [thread overview]
Message-ID: <1459850534.5564.16.camel@linux.intel.com> (raw)
In-Reply-To: <1459848145-24042-1-git-send-email-chris@chris-wilson.co.uk>
On ti, 2016-04-05 at 10:22 +0100, Chris Wilson wrote:
> Both the oom and vmap notifier callbacks have a loop to acquire the
> struct_mutex and set the device as uninterruptible, within a certain
> time. Refactor the common code into a pair of functions.
>
> Suggested-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Looks good.
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> drivers/gpu/drm/i915/i915_gem_shrinker.c | 79 +++++++++++++++++---------------
> 1 file changed, 42 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
> index be7501afb59e..39943793edcc 100644
> --- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
> +++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
> @@ -289,35 +289,56 @@ i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
> return freed;
> }
>
> +struct shrinker_lock_uninterruptible {
> + bool was_interruptible;
> + bool unlock;
> +};
> +
> +static bool
> +i915_gem_shrinker_lock_uninterruptible(struct drm_i915_private *dev_priv,
> + struct shrinker_lock_uninterruptible *slu,
> + int timeout_ms)
> +{
> + unsigned long timeout = msecs_to_jiffies(timeout_ms) + 1;
> +
> + while (!i915_gem_shrinker_lock(dev_priv->dev, &slu->unlock)) {
> + schedule_timeout_killable(1);
> + if (fatal_signal_pending(current))
> + return false;
> + if (--timeout == 0) {
> + pr_err("Unable to lock GPU to purge memory.\n");
> + return false;
> + }
> + }
> +
> + slu->was_interruptible = dev_priv->mm.interruptible;
> + dev_priv->mm.interruptible = false;
> + return true;
> +}
> +
> +static void
> +i915_gem_shrinker_unlock_uninterruptible(struct drm_i915_private *dev_priv,
> + struct shrinker_lock_uninterruptible *slu)
> +{
> + dev_priv->mm.interruptible = slu->was_interruptible;
> + if (slu->unlock)
> + mutex_unlock(&dev_priv->dev->struct_mutex);
> +}
> +
> static int
> i915_gem_shrinker_oom(struct notifier_block *nb, unsigned long event, void *ptr)
> {
> struct drm_i915_private *dev_priv =
> container_of(nb, struct drm_i915_private, mm.oom_notifier);
> - struct drm_device *dev = dev_priv->dev;
> + struct shrinker_lock_uninterruptible slu;
> struct drm_i915_gem_object *obj;
> - unsigned long timeout = msecs_to_jiffies(5000) + 1;
> unsigned long pinned, bound, unbound, freed_pages;
> - bool was_interruptible;
> - bool unlock;
>
> - while (!i915_gem_shrinker_lock(dev, &unlock) && --timeout) {
> - schedule_timeout_killable(1);
> - if (fatal_signal_pending(current))
> - return NOTIFY_DONE;
> - }
> - if (timeout == 0) {
> - pr_err("Unable to purge GPU memory due lock contention.\n");
> + if (!i915_gem_shrinker_lock_uninterruptible(dev_priv, &slu, 5000))
> return NOTIFY_DONE;
> - }
> -
> - was_interruptible = dev_priv->mm.interruptible;
> - dev_priv->mm.interruptible = false;
>
> freed_pages = i915_gem_shrink_all(dev_priv);
>
> - dev_priv->mm.interruptible = was_interruptible;
> -
> /* Because we may be allocating inside our own driver, we cannot
> * assert that there are no objects with pinned pages that are not
> * being pointed to by hardware.
> @@ -342,8 +363,7 @@ i915_gem_shrinker_oom(struct notifier_block *nb, unsigned long event, void *ptr)
> bound += obj->base.size;
> }
>
> - if (unlock)
> - mutex_unlock(&dev->struct_mutex);
> + i915_gem_shrinker_unlock_uninterruptible(dev_priv, &slu);
>
> if (freed_pages || unbound || bound)
> pr_info("Purging GPU memory, %lu bytes freed, %lu bytes still pinned.\n",
> @@ -362,30 +382,15 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
> {
> struct drm_i915_private *dev_priv =
> container_of(nb, struct drm_i915_private, mm.vmap_notifier);
> - struct drm_device *dev = dev_priv->dev;
> - unsigned long timeout = msecs_to_jiffies(5000) + 1;
> + struct shrinker_lock_uninterruptible slu;
> unsigned long freed_pages;
> - bool was_interruptible;
> - bool unlock;
>
> - while (!i915_gem_shrinker_lock(dev, &unlock) && --timeout) {
> - schedule_timeout_killable(1);
> - if (fatal_signal_pending(current))
> - return NOTIFY_DONE;
> - }
> - if (timeout == 0) {
> - pr_err("Unable to purge GPU vmaps due to lock contention.\n");
> + if (!i915_gem_shrinker_lock_uninterruptible(dev_priv, &slu, 5000))
> return NOTIFY_DONE;
> - }
> -
> - was_interruptible = dev_priv->mm.interruptible;
> - dev_priv->mm.interruptible = false;
>
> freed_pages = i915_gem_shrink_all(dev_priv);
>
> - dev_priv->mm.interruptible = was_interruptible;
> - if (unlock)
> - mutex_unlock(&dev->struct_mutex);
> + i915_gem_shrinker_unlock_uninterruptible(dev_priv, &slu);
>
> *(unsigned long *)ptr += freed_pages;
> return NOTIFY_DONE;
--
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2016-04-05 10:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-04 13:46 vmap purge notifier for exhaustion of the vmalloc arena Chris Wilson
2016-04-04 13:46 ` [PATCH v2 1/3] drm/i915/shrinker: Account for unshrinkable unbound pages Chris Wilson
2016-04-05 7:57 ` Joonas Lahtinen
2016-04-04 13:46 ` [PATCH v2 2/3] mm/vmap: Add a notifier for when we run out of vmap address space Chris Wilson
2016-04-05 8:01 ` Joonas Lahtinen
2016-04-04 13:46 ` [PATCH v2 3/3] drm/i915/shrinker: Hook up vmap allocation failure notifier Chris Wilson
2016-04-05 8:19 ` Joonas Lahtinen
2016-04-05 9:03 ` Chris Wilson
2016-04-05 9:22 ` [PATCH] drm/i915/shrinker: Refactor common uninterruptible locking Chris Wilson
2016-04-05 10:02 ` Joonas Lahtinen [this message]
2016-04-05 10:59 ` Chris Wilson
2016-04-04 15:26 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/3] drm/i915/shrinker: Account for unshrinkable unbound pages Patchwork
2016-04-05 10:08 ` ✗ Fi.CI.BAT: failure for series starting with [v2,1/3] drm/i915/shrinker: Account for unshrinkable unbound pages (rev2) Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1459850534.5564.16.camel@linux.intel.com \
--to=joonas.lahtinen@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox