From 3693d7aa71ddb6236164ddd6ffd658ec0be8f6df Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 9 Jan 2013 02:35:16 +0000 Subject: [PATCH 1/2] longshot2 --- drivers/gpu/drm/i915/i915_gem.c | 52 +++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 845cc04..cb7e0ee 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4405,6 +4405,51 @@ static bool mutex_is_locked_by(struct mutex *mutex, struct task_struct *task) #endif } +static void i915_gem_shrink(struct drm_i915_private *dev_priv, + unsigned long target) +{ + struct drm_i915_gem_object *obj, *next; + unsigned long count = 0; + + list_for_each_entry_safe(obj, next, + &dev_priv->mm.unbound_list, + gtt_list) { + if (i915_gem_object_put_pages(obj) == 0) { + count += obj->base.size >> PAGE_SHIFT; + if (count >= target) + return; + } + } + + list_for_each_entry_safe(obj, next, + &dev_priv->mm.inactive_list, + mm_list) { + if (i915_gem_object_is_purgeable(obj) && + i915_gem_object_unbind(obj) == 0 && + i915_gem_object_put_pages(obj) == 0) { + count += obj->base.size >> PAGE_SHIFT; + if (count >= target) + return; + } + } + + list_for_each_entry_safe(obj, next, + &dev_priv->mm.inactive_list, + mm_list) { + if (obj->base.read_domains & I915_GEM_DOMAIN_INSTRUCTION) + continue; + + if (i915_gem_object_unbind(obj) == 0 && + i915_gem_object_put_pages(obj) == 0) { + count += obj->base.size >> PAGE_SHIFT; + if (count >= target) + return; + } + } + + i915_gem_shrink_all(dev_priv); +} + static int i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) { @@ -4425,11 +4470,8 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) unlock = false; } - if (nr_to_scan) { - nr_to_scan -= i915_gem_purge(dev_priv, nr_to_scan); - if (nr_to_scan > 0) - i915_gem_shrink_all(dev_priv); - } + if (nr_to_scan) + i915_gem_shrink(dev_priv, nr_to_scan); cnt = 0; list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) -- 1.7.10.4