From patchwork Tue Jun 10 20:16:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 4333071 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 820DA9F314 for ; Wed, 11 Jun 2014 01:45:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A9ADB20204 for ; Wed, 11 Jun 2014 01:45:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0A57E201FE for ; Wed, 11 Jun 2014 01:45:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 84A336E7BA; Tue, 10 Jun 2014 18:45:12 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E3FA6E773 for ; Tue, 10 Jun 2014 13:17:03 -0700 (PDT) Received: from www262.sakura.ne.jp (ksav11.sakura.ne.jp [210.224.165.45]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id s5AKGwUT060552; Wed, 11 Jun 2014 05:16:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) X-Nat-Received: from [202.181.97.72]:55134 [ident-empty] by smtp-proxy.isp with TPROXY id 1402431418.14013 Received: from CLAMP (KD175108057186.ppp-bb.dion.ne.jp [175.108.57.186]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id s5AKGw18060547; Wed, 11 Jun 2014 05:16:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: konrad.wilk@oracle.com Subject: Re: [PATCH 3/5] gpu/drm/ttm: Use mutex_trylock() to avoid deadlock inside shrinker functions. From: Tetsuo Handa References: <20140530160824.GD3621@localhost.localdomain> <201405311158.DGE64002.QLOOHJSFFMVFOt@I-love.SAKURA.ne.jp> <201405311159.CHG64048.SOFLQHVtFOMFJO@I-love.SAKURA.ne.jp> <201405311200.III57894.MLFOOFStQVHJFO@I-love.SAKURA.ne.jp> <20140610191741.GA28523@phenom.dumpdata.com> In-Reply-To: <20140610191741.GA28523@phenom.dumpdata.com> Message-Id: <201406110516.HCH90692.FFFStVJMOHOLQO@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Wed, 11 Jun 2014 05:16:59 +0900 Mime-Version: 1.0 X-Anti-Virus: Kaspersky Anti-Virus for Linux Mail Server 5.6.45.2/RELEASE, bases: 10062014 #8203084, status: clean X-Mailman-Approved-At: Tue, 10 Jun 2014 18:45:11 -0700 Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, glommer@openvz.org, linux-mm@kvack.org, mgorman@suse.de, dchinner@redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Konrad Rzeszutek Wilk wrote: > Hmm.. > > /home/konrad/linux/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c: In function ‘ttm_dma_pool_shrink_scan’: > /home/konrad/linux/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c:1015:2: error: invalid use of void expression > if (!mutex_lock(&_manager->lock)) > > This is based on v3.15 with these patches. Wow! I didn't know that my gcc does not emit warning on such a mistake. Thank you for catching this. ---------- >From 6e6774a87695408ef077cab576e76f7fa2cf4355 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Wed, 11 Jun 2014 05:10:50 +0900 Subject: [PATCH 3/5 (v2)] gpu/drm/ttm: Use mutex_trylock() to avoid deadlock inside shrinker functions. I can observe that RHEL7 environment stalls with 100% CPU usage when a certain type of memory pressure is given. While the shrinker functions are called by shrink_slab() before the OOM killer is triggered, the stall lasts for many minutes. One of reasons of this stall is that ttm_dma_pool_shrink_count()/ttm_dma_pool_shrink_scan() are called and are blocked at mutex_lock(&_manager->lock). GFP_KERNEL allocation with _manager->lock held causes someone (including kswapd) to deadlock when these functions are called due to memory pressure. This patch changes "mutex_lock();" to "if (!mutex_trylock()) return ...;" in order to avoid deadlock. Signed-off-by: Tetsuo Handa Cc: stable [3.3+] Signed-off-by: Tetsuo Handa --- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index d8e59f7..524cc1a 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -1014,7 +1014,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) if (list_empty(&_manager->pools)) return SHRINK_STOP; - mutex_lock(&_manager->lock); + if (!mutex_trylock(&_manager->lock)) + return SHRINK_STOP; if (!_manager->npools) goto out; pool_offset = ++start_pool % _manager->npools; @@ -1047,7 +1048,8 @@ ttm_dma_pool_shrink_count(struct shrinker *shrink, struct shrink_control *sc) struct device_pools *p; unsigned long count = 0; - mutex_lock(&_manager->lock); + if (!mutex_trylock(&_manager->lock)) + return 0; list_for_each_entry(p, &_manager->pools, pools) count += p->pool->npages_free; mutex_unlock(&_manager->lock);