Skip to content

Commit 22e7169

Browse files
Tetsuo Handaairlied
authored andcommitted
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 <penguin-kernel@I-love.SAKURA.ne.jp> Cc: stable <stable@kernel.org> [3.3+] Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 46c2df6 commit 22e7169

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
10141014
if (list_empty(&_manager->pools))
10151015
return SHRINK_STOP;
10161016

1017-
mutex_lock(&_manager->lock);
1017+
if (!mutex_trylock(&_manager->lock))
1018+
return SHRINK_STOP;
10181019
if (!_manager->npools)
10191020
goto out;
10201021
pool_offset = ++start_pool % _manager->npools;
@@ -1047,7 +1048,8 @@ ttm_dma_pool_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
10471048
struct device_pools *p;
10481049
unsigned long count = 0;
10491050

1050-
mutex_lock(&_manager->lock);
1051+
if (!mutex_trylock(&_manager->lock))
1052+
return 0;
10511053
list_for_each_entry(p, &_manager->pools, pools)
10521054
count += p->pool->npages_free;
10531055
mutex_unlock(&_manager->lock);

0 commit comments

Comments
 (0)