]> git.baikalelectronics.ru Git - kernel.git/commit
drm/msm/gem: Prevent blocking within shrinker loop
authorDmitry Osipenko <dmitry.osipenko@collabora.com>
Fri, 4 Nov 2022 16:04:59 +0000 (19:04 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Mar 2023 12:33:39 +0000 (13:33 +0100)
commit806624dd437984d6df41cdc83e2f7564ea56c568
treee13515bf5594bb8c5d03fab1ea57517082173d9f
parentecb4f71645055bdbff87daa4236d67439ce80c06
drm/msm/gem: Prevent blocking within shrinker loop

[ Upstream commit 941f26794ce3e95a7349f2d3eb9570e712d07f38 ]

Consider this scenario:

1. APP1 continuously creates lots of small GEMs
2. APP2 triggers `drop_caches`
3. Shrinker starts to evict APP1 GEMs, while APP1 produces new purgeable
   GEMs
4. msm_gem_shrinker_scan() returns non-zero number of freed pages
   and causes shrinker to try shrink more
5. msm_gem_shrinker_scan() returns non-zero number of freed pages again,
   goto 4
6. The APP2 is blocked in `drop_caches` until APP1 stops producing
   purgeable GEMs

To prevent this blocking scenario, check number of remaining pages
that GPU shrinker couldn't release due to a GEM locking contention
or shrinking rejection. If there are no remaining pages left to shrink,
then there is no need to free up more pages and shrinker may break out
from the loop.

This problem was found during shrinker/madvise IOCTL testing of
virtio-gpu driver. The MSM driver is affected in the same way.

Reviewed-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Fixes: 04a0d2f95e85 ("drm/msm/gem: Convert to using drm_gem_lru")
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://lore.kernel.org/all/20230108210445.3948344-2-dmitry.osipenko@collabora.com/
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/drm_gem.c
drivers/gpu/drm/msm/msm_gem_shrinker.c
include/drm/drm_gem.h