dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/2] DRM standardized memory stats
@ 2026-09-17 12:04 Tvrtko Ursulin
  2026-09-17 12:04 ` [RFC 1/2] drm: Allow drivers to report " Tvrtko Ursulin
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Tvrtko Ursulin @ 2026-09-17 12:04 UTC (permalink / raw)
  To: amd-gfx, dri-devel
  Cc: kernel-dev, Tvrtko Ursulin, Maíra Canal, Ludovico de Nittis,
	Alex Deucher, Christian König, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter

Re-floating a simple idea (this time with more Cc) born from an user interest to
be able to correctly size the swap space during OS installation, based on the
size of the VRAM a discrete GPU might have. And to be able to do it in a vendor
agnostic way.

Idea is to expose a standardized scheme in sysfs, under the DRM class card, and
under a new 'memstat' directory. Such as, example from amdgpu:

/sys/class/drm/card1/memstat/
├── gtt
│   ├── total_mb
│   └── used_mb
└── vram
    ├── total_mb
    └── used_mb

Or with concrete numbers:

$ grep -Hr . /sys/class/drm/card1/memstat/
/sys/class/drm/card1/memstat/vram/total_mb:1024
/sys/class/drm/card1/memstat/vram/used_mb:445
/sys/class/drm/card1/memstat/gtt/total_mb:7394
/sys/class/drm/card1/memstat/gtt/used_mb:71

Drivers need to implement a simple DRM driver level callback which needs to
report a stable list of interesting memory regions and their respective stats.
The region names then become sub-directory names under the new 'memstat'
directory, with each region exposing the total size and the current usage.

Similar data can already be queried if the dmem cgroup controller is enabled,
also only for the participating drivers, by querying the root cgroup. But
perhaps sysfs is easier, or perhaps it is too much code for too little benefit.
I am curious to hear any opinions.

Cc: Maíra Canal <mcanal@igalia.com>
Cc: Ludovico de Nittis <ludovico.denittis@collabora.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>

Tvrtko Ursulin (2):
  drm: Allow drivers to report standardized memory stats
  drm/amdgpu: Wire up DRM memory stats reporting

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c |  40 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  37 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h    |   3 +
 drivers/gpu/drm/drm_drv.c                  |  10 ++
 drivers/gpu/drm/drm_sysfs.c                | 123 +++++++++++++++++++++
 include/drm/drm_device.h                   |  19 ++++
 include/drm/drm_drv.h                      |   8 ++
 include/drm/drm_file.h                     |   9 ++
 include/drm/drm_sysfs.h                    |   4 +
 11 files changed, 248 insertions(+), 13 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [RFC 0/2] DRM standardized memory stats
@ 2026-04-29 13:06 Tvrtko Ursulin
  2026-04-29 13:06 ` [RFC 1/2] drm: Allow drivers to report " Tvrtko Ursulin
  0 siblings, 1 reply; 10+ messages in thread
From: Tvrtko Ursulin @ 2026-04-29 13:06 UTC (permalink / raw)
  To: amd-gfx, dri-devel; +Cc: kernel-dev, Tvrtko Ursulin

Floating a simple idea born from an user interest to be able to correctly size
the swap space during OS installation, based on the size of the VRAM a discrete
GPU might have. And to be able to do it in a vendor agnostic way.

Idea is to expose a standardized scheme in sysfs, under the DRM class card, and
under a new 'memstat' directory. Such as, example from amdgpu:

/sys/class/drm/card1/memstat/
├── gtt
│   ├── total_mb
│   └── used_mb
└── vram
    ├── total_mb
    └── used_mb

Or with concrete numbers:

$ grep -Hr . /sys/class/drm/card1/memstat/
/sys/class/drm/card1/memstat/vram/total_mb:1024
/sys/class/drm/card1/memstat/vram/used_mb:445
/sys/class/drm/card1/memstat/gtt/total_mb:7394
/sys/class/drm/card1/memstat/gtt/used_mb:71

Drivers need to implement a simple DRM driver level callback which needs to
report a stable list of interesting memory regions and their respective stats.
The region names then become sub-directory names under the new 'memstat'
directory, with each region exposing the total size and the current usage.

Similar data can already be queried if the dmem cgroup controller is enabled,
also only for the participating drivers, by querying the root cgroup. But
perhaps sysfs is easier, or perhaps it is too much code for too little benefit.
I am curious to hear any opinions.

Tvrtko Ursulin (2):
  drm: Allow drivers to report standardized memory stats
  drm/amdgpu: Wire up DRM memory stats reporting

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c |  40 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  37 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h    |   3 +
 drivers/gpu/drm/drm_drv.c                  |  10 ++
 drivers/gpu/drm/drm_sysfs.c                | 123 +++++++++++++++++++++
 include/drm/drm_device.h                   |  19 ++++
 include/drm/drm_drv.h                      |   8 ++
 include/drm/drm_file.h                     |   9 ++
 include/drm/drm_sysfs.h                    |   4 +
 11 files changed, 248 insertions(+), 13 deletions(-)

-- 
2.52.0


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

end of thread, other threads:[~2026-10-03  8:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 12:04 [RFC 0/2] DRM standardized memory stats Tvrtko Ursulin
2026-09-17 12:04 ` [RFC 1/2] drm: Allow drivers to report " Tvrtko Ursulin
2026-09-17 12:14   ` sashiko-bot
2026-09-17 12:38   ` Thomas Zimmermann
2026-09-18  7:44     ` Tvrtko Ursulin
2026-09-17 12:04 ` [RFC 2/2] drm/amdgpu: Wire up DRM memory stats reporting Tvrtko Ursulin
2026-09-17 12:15   ` sashiko-bot
2026-09-21  9:19 ` [RFC 0/2] DRM standardized memory stats Christian König
2026-10-03  8:36   ` Tvrtko Ursulin
  -- strict thread matches above, loose matches on Subject: below --
2026-04-29 13:06 Tvrtko Ursulin
2026-04-29 13:06 ` [RFC 1/2] drm: Allow drivers to report " Tvrtko Ursulin

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