drm/i915: unlock shmem folios after skipped writeback
Subsystems (4)
PATCH 1/1 drm/i915: unlock shmem folios after skipped writeback
writeback_iter() returns a locked folio. The mapped-folio path redirties the folio without unlocking it, so shrinking can leave the folio locked indefinitely.
shmem_write_folio() can also return AOP_WRITEPAGE_ACTIVATE with the folio locked. Passing that positive control value back to writeback_iter() triggers its warning, stops asynchronous writeback, and leaves the folio locked. This can occur when zswap rejects a folio while memcg zswap writeback is disabled.
Unlock folios on both paths and consume AOP_WRITEPAGE_ACTIVATE so the best-effort writeback scan can continue.
--- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +8 -2
@@ -322,10 +322,16 @@ void __shmem_writeback(size_t size, struct address_space *mapping)* as normal. */ while ((folio =writeback_iter (mapping, &wbc, folio, &error))) { -if (folio_mapped (folio)) +if (folio_mapped (folio)) {folio_redirty_for_writepage (&wbc, folio); -else +folio_unlock (folio); + }else { error =shmem_write_folio (folio); +if (error ==AOP_WRITEPAGE_ACTIVATE ) { +folio_unlock (folio); + error =0 ; + } + } } }
base-commit: cbd3dafc2003db679ccd2f6c6a2551db79657049
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] __shmem_writeback() limits writeback to SWAP_CLUSTER_MAX (32) pages, ignoring the requested size, which causes the shrinker to severely under-reclaim memory while reporting full reclaim success. --
commit bda67bb2ffdd195685542c6f27e5b602b16ff109
Author: Matthias Goergens <[email protected]>
drm/i915: unlock shmem folios after skipped writeback
This commit fixes an issue where shmem folios are left locked indefinitely when writeback is skipped. It unlocks folios when they are redirtied or when shmem_write_folio returns AOP_WRITEPAGE_ACTIVATE.
drivers/gpu/drm/i915/gem/i915_gem_shmem.c void __shmem_writeback(size_t size, struct address_space *mapping) · line 324
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-0@@ -322,10 +322,16 @@ void __shmem_writeback(size_t size, struct address_space *mapping)* as normal. */ while ((folio =writeback_iter (mapping, &wbc, folio, &error))) {
[Severity: High]
This isn't a bug introduced by this patch, but does the hardcoded limit on wbc.nr_to_write here cause the shrinker to severely under-reclaim?
In drivers/gpu/drm/i915/gem/i915_gem_shmem.c:__shmem_writeback(), the size parameter is completely ignored and the writeback_control is initialized earlier in the function with:
struct writeback_control wbc = {
.sync_mode = WB_SYNC_NONE,
.nr_to_write = SWAP_CLUSTER_MAX,
...
};Because of this, writeback_iter() will terminate after 32 pages (128KB). However, when the system is under memory pressure and i915_gem_shrinker_scan() delegates to i915_gem_shrink(), try_to_writeback() eventually reaches __shmem_writeback().
i915_gem_shrink() assumes the entire object was successfully written back and increments its freed count by the full object size. If the object is large, the mm subsystem is misled into thinking massive amounts of memory were freed when only 128KB actually was. This could degrade memory reclaim under pressure and lead to system stalls or OOMs.
Should the writeback limit respect the requested size parameter instead of being hardcoded to SWAP_CLUSTER_MAX?
Quoted 14 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +8
-2-if (folio_mapped (folio)) +if (folio_mapped (folio)) {folio_redirty_for_writepage (&wbc, folio); -else +folio_unlock (folio); + }else { error =shmem_write_folio (folio); +if (error ==AOP_WRITEPAGE_ACTIVATE ) { +folio_unlock (folio); + error =0 ; + } + } } }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Yes, the budget should use the supplied object size. The current limit is a separate regression from776a853a43c9 ("i915: Use writeback_iter()"). The old loop walked size >> PAGE_SHIFT pages; the iterator now honours the pre-existing SWAP_CLUSTER_MAX budget, leaving size unused.
The reclaim-accounting consequence needs some qualification, though. Before optional writeback, i915 drops its references to the whole object's pages and clears mapping unevictability. The remaining pages can be reclaimed by the MM. The shrinker also counts the object when writeback isn't requested, so that count doesn't mean every page reached swap.
I have sent a separate patch [1], "drm/i915: size shmem writeback budget to the object", using an object-sized nr_to_write budget to restore the previous writeback scope. It remains best-effort.
I have not measured the effect of the current limit on reclaim latency or OOM.
Patchwork
CI✗ LGCI.VerificationFailed: failure for drm/i915: unlock shmem folios after skipped writeback
In reply to Matthias Goergens== Series Details ==
== Series Details ==
Series: drm/i915: unlock shmem folios after skipped writeback
URL : https://patchwork.freedesktop.org/series/174153/
State : failure
== Summary ==
Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/187569/ (on built-in)
A gentle ping on this fix. CI appears to have stopped because my address isn't on the allowlist; could a project owner trigger a retest?
https://patchwork.freedesktop.org/series/174153/
I'd also appreciate review when someone has a chance.
Thanks,
Matthias