From: Boris Brezillon <boris.brezillon@collabora.com>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: loic.molinari@collabora.com, willy@infradead.org,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
airlied@gmail.com, simona@ffwll.ch, frank.binns@imgtec.com,
matt.coster@imgtec.com, dri-devel@lists.freedesktop.org,
linux-mm@kvack.org
Subject: Re: [PATCH 2/3] drm/gem-shmem: Track folio accessed/dirty status in mmap
Date: Tue, 27 Jan 2026 16:52:39 +0100 [thread overview]
Message-ID: <20260127165239.78f3dde6@fedora> (raw)
In-Reply-To: <20260127132938.429288-3-tzimmermann@suse.de>
On Tue, 27 Jan 2026 14:16:37 +0100
Thomas Zimmermann <tzimmermann@suse.de> wrote:
> Invoke folio_mark_accessed() in mmap page faults to add the folio to
> the memory manager's LRU list. Userspace invokes mmap to get the memory
> for software rendering. Later compositors will do the same to create the
> final on-screen image, so keeping the pages in LRU makes sense. Avoids
> paging out graphics buffers when under memory pressure.
>
> In page_mkwrite, further invoke the folio_mark_dirty() to add the folio
> for writeback, should the underlying file be paged out from system memory.
> This rarely happens in practice, yet it would corrupt the buffer content.
>
> This has little effect on a system's hardware-accelerated rendering, which
> only mmaps for an initial setup of textures, meshes, shaders, etc.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index b6ddabbfcc52..30cd34d3a111 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -562,8 +562,10 @@ static bool drm_gem_shmem_try_map_pmd(struct vm_fault *vmf, unsigned long addr,
>
> if (folio_test_pmd_mappable(folio)) {
> /* Read-only mapping; split upon write fault */
> - if (vmf_insert_folio_pmd(vmf, folio, false) == VM_FAULT_NOPAGE)
> + if (vmf_insert_folio_pmd(vmf, folio, false) == VM_FAULT_NOPAGE) {
> + folio_mark_accessed(folio);
> return true;
> + }
> }
> }
> #endif
> @@ -605,6 +607,7 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
> get_page(page);
>
> folio_lock(folio);
> + folio_mark_accessed(folio);
>
> vmf->page = page;
> ret = VM_FAULT_LOCKED;
> @@ -653,10 +656,23 @@ static void drm_gem_shmem_vm_close(struct vm_area_struct *vma)
> drm_gem_vm_close(vma);
> }
>
> +static vm_fault_t drm_gem_shmem_page_mkwrite(struct vm_fault *vmf)
> +{
> + struct folio *folio = page_folio(vmf->page);
> +
> + file_update_time(vmf->vma->vm_file);
> +
> + folio_lock(folio);
> + folio_mark_dirty(folio);
> +
> + return VM_FAULT_LOCKED;
> +}
> +
> const struct vm_operations_struct drm_gem_shmem_vm_ops = {
> .fault = drm_gem_shmem_fault,
> .open = drm_gem_shmem_vm_open,
> .close = drm_gem_shmem_vm_close,
> + .page_mkwrite = drm_gem_shmem_page_mkwrite,
> };
> EXPORT_SYMBOL_GPL(drm_gem_shmem_vm_ops);
>
next prev parent reply other threads:[~2026-01-27 15:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 13:16 [PATCH 0/3] drm/gem-shmem: Track page accessed/dirty status Thomas Zimmermann
2026-01-27 13:16 ` [PATCH 1/3] drm/gem-shmem: Map pages in mmap fault handler Thomas Zimmermann
2026-01-27 13:58 ` Matthew Wilcox
2026-01-27 14:51 ` Thomas Zimmermann
2026-01-27 14:45 ` Boris Brezillon
2026-01-27 14:53 ` Thomas Zimmermann
2026-01-27 13:16 ` [PATCH 2/3] drm/gem-shmem: Track folio accessed/dirty status in mmap Thomas Zimmermann
2026-01-27 15:52 ` Boris Brezillon [this message]
2026-01-27 13:16 ` [PATCH 3/3] drm/gem-shmem: Track folio accessed/dirty status in vmap Thomas Zimmermann
2026-01-27 15:56 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260127165239.78f3dde6@fedora \
--to=boris.brezillon@collabora.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=frank.binns@imgtec.com \
--cc=linux-mm@kvack.org \
--cc=loic.molinari@collabora.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matt.coster@imgtec.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox