* [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages
@ 2026-07-23 6:46 Hongfu Li
2026-07-23 6:54 ` sashiko-bot
2026-07-23 15:19 ` ✓ i915.CI.BAT: success for " Patchwork
0 siblings, 2 replies; 3+ messages in thread
From: Hongfu Li @ 2026-07-23 6:46 UTC (permalink / raw)
To: jani.nikula, joonas.lahtinen, rodrigo.vivi, tursulin, airlied,
simona, kees, tzimmermann
Cc: intel-gfx, dri-devel, linux-kernel, hongfu.li, Hongfu Li
From: Hongfu Li <lihongfu@kylinos.cn>
Cache the folio with page_folio() at the start of the sg_table loop,
then use folio helpers directly to eliminate repeated compound_head()
lookups inside page API wrappers.
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
index 043095f93ac6..0ae68c52cc12 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
@@ -160,6 +160,7 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
struct sg_table *pages)
{
struct sgt_iter sgt_iter;
struct page *page;
+ struct folio *folio;
if (!pages)
@@ -177,7 +178,9 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
obj->mm.dirty = false;
for_each_sgt_page(page, sgt_iter, pages) {
- if (obj->mm.dirty && trylock_page(page)) {
+ folio = page_folio(page);
+
+ if (obj->mm.dirty && folio_trylock(folio)) {
/*
* As this may not be anonymous memory (e.g. shmem)
* but exist on a real mapping, we have to lock
@@ -193,14 +196,14 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
* on the folio. Such a try_to_unmap() will result
* in us calling put_pages() and so recursively try
* to lock the page. We avoid that deadlock with
- * a trylock_page() and in exchange we risk missing
+ * a folio_trylock() and in exchange we risk missing
* some page dirtying.
*/
- set_page_dirty(page);
- unlock_page(page);
+ folio_mark_dirty(folio);
+ folio_unlock(folio);
}
- mark_page_accessed(page);
+ folio_mark_accessed(folio);
}
obj->mm.dirty = false;
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages
2026-07-23 6:46 [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages Hongfu Li
@ 2026-07-23 6:54 ` sashiko-bot
2026-07-23 15:19 ` ✓ i915.CI.BAT: success for " Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-07-23 6:54 UTC (permalink / raw)
To: Hongfu Li; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unconditional PAGE_SIZE stepping over a scatterlist performs non-idempotent folio operations multiple times for large folios.
--
--- Patch [1]: [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages ---
commit a2440a520ca40b971ab3143efb8ecac51e56d073
Author: Hongfu Li <lihongfu@kylinos.cn>
drm/i915/userptr: Convert page APIs to folio equivalents in put_pages
This commit replaces page-based APIs with folio equivalents in
i915_gem_userptr_put_pages(). It caches the folio at the start of the loop
to avoid repeated compound head lookups inside page API wrappers.
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
> index 043095f93ac60..bd91782f4bbc7 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
[ ... ]
> @@ -177,7 +178,9 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
> obj->mm.dirty = false;
>
> for_each_sgt_page(page, sgt_iter, pages) {
> - if (obj->mm.dirty && trylock_page(page)) {
> + folio = page_folio(page);
> +
> + if (obj->mm.dirty && folio_trylock(folio)) {
[Severity: High]
This isn't a bug introduced by this patch, but does this loop process the same
folio multiple times for large folios?
In i915_gem_userptr_put_pages(), the for_each_sgt_page() macro unconditionally
steps by PAGE_SIZE. This causes page_folio() to repeatedly return the same folio
for the tail pages of a large folio.
For non-idempotent operations, this causes the folio to be processed redundantly.
If the scatterlist is backed by a 2MB THP, the same folio is processed 512
times. This means the code unnecessarily locks and unlocks the folio 512 times,
and folio_mark_accessed() causes the folio to repeatedly toggle between
referenced and active states.
Because large folios bypass per-CPU LRU batches, this hammers the global zone
LRU spinlock repeatedly per THP, causing severe system-wide lock contention.
Could we track the last processed folio to avoid duplicate processing of tail
pages in this loop?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723064651.4100-1-hongfu.li@linux.dev?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* ✓ i915.CI.BAT: success for drm/i915/userptr: Convert page APIs to folio equivalents in put_pages
2026-07-23 6:46 [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages Hongfu Li
2026-07-23 6:54 ` sashiko-bot
@ 2026-07-23 15:19 ` Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: Patchwork @ 2026-07-23 15:19 UTC (permalink / raw)
To: Hongfu Li; +Cc: intel-gfx
[-- Attachment #1: Type: text/plain, Size: 2778 bytes --]
== Series Details ==
Series: drm/i915/userptr: Convert page APIs to folio equivalents in put_pages
URL : https://patchwork.freedesktop.org/series/170999/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_18885 -> Patchwork_170999v1
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/index.html
Participating hosts (41 -> 40)
------------------------------
Additional (1): fi-pnv-d510
Missing (2): bat-dg2-13 fi-snb-2520m
Known issues
------------
Here are the changes found in Patchwork_170999v1 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@fbdev@info:
- fi-pnv-d510: NOTRUN -> [SKIP][1] ([i915#1849])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/fi-pnv-d510/igt@fbdev@info.html
* igt@kms_pipe_crc_basic@nonblocking-crc:
- fi-pnv-d510: NOTRUN -> [SKIP][2] ([i915#11190]) +16 other tests skip
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/fi-pnv-d510/igt@kms_pipe_crc_basic@nonblocking-crc.html
* igt@kms_psr@psr-primary-mmap-gtt:
- fi-pnv-d510: NOTRUN -> [SKIP][3] +31 other tests skip
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/fi-pnv-d510/igt@kms_psr@psr-primary-mmap-gtt.html
#### Possible fixes ####
* igt@i915_selftest@live:
- fi-bsw-nick: [INCOMPLETE][4] -> [PASS][5] +1 other test pass
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18885/fi-bsw-nick/igt@i915_selftest@live.html
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/fi-bsw-nick/igt@i915_selftest@live.html
* igt@kms_flip@basic-flip-vs-wf_vblank:
- fi-bsw-n3050: [DMESG-WARN][6] ([i915#16057]) -> [PASS][7] +1 other test pass
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18885/fi-bsw-n3050/igt@kms_flip@basic-flip-vs-wf_vblank.html
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/fi-bsw-n3050/igt@kms_flip@basic-flip-vs-wf_vblank.html
[i915#11190]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11190
[i915#16057]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16057
[i915#1849]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/1849
Build changes
-------------
* Linux: CI_DRM_18885 -> Patchwork_170999v1
CI-20190529: 20190529
CI_DRM_18885: 2c64192f1ad194a53800f6dd8c779d5b4bbc1831 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_9020: 9020
Patchwork_170999v1: 2c64192f1ad194a53800f6dd8c779d5b4bbc1831 @ git://anongit.freedesktop.org/gfx-ci/linux
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_170999v1/index.html
[-- Attachment #2: Type: text/html, Size: 3502 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-23 15:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 6:46 [PATCH] drm/i915/userptr: Convert page APIs to folio equivalents in put_pages Hongfu Li
2026-07-23 6:54 ` sashiko-bot
2026-07-23 15:19 ` ✓ i915.CI.BAT: success for " Patchwork
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.