mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: shechenglong <shechenglong@xfusion.com>
To: David Airlie <airlied@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	Thomas Zimmermann <tzimmermann@suse.de>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Simona Vetter <simona@ffwll.ch>,
	<dri-devel@lists.freedesktop.org>,
	<virtualization@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<stone.xulei@xfusion.com>, <chenjialong@xfusion.com>,
	shechenglong <shechenglong@xfusion.com>
Subject: [PATCH RESEND] drm/virtio: expose GEM memory statistics through fdinfo
Date: Mon, 28 Sep 2026 21:36:35 +0800	[thread overview]
Message-ID: <20260928133635.1835-1-shechenglong@xfusion.com> (raw)
In-Reply-To: <20260922094455.1799-1-shechenglong@xfusion.com>

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

      reply	other threads:[~2026-09-28 13:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  9:44 [PATCH] " shechenglong
2026-09-28 13:36 ` shechenglong [this message]

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=20260928133635.1835-1-shechenglong@xfusion.com \
    --to=shechenglong@xfusion.com \
    --cc=airlied@redhat.com \
    --cc=chenjialong@xfusion.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=stone.xulei@xfusion.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®