From patchwork Wed Oct 10 11:07:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 1572941 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 7649E40135 for ; Wed, 10 Oct 2012 11:08:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 573219F6A5 for ; Wed, 10 Oct 2012 04:08:05 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (smtp.fireflyinternet.com [109.228.6.236]) by gabe.freedesktop.org (Postfix) with ESMTP id 16CC69F6A5 for ; Wed, 10 Oct 2012 04:07:54 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.73.22; Received: from arrandale.alporthouse.com (unverified [78.156.73.22]) by fireflyinternet.com (Firefly Internet SMTP) with ESMTP id 123839247-1500050 for multiple; Wed, 10 Oct 2012 12:07:46 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 10 Oct 2012 12:07:30 +0100 Message-Id: <1349867250-22808-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.7.10.4 X-Originating-IP: 78.156.73.22 Subject: [Intel-gfx] [PATCH] drm/i915: Wait for the mutex whilst the reaper runs X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org If the system is forced to start kswapd to recover pages, the system is very starved. Fortunately, kswapd is its own process context and can wait for the mutex. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index ff2ea2b..7108493 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4600,8 +4600,16 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) int nr_to_scan = sc->nr_to_scan; int cnt; - if (!mutex_trylock(&dev->struct_mutex)) - return 0; + /* Force reaping when kswapd runs and the system is starved of + * free pages, Otherwise only opportunistically shrink our caches, + * being wary of deadlocks. + */ + if (current_is_kswapd()) { + mutex_lock(&dev->struct_mutex); + } else { + if (!mutex_trylock(&dev->struct_mutex)) + return 0; + } if (nr_to_scan) { nr_to_scan -= i915_gem_purge(dev_priv, nr_to_scan);