mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/virtio: expose GEM memory statistics through fdinfo
@ 2026-09-22  9:44 shechenglong
  2026-09-28 13:36 ` [PATCH RESEND] " shechenglong
  0 siblings, 1 reply; 2+ messages in thread
From: shechenglong @ 2026-09-22  9:44 UTC (permalink / raw)
  To: David Airlie, Gerd Hoffmann, Dmitry Osipenko, Thomas Zimmermann
  Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
	Simona Vetter, dri-devel, virtualization, linux-kernel,
	stone.xulei, chenjialong, shechenglong

virtio-gpu does not expose per-client GEM memory usage through DRM
fdinfo, leaving monitoring tools unable to account for buffers owned by a
client.

Wire up the DRM fdinfo helpers and use drm_show_memory_stats() to report
the standard drm-total-memory, drm-shared-memory and drm-active-memory
fields for GEM objects referenced by each DRM file.

Tested on a QEMU/KVM guest with virtio-gpu. After running:

  modetest -M virtio_gpu -s 40:1024x768

the DRM file descriptor of the modetest process shows the following in
/proc/<pid>/fdinfo/<fd>:

  drm-driver:         virtio_gpu
  drm-client-id:      8
  drm-pdev:           0000:00:02.0
  drm-total-memory:   3 MiB
  drm-shared-memory:  3 MiB

Signed-off-by: shechenglong <shechenglong@xfusion.com>
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c
index 2aaa7cb0808..d43d7ddac60 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -323,7 +323,17 @@ MODULE_AUTHOR("Dave Airlie <airlied@redhat.com>");
 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
 MODULE_AUTHOR("Alon Levy");

-DEFINE_DRM_GEM_FOPS(virtio_gpu_driver_fops);
+static void virtio_gpu_show_fdinfo(struct drm_printer *p,
+                                  struct drm_file *file)
+{
+       drm_show_memory_stats(p, file);
+}
+
+static const struct file_operations virtio_gpu_driver_fops = {
+       .owner = THIS_MODULE,
+       DRM_GEM_FOPS,
+       .show_fdinfo = drm_show_fdinfo,
+};

 static const struct drm_driver driver = {
        /*
@@ -347,6 +357,7 @@ static const struct drm_driver driver = {

        .gem_create_object = virtio_gpu_create_object,
        .fops = &virtio_gpu_driver_fops,
+       .show_fdinfo = virtio_gpu_show_fdinfo,

        .ioctls = virtio_gpu_ioctls,
        .num_ioctls = DRM_VIRTIO_NUM_IOCTLS,
--
2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH RESEND] drm/virtio: expose GEM memory statistics through fdinfo
  2026-09-22  9:44 [PATCH] drm/virtio: expose GEM memory statistics through fdinfo shechenglong
@ 2026-09-28 13:36 ` shechenglong
  0 siblings, 0 replies; 2+ messages in thread
From: shechenglong @ 2026-09-28 13:36 UTC (permalink / raw)
  To: David Airlie, Gerd Hoffmann, Dmitry Osipenko, Thomas Zimmermann
  Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
	Simona Vetter, dri-devel, virtualization, linux-kernel,
	stone.xulei, chenjialong, shechenglong

virtio-gpu does not expose per-client GEM memory usage through DRM
fdinfo, leaving monitoring tools unable to account for buffers owned by a
client.

Wire up the DRM fdinfo helpers and use drm_show_memory_stats() to report
the standard drm-total-memory, drm-shared-memory and drm-active-memory
fields for GEM objects referenced by each DRM file.

Tested on a QEMU/KVM guest with virtio-gpu. After running:

  modetest -M virtio_gpu -s 40:1024x768

the DRM file descriptor of the modetest process shows the following in
/proc/<pid>/fdinfo/<fd>:

  drm-driver:         virtio_gpu
  drm-client-id:      8
  drm-pdev:           0000:00:02.0
  drm-total-memory:   3 MiB
  drm-shared-memory:  3 MiB

Signed-off-by: shechenglong <shechenglong@xfusion.com>
Signed-off-by: chenjialong <chenjialong@xfusion.com>
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c
index 2aaa7cb0808..d43d7ddac60 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -323,7 +323,17 @@ MODULE_AUTHOR("Dave Airlie <airlied@redhat.com>");
 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
 MODULE_AUTHOR("Alon Levy");

-DEFINE_DRM_GEM_FOPS(virtio_gpu_driver_fops);
+static void virtio_gpu_show_fdinfo(struct drm_printer *p,
+                                  struct drm_file *file)
+{
+       drm_show_memory_stats(p, file);
+}
+
+static const struct file_operations virtio_gpu_driver_fops = {
+       .owner = THIS_MODULE,
+       DRM_GEM_FOPS,
+       .show_fdinfo = drm_show_fdinfo,
+};

 static const struct drm_driver driver = {
        /*
@@ -347,6 +357,7 @@ static const struct drm_driver driver = {

        .gem_create_object = virtio_gpu_create_object,
        .fops = &virtio_gpu_driver_fops,
+       .show_fdinfo = virtio_gpu_show_fdinfo,

        .ioctls = virtio_gpu_ioctls,
        .num_ioctls = DRM_VIRTIO_NUM_IOCTLS,
--
2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-28 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22  9:44 [PATCH] drm/virtio: expose GEM memory statistics through fdinfo shechenglong
2026-09-28 13:36 ` [PATCH RESEND] " shechenglong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®