From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Remove the duplicated logic between the two shrink phases
Date: Fri, 3 Oct 2014 15:41:21 +0200 [thread overview]
Message-ID: <20141003134121.GG16117@phenom.ffwll.local> (raw)
In-Reply-To: <1412328591-6251-1-git-send-email-chris@chris-wilson.co.uk>
On Fri, Oct 03, 2014 at 10:29:51AM +0100, Chris Wilson wrote:
> We can use the same logic to walk the different bound/unbound lists
> during shrinker (as the unbound list is a degenerate case of the bound
> list), slightly compacting the code.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Queued for -next, thanks for the patch.
-Daniel
> ---
> drivers/gpu/drm/i915/i915_gem.c | 49 ++++++++++++++++-------------------------
> 1 file changed, 19 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index fccb811ba6da..f6893bc8613c 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -2040,7 +2040,14 @@ unsigned long
> i915_gem_shrink(struct drm_i915_private *dev_priv,
> long target, unsigned flags)
> {
> - const bool purgeable_only = flags & I915_SHRINK_PURGEABLE;
> + const struct {
> + struct list_head *list;
> + unsigned int bit;
> + } phases[] = {
> + { &dev_priv->mm.unbound_list, I915_SHRINK_UNBOUND },
> + { &dev_priv->mm.bound_list, I915_SHRINK_BOUND },
> + { NULL, 0 },
> + }, *phase;
> unsigned long count = 0;
>
> /*
> @@ -2062,48 +2069,30 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
> * dev->struct_mutex and so we won't ever be able to observe an
> * object on the bound_list with a reference count equals 0.
> */
> - if (flags & I915_SHRINK_UNBOUND) {
> + for (phase = phases; phase->list; phase++) {
> struct list_head still_in_list;
>
> - INIT_LIST_HEAD(&still_in_list);
> - while (count < target && !list_empty(&dev_priv->mm.unbound_list)) {
> - struct drm_i915_gem_object *obj;
> -
> - obj = list_first_entry(&dev_priv->mm.unbound_list,
> - typeof(*obj), global_list);
> - list_move_tail(&obj->global_list, &still_in_list);
> -
> - if (!i915_gem_object_is_purgeable(obj) && purgeable_only)
> - continue;
> -
> - drm_gem_object_reference(&obj->base);
> -
> - if (i915_gem_object_put_pages(obj) == 0)
> - count += obj->base.size >> PAGE_SHIFT;
> -
> - drm_gem_object_unreference(&obj->base);
> - }
> - list_splice(&still_in_list, &dev_priv->mm.unbound_list);
> - }
> -
> - if (flags & I915_SHRINK_BOUND) {
> - struct list_head still_in_list;
> + if ((flags & phase->bit) == 0)
> + continue;
>
> INIT_LIST_HEAD(&still_in_list);
> - while (count < target && !list_empty(&dev_priv->mm.bound_list)) {
> + while (count < target && !list_empty(phase->list)) {
> struct drm_i915_gem_object *obj;
> struct i915_vma *vma, *v;
>
> - obj = list_first_entry(&dev_priv->mm.bound_list,
> + obj = list_first_entry(phase->list,
> typeof(*obj), global_list);
> list_move_tail(&obj->global_list, &still_in_list);
>
> - if (!i915_gem_object_is_purgeable(obj) && purgeable_only)
> + if (flags & I915_SHRINK_PURGEABLE &&
> + !i915_gem_object_is_purgeable(obj))
> continue;
>
> drm_gem_object_reference(&obj->base);
>
> - list_for_each_entry_safe(vma, v, &obj->vma_list, vma_link)
> + /* For the unbound phase, this should be a no-op! */
> + list_for_each_entry_safe(vma, v,
> + &obj->vma_list, vma_link)
> if (i915_vma_unbind(vma))
> break;
>
> @@ -2112,7 +2101,7 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
>
> drm_gem_object_unreference(&obj->base);
> }
> - list_splice(&still_in_list, &dev_priv->mm.bound_list);
> + list_splice(&still_in_list, phase->list);
> }
>
> return count;
> --
> 2.1.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
prev parent reply other threads:[~2014-10-03 13:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-03 9:29 [PATCH] drm/i915: Remove the duplicated logic between the two shrink phases Chris Wilson
2014-10-03 13:41 ` Daniel Vetter [this message]
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=20141003134121.GG16117@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--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;
as well as URLs for NNTP newsgroup(s).