[PATCH AUTOSEL 6.18-6.1] drm/gem: Consider GEM object reclaimable if shrinking fails

From: Sasha Levin

Date: Mon Aug 31 2026 - 11:04:21 EST


From: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>

[ Upstream commit 71c8224a18825102ee1e5e70498f96f6c2d2a81d ]

If the object wasn't moved to a different LRU after the shrink callback
returns, it means the buffer is still reclaimable. Update the remaining
counter to reflect that.

v2:
- Collect R-b

v3:
- Collect R-b

v4:
- No changes

v5:
- No changes

v6:
- No changes

v7:
- No changes

Reviewed-by: Liviu Dudau <liviu.dudau@xxxxxxx>
Reviewed-by: Steven Price <steven.price@xxxxxxx>
Link: https://patch.msgid.link/20260401134854.2275433-2-boris.brezillon@xxxxxxxxxxxxx
Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---

LLM Generated explanations, may be completely bogus:

The background `b4 dig` on the original `drm_gem_lru_scan` introduction
commit (`a4871e6201c46`) finished successfully. It matched the Thomas
Zimmermann May 2025 thread:
https://patch.msgid.link/20250520094203.30545-5-tzimmermann@xxxxxxx

That lines up with the earlier finding that the helper and the missing
`*remaining` accounting have been in this tree since `drm_gem.c` landed;
the Boris Brezillon patch is a small, standalone fix on top of that.

For **Linux 6.18.43**, the backport recommendation remains **YES**.

drivers/gpu/drm/drm_gem.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 5c4a113b08941..224ed96bd0d4a 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1601,6 +1601,16 @@ drm_gem_lru_scan(struct drm_gem_lru *lru,
*/
WARN_ON(obj->lru == &still_in_lru);
WARN_ON(obj->lru == lru);
+ } else if (obj->lru == &still_in_lru) {
+ /*
+ * If the object wasn't moved and wasn't shrunk either,
+ * it's still remaining as reclaimable. Note that
+ * obj->lru is supposed to be checked with the LRU lock
+ * held for an accurate result, but we don't care about
+ * accuracy here. Worst thing that could happen is an
+ * extra scan.
+ */
+ *remaining += obj->size >> PAGE_SHIFT;
}

dma_resv_unlock(obj->resv);
--
2.53.0