All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [RFC 3/4] drm/i915: Return immediately if trylock fails for direct-reclaim
Date: Thu,  3 Jan 2019 12:23:28 +0000	[thread overview]
Message-ID: <20190103122329.19948-4-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20190103122329.19948-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

In an equally named patch Chris Wilson proposes skipping the attempts to
obtain struct_mutex via trylock-looping in order to improve latency for
non-i915 clients. I quote:

"""
Ignore trying to shrink from i915 if we fail to acquire the struct_mutex
in the shrinker while performing direct-reclaim. The trade-off being
(much) lower latency for non-i915 clients at an increased risk of being
unable to obtain a page from direct-reclaim without hitting the
oom-notifier. The proviso being that we still keep trying to hard
obtain the lock for oom so that we can reap under heavy memory pressure.
"""

This version of the patch does strictly what the commit message explains
and leaves other changes out.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem_shrinker.c | 30 ++++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
index 586acf02727e..97deec775f40 100644
--- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
@@ -36,7 +36,8 @@
 #include "i915_drv.h"
 #include "i915_trace.h"
 
-static bool shrinker_lock(struct drm_i915_private *i915, bool *unlock)
+static bool
+shrinker_lock(struct drm_i915_private *i915, unsigned int flags, bool *unlock)
 {
 	switch (mutex_trylock_recursive(&i915->drm.struct_mutex)) {
 	case MUTEX_TRYLOCK_RECURSIVE:
@@ -45,15 +46,17 @@ static bool shrinker_lock(struct drm_i915_private *i915, bool *unlock)
 
 	case MUTEX_TRYLOCK_FAILED:
 		*unlock = false;
-		preempt_disable();
-		do {
-			cpu_relax();
-			if (mutex_trylock(&i915->drm.struct_mutex)) {
-				*unlock = true;
-				break;
-			}
-		} while (!need_resched());
-		preempt_enable();
+		if (flags & I915_SHRINK_ACTIVE) {
+			preempt_disable();
+			do {
+				cpu_relax();
+				if (mutex_trylock(&i915->drm.struct_mutex)) {
+					*unlock = true;
+					break;
+				}
+			} while (!need_resched());
+			preempt_enable();
+		}
 		return *unlock;
 
 	case MUTEX_TRYLOCK_SUCCESS:
@@ -160,7 +163,8 @@ i915_gem_shrink(struct drm_i915_private *i915,
 	unsigned long scanned = 0;
 	bool unlock = false;
 
-	if (!(flags & I915_SHRINK_LOCKED) && !shrinker_lock(i915, &unlock))
+	if (!(flags & I915_SHRINK_LOCKED) &&
+	    !shrinker_lock(i915, flags, &unlock))
 		return 0;
 
 	/*
@@ -359,7 +363,7 @@ i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
 
 	sc->nr_scanned = 0;
 
-	if (!shrinker_lock(i915, &unlock))
+	if (!shrinker_lock(i915, flags, &unlock))
 		return SHRINK_STOP;
 
 	freed = i915_gem_shrink(i915,
@@ -393,7 +397,7 @@ shrinker_lock_uninterruptible(struct drm_i915_private *i915, bool *unlock,
 
 	do {
 		if (i915_gem_wait_for_idle(i915, 0, timeout) == 0 &&
-		    shrinker_lock(i915, unlock))
+		    shrinker_lock(i915, 0, unlock))
 			break;
 
 		schedule_timeout_killable(1);
-- 
2.19.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-01-03 12:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03 12:23 [RFC 0/4] Shrinker tweaks/fixes? Tvrtko Ursulin
2019-01-03 12:23 ` [RFC 1/4] drm/i915: Reduce recursive mutex locking from the shrinker Tvrtko Ursulin
2019-01-03 12:29   ` Chris Wilson
2019-01-03 13:09     ` Tvrtko Ursulin
2019-01-03 12:23 ` [RFC 2/4] drm/i915: Fix timeout handling in i915_gem_shrinker_vmap Tvrtko Ursulin
2019-01-03 12:23 ` Tvrtko Ursulin [this message]
2019-01-03 12:23 ` [RFC 4/4] drm/i915: Remove trylock-looping from the shrinker Tvrtko Ursulin
2019-01-03 12:56   ` Chris Wilson
2019-01-03 13:10     ` Tvrtko Ursulin
2019-01-03 12:45 ` ✗ Fi.CI.CHECKPATCH: warning for Shrinker tweaks/fixes? Patchwork
2019-01-03 12:47 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-01-03 13:06 ` ✓ Fi.CI.BAT: success " Patchwork
2019-01-03 14:54 ` ✗ Fi.CI.IGT: failure " 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=20190103122329.19948-4-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --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 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.