* [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; 4+ 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 related [flat|nested] 4+ 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
2026-10-07 21:44 ` Dmitry Osipenko
0 siblings, 1 reply; 4+ 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 related [flat|nested] 4+ messages in thread* Re: [PATCH RESEND] drm/virtio: expose GEM memory statistics through fdinfo
2026-09-28 13:36 ` [PATCH RESEND] " shechenglong
@ 2026-10-07 21:44 ` Dmitry Osipenko
2026-10-08 16:41 ` shechenglong
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Osipenko @ 2026-10-07 21:44 UTC (permalink / raw)
To: shechenglong, David Airlie, Gerd Hoffmann, Thomas Zimmermann
Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Simona Vetter, dri-devel, virtualization, linux-kernel,
stone.xulei, chenjialong
On 9/28/26 16:36, shechenglong wrote:
> 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
Usefulness of this change is dubious. VirtIO-GPU has different types of
RAM, I'd expect them all represented properly instead of only shmem.
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH RESEND] drm/virtio: expose GEM memory statistics through fdinfo
2026-10-07 21:44 ` Dmitry Osipenko
@ 2026-10-08 16:41 ` shechenglong
0 siblings, 0 replies; 4+ messages in thread
From: shechenglong @ 2026-10-08 16:41 UTC (permalink / raw)
To: dmitry.osipenko, airlied, kraxel, tzimmermann
Cc: gurchetansingh, olvaffe, maarten.lankhorst, mripard, simona,
dri-devel, virtualization, linux-kernel, stone.xulei, chenjialong
On Thu, 8 Oct 2026 00:44:34 +0300, Dmitry Osipenko wrote:
> Usefulness of this change is dubious. VirtIO-GPU has different types of
> RAM, I'd expect them all represented properly instead of only shmem.
Hi Dmitry,
Thanks for the review.
Agreed that a generic memory collector does not map well onto
virtio-gpu, given its different memory types. For v2, I plan to
replace it with virtio-gpu-specific accounting and to document the
semantics of each reported value explicitly:
- Guest shmem objects: reported under the "memory" region as
drm-total/drm-shared, based on the guest GEM object size. These
reflect the requested buffer size; drm-resident, if reported, would
be derived from the actual state of the guest backing pages.
- Host-only blobs (VIRTGPU_BLOB_MEM_HOST3D): reported under a separate
region, tentatively "host3d", using the requested blob size. These
values would be documented as logical sizes and not as actual host
RAM or VRAM consumption.
- Mixed blobs (VIRTGPU_BLOB_MEM_HOST3D_GUEST): the guest shadow
backing is accounted under "memory", while the logical blob size is
exposed through a separate, documented supplementary key. This
distinguishes mixed resources from guest-only ones without
presenting the supplementary value as additional measured host
memory.
- Imported dma-bufs: handled explicitly, without assuming that they
are backed by local shmem.
Usage of the host-visible memory region would be reported separately
from the backing statistics and would not be used to infer host
residency.
The actual host allocation size and residency, including legacy virgl
resources and the host part of mixed blobs, are not available through
the existing guest/host interface. Reporting them would require
additional host/renderer support, so I propose leaving that out of
this series unless you consider it a prerequisite.
Does this scope match your expectations for v2? Are there other
memory types or accounting semantics you would like covered?
Best regards,
Chenglong She
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-08 16:59 UTC | newest]
Thread overview: 4+ 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
2026-10-07 21:44 ` Dmitry Osipenko
2026-10-08 16:41 ` shechenglong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox