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 <[email protected]>
> Signed-off-by: chenjialong <[email protected]>
> ---
>  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 <[email protected]>");
>  MODULE_AUTHOR("Gerd Hoffmann <[email protected]>");
>  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

Reply via email to