public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects
@ 2026-04-21 10:45 Nicolas Frattaroli
  2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Nicolas Frattaroli @ 2026-04-21 10:45 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, Boris Brezillon, Steven Price, Liviu Dudau
  Cc: dri-devel, linux-kernel, kernel, Nicolas Frattaroli

Panthor has recently gained a GEM shrinker. It allows evicting memory
that backs unused GEM objects to swap.

In this series, both fdinfo and Panthor's gems debugfs are extended so
that information on evicted pages can be gathered by users through these
two methods.

---
Changes in v2:
- Change reclaimed_count to saturate at INT_MAX
- Add "evictions" column to panthor gems debugfs which prints
  reclaimed_count
- Add a patch to reduce the padding of one panthor gems debugfs column a
  bit
- Link to v1: https://patch.msgid.link/20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com

To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Maxime Ripard <mripard@kernel.org>
To: Thomas Zimmermann <tzimmermann@suse.de>
To: David Airlie <airlied@gmail.com>
To: Simona Vetter <simona@ffwll.ch>
To: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>
To: Liviu Dudau <liviu.dudau@arm.com>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: kernel@collabora.com
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

---
Nicolas Frattaroli (3):
      drm/fdinfo: Add "evicted" memory accounting
      drm/panthor: Implement evicted status for GEM objects
      drm/panthor: Reduce padding in gems debugfs for refcount

 drivers/gpu/drm/drm_file.c            |  8 ++++++++
 drivers/gpu/drm/panthor/panthor_gem.c | 18 ++++++++++++++----
 drivers/gpu/drm/panthor/panthor_gem.h | 10 ++++++++++
 include/drm/drm_file.h                |  2 ++
 include/drm/drm_gem.h                 |  2 ++
 5 files changed, 36 insertions(+), 4 deletions(-)
---
base-commit: 3f9357c30a44734d45e3093c521d52b2aefb09f5
change-id: 20260420-panthor-bo-reclaim-observability-970679c9533c

Best regards,
--  
Nicolas Frattaroli <nicolas.frattaroli@collabora.com>


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

* [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting
  2026-04-21 10:45 [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects Nicolas Frattaroli
@ 2026-04-21 10:45 ` Nicolas Frattaroli
  2026-04-22 10:59   ` Steven Price
  2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
  2026-04-21 10:45 ` [PATCH v2 2/3] drm/panthor: Implement evicted status for GEM objects Nicolas Frattaroli
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Nicolas Frattaroli @ 2026-04-21 10:45 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, Boris Brezillon, Steven Price, Liviu Dudau
  Cc: dri-devel, linux-kernel, kernel, Nicolas Frattaroli

Currently, there's no way to know for certain how much GPU memory was
swapped out. The difference between total and resident memory would
include newly allocated pages, which are not resident, but also aren't
swapped out.

Add a new drm_gem_object_status so drivers can signal when an object has
been evicted to swap, and add a new "evicted" counter to
drm_memory_stats.

Due to how the supported_flags bitmask is determined, the "evicted"
count won't be printed to fdinfo if there's no swapped out pages.

Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
 drivers/gpu/drm/drm_file.c | 8 ++++++++
 include/drm/drm_file.h     | 2 ++
 include/drm/drm_gem.h      | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index ec820686b302..5078172976c0 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -868,6 +868,7 @@ int drm_memory_stats_is_zero(const struct drm_memory_stats *stats)
 		stats->private == 0 &&
 		stats->resident == 0 &&
 		stats->purgeable == 0 &&
+		stats->evicted == 0 &&
 		stats->active == 0);
 }
 EXPORT_SYMBOL(drm_memory_stats_is_zero);
@@ -901,6 +902,10 @@ void drm_print_memory_stats(struct drm_printer *p,
 	if (supported_status & DRM_GEM_OBJECT_PURGEABLE)
 		drm_fdinfo_print_size(p, prefix, "purgeable", region,
 				      stats->purgeable);
+
+	if (supported_status & DRM_GEM_OBJECT_EVICTED)
+		drm_fdinfo_print_size(p, prefix, "evicted", region,
+				      stats->evicted);
 }
 EXPORT_SYMBOL(drm_print_memory_stats);
 
@@ -954,6 +959,9 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)
 
 		if (s & DRM_GEM_OBJECT_PURGEABLE)
 			status.purgeable += add_size;
+
+		if (s & DRM_GEM_OBJECT_EVICTED)
+			status.evicted += add_size;
 	}
 	spin_unlock(&file->table_lock);
 
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 6ee70ad65e1f..213dfecac342 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -500,6 +500,7 @@ void drm_send_event_timestamp_locked(struct drm_device *dev,
  * @resident: Total size of GEM objects backing pages
  * @purgeable: Total size of GEM objects that can be purged (resident and not active)
  * @active: Total size of GEM objects active on one or more engines
+ * @evicted: Total size of GEM objects that have been evicted to swap
  *
  * Used by drm_print_memory_stats()
  */
@@ -509,6 +510,7 @@ struct drm_memory_stats {
 	u64 resident;
 	u64 purgeable;
 	u64 active;
+	u64 evicted;
 };
 
 enum drm_gem_object_status;
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 86f5846154f7..b42ea2e582cf 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -53,6 +53,7 @@ struct drm_gem_object;
  * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
  * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
  * @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission
+ * @DRM_GEM_OBJECT_EVICTED: object is evicted to swap
  *
  * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
  * and drm_show_fdinfo().  Note that an object can report DRM_GEM_OBJECT_PURGEABLE
@@ -67,6 +68,7 @@ enum drm_gem_object_status {
 	DRM_GEM_OBJECT_RESIDENT  = BIT(0),
 	DRM_GEM_OBJECT_PURGEABLE = BIT(1),
 	DRM_GEM_OBJECT_ACTIVE    = BIT(2),
+	DRM_GEM_OBJECT_EVICTED   = BIT(3),
 };
 
 /**

-- 
2.53.0


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

* [PATCH v2 2/3] drm/panthor: Implement evicted status for GEM objects
  2026-04-21 10:45 [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects Nicolas Frattaroli
  2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
@ 2026-04-21 10:45 ` Nicolas Frattaroli
  2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
  2026-04-21 10:45 ` [PATCH v2 3/3] drm/panthor: Reduce padding in gems debugfs for refcount Nicolas Frattaroli
  2026-04-22 22:36 ` Claude review: Let userspace know about swapped out panthor GEM objects Claude Code Review Bot
  3 siblings, 1 reply; 10+ messages in thread
From: Nicolas Frattaroli @ 2026-04-21 10:45 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, Boris Brezillon, Steven Price, Liviu Dudau
  Cc: dri-devel, linux-kernel, kernel, Nicolas Frattaroli

For fdinfo to be able to fill its evicted counter with data, panthor
needs to keep track of whether a GEM object has ever been reclaimed.
Just checking whether the pages are resident isn't enough, as newly
allocated objects also won't be resident.

Do this with a new atomic_t member on panthor_gem_object. It's increased
when an object gets evicted by the shrinker, and saturates at INT_MAX.
This means that once an object has been evicted at least once, its
reclaim counter will never return to 0.

Due to this, it's possible to distinguish evicted non-resident pages
from newly allocated non-resident pages by checking whether
reclaimed_count is != 0

Use this new member to then set the appropriate DRM_GEM_OBJECT_EVICTED
status flag for fdinfo.

Also add a new column and status flag to the panthor gems debugfs: the
column is the number of times an object has been evicted, whereas the
flag indicates whether it currently is evicted.

Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_gem.c | 18 ++++++++++++++----
 drivers/gpu/drm/panthor/panthor_gem.h | 10 ++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 69cef05b6ef7..b6fe20b7e6d0 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -687,6 +687,8 @@ static void panthor_gem_evict_locked(struct panthor_gem_object *bo)
 	if (drm_WARN_ON_ONCE(bo->base.dev, !bo->backing.pages))
 		return;
 
+	atomic_add_unless(&bo->reclaimed_count, 1, INT_MAX);
+
 	panthor_gem_dev_map_cleanup_locked(bo);
 	panthor_gem_backing_cleanup_locked(bo);
 	panthor_gem_update_reclaim_state_locked(bo, NULL);
@@ -788,6 +790,8 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
 
 	if (drm_gem_is_imported(&bo->base) || bo->backing.pages)
 		res |= DRM_GEM_OBJECT_RESIDENT;
+	else if (atomic_read(&bo->reclaimed_count))
+		res |= DRM_GEM_OBJECT_EVICTED;
 
 	return res;
 }
@@ -1595,6 +1599,7 @@ static void panthor_gem_debugfs_print_flag_names(struct seq_file *m)
 	static const char * const gem_state_flags_names[] = {
 		[PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT] = "imported",
 		[PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT] = "exported",
+		[PANTHOR_DEBUGFS_GEM_STATE_EVICTED_BIT] = "evicted",
 	};
 
 	static const char * const gem_usage_flags_names[] = {
@@ -1625,6 +1630,7 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo,
 {
 	enum panthor_gem_reclaim_state reclaim_state = bo->reclaim_state;
 	unsigned int refcount = kref_read(&bo->base.refcount);
+	int reclaimed_count = atomic_read(&bo->reclaimed_count);
 	char creator_info[32] = {};
 	size_t resident_size;
 	u32 gem_usage_flags = bo->debugfs.flags;
@@ -1638,16 +1644,20 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo,
 
 	snprintf(creator_info, sizeof(creator_info),
 		 "%s/%d", bo->debugfs.creator.process_name, bo->debugfs.creator.tgid);
-	seq_printf(m, "%-32s%-16d%-16d%-16zd%-16zd0x%-16lx",
+	seq_printf(m, "%-32s%-16d%-16d%-11d%-16zd%-16zd0x%-16lx",
 		   creator_info,
 		   bo->base.name,
 		   refcount,
+		   reclaimed_count,
 		   bo->base.size,
 		   resident_size,
 		   drm_vma_node_start(&bo->base.vma_node));
 
 	if (drm_gem_is_imported(&bo->base))
 		gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED;
+	else if (!resident_size && reclaimed_count)
+		gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED;
+
 	if (bo->base.dma_buf)
 		gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
 
@@ -1671,8 +1681,8 @@ static void panthor_gem_debugfs_print_bos(struct panthor_device *ptdev,
 
 	panthor_gem_debugfs_print_flag_names(m);
 
-	seq_puts(m, "created-by                      global-name     refcount        size            resident-size   file-offset       state      usage       label\n");
-	seq_puts(m, "----------------------------------------------------------------------------------------------------------------------------------------------\n");
+	seq_puts(m, "created-by                      global-name     refcount        evictions  size            resident-size   file-offset       state      usage       label\n");
+	seq_puts(m, "---------------------------------------------------------------------------------------------------------------------------------------------------------\n");
 
 	scoped_guard(mutex, &ptdev->gems.lock) {
 		list_for_each_entry(bo, &ptdev->gems.node, debugfs.node) {
@@ -1680,7 +1690,7 @@ static void panthor_gem_debugfs_print_bos(struct panthor_device *ptdev,
 		}
 	}
 
-	seq_puts(m, "==============================================================================================================================================\n");
+	seq_puts(m, "=========================================================================================================================================================\n");
 	seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
 		   totals.size, totals.resident, totals.reclaimable);
 }
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index ae0491d0b121..56d63137b4eb 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -19,12 +19,16 @@ struct panthor_vm;
 enum panthor_debugfs_gem_state_flags {
 	PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT = 0,
 	PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT = 1,
+	PANTHOR_DEBUGFS_GEM_STATE_EVICTED_BIT = 2,
 
 	/** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */
 	PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED = BIT(PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT),
 
 	/** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */
 	PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED = BIT(PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT),
+
+	/** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED: GEM BO is evicted to swap. */
+	PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED = BIT(PANTHOR_DEBUGFS_GEM_STATE_EVICTED_BIT),
 };
 
 enum panthor_debugfs_gem_usage_flags {
@@ -172,6 +176,12 @@ struct panthor_gem_object {
 	/** @reclaim_state: Cached reclaim state */
 	enum panthor_gem_reclaim_state reclaim_state;
 
+	/**
+	 * @reclaimed_count: How many times object has been evicted to swap.
+	 * The count saturates at %INT_MAX and will never wrap around to 0.
+	 */
+	atomic_t reclaimed_count;
+
 	/**
 	 * @exclusive_vm_root_gem: Root GEM of the exclusive VM this GEM object
 	 * is attached to.

-- 
2.53.0


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

* [PATCH v2 3/3] drm/panthor: Reduce padding in gems debugfs for refcount
  2026-04-21 10:45 [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects Nicolas Frattaroli
  2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
  2026-04-21 10:45 ` [PATCH v2 2/3] drm/panthor: Implement evicted status for GEM objects Nicolas Frattaroli
@ 2026-04-21 10:45 ` Nicolas Frattaroli
  2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
  2026-04-22 22:36 ` Claude review: Let userspace know about swapped out panthor GEM objects Claude Code Review Bot
  3 siblings, 1 reply; 10+ messages in thread
From: Nicolas Frattaroli @ 2026-04-21 10:45 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, Boris Brezillon, Steven Price, Liviu Dudau
  Cc: dri-devel, linux-kernel, kernel, Nicolas Frattaroli

The "gems" debugfs file is getting a little too wide for comfort. While
a lot of this is unavoidable due to the theoretical upper limits of
numbers here (e.g. size needs to be 16 chars because 2**48-1 in decimal
is 15 digits, plus one space for separation), the refcount column has a
decent 5 characters to be saved, as it can only ever contain a 10-digit
decimal number.

Reduce the refcount column's width to 11, which fulfils this requirement
with an additional space for separation.

Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_gem.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index b6fe20b7e6d0..462a9d2ce319 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -1644,7 +1644,7 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo,
 
 	snprintf(creator_info, sizeof(creator_info),
 		 "%s/%d", bo->debugfs.creator.process_name, bo->debugfs.creator.tgid);
-	seq_printf(m, "%-32s%-16d%-16d%-11d%-16zd%-16zd0x%-16lx",
+	seq_printf(m, "%-32s%-16d%-11d%-11d%-16zd%-16zd0x%-16lx",
 		   creator_info,
 		   bo->base.name,
 		   refcount,
@@ -1681,8 +1681,8 @@ static void panthor_gem_debugfs_print_bos(struct panthor_device *ptdev,
 
 	panthor_gem_debugfs_print_flag_names(m);
 
-	seq_puts(m, "created-by                      global-name     refcount        evictions  size            resident-size   file-offset       state      usage       label\n");
-	seq_puts(m, "---------------------------------------------------------------------------------------------------------------------------------------------------------\n");
+	seq_puts(m, "created-by                      global-name     refcount   evictions  size            resident-size   file-offset       state      usage       label\n");
+	seq_puts(m, "----------------------------------------------------------------------------------------------------------------------------------------------------\n");
 
 	scoped_guard(mutex, &ptdev->gems.lock) {
 		list_for_each_entry(bo, &ptdev->gems.node, debugfs.node) {
@@ -1690,7 +1690,7 @@ static void panthor_gem_debugfs_print_bos(struct panthor_device *ptdev,
 		}
 	}
 
-	seq_puts(m, "=========================================================================================================================================================\n");
+	seq_puts(m, "====================================================================================================================================================\n");
 	seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
 		   totals.size, totals.resident, totals.reclaimable);
 }

-- 
2.53.0


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

* Re: [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting
  2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
@ 2026-04-22 10:59   ` Steven Price
  2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
  1 sibling, 0 replies; 10+ messages in thread
From: Steven Price @ 2026-04-22 10:59 UTC (permalink / raw)
  To: Nicolas Frattaroli, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Boris Brezillon,
	Liviu Dudau
  Cc: dri-devel, linux-kernel, kernel

On 21/04/2026 11:45, Nicolas Frattaroli wrote:
> Currently, there's no way to know for certain how much GPU memory was
> swapped out. The difference between total and resident memory would
> include newly allocated pages, which are not resident, but also aren't
> swapped out.
> 
> Add a new drm_gem_object_status so drivers can signal when an object has
> been evicted to swap, and add a new "evicted" counter to
> drm_memory_stats.
> 
> Due to how the supported_flags bitmask is determined, the "evicted"
> count won't be printed to fdinfo if there's no swapped out pages.
> 
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

You should also update the documentation to include this new field
(Documentation/gpu/drm-usage-stats.rst).

Thanks,
Steve

> ---
>  drivers/gpu/drm/drm_file.c | 8 ++++++++
>  include/drm/drm_file.h     | 2 ++
>  include/drm/drm_gem.h      | 2 ++
>  3 files changed, 12 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index ec820686b302..5078172976c0 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -868,6 +868,7 @@ int drm_memory_stats_is_zero(const struct drm_memory_stats *stats)
>  		stats->private == 0 &&
>  		stats->resident == 0 &&
>  		stats->purgeable == 0 &&
> +		stats->evicted == 0 &&
>  		stats->active == 0);
>  }
>  EXPORT_SYMBOL(drm_memory_stats_is_zero);
> @@ -901,6 +902,10 @@ void drm_print_memory_stats(struct drm_printer *p,
>  	if (supported_status & DRM_GEM_OBJECT_PURGEABLE)
>  		drm_fdinfo_print_size(p, prefix, "purgeable", region,
>  				      stats->purgeable);
> +
> +	if (supported_status & DRM_GEM_OBJECT_EVICTED)
> +		drm_fdinfo_print_size(p, prefix, "evicted", region,
> +				      stats->evicted);
>  }
>  EXPORT_SYMBOL(drm_print_memory_stats);
>  
> @@ -954,6 +959,9 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)
>  
>  		if (s & DRM_GEM_OBJECT_PURGEABLE)
>  			status.purgeable += add_size;
> +
> +		if (s & DRM_GEM_OBJECT_EVICTED)
> +			status.evicted += add_size;
>  	}
>  	spin_unlock(&file->table_lock);
>  
> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
> index 6ee70ad65e1f..213dfecac342 100644
> --- a/include/drm/drm_file.h
> +++ b/include/drm/drm_file.h
> @@ -500,6 +500,7 @@ void drm_send_event_timestamp_locked(struct drm_device *dev,
>   * @resident: Total size of GEM objects backing pages
>   * @purgeable: Total size of GEM objects that can be purged (resident and not active)
>   * @active: Total size of GEM objects active on one or more engines
> + * @evicted: Total size of GEM objects that have been evicted to swap
>   *
>   * Used by drm_print_memory_stats()
>   */
> @@ -509,6 +510,7 @@ struct drm_memory_stats {
>  	u64 resident;
>  	u64 purgeable;
>  	u64 active;
> +	u64 evicted;
>  };
>  
>  enum drm_gem_object_status;
> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index 86f5846154f7..b42ea2e582cf 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -53,6 +53,7 @@ struct drm_gem_object;
>   * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
>   * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
>   * @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission
> + * @DRM_GEM_OBJECT_EVICTED: object is evicted to swap
>   *
>   * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
>   * and drm_show_fdinfo().  Note that an object can report DRM_GEM_OBJECT_PURGEABLE
> @@ -67,6 +68,7 @@ enum drm_gem_object_status {
>  	DRM_GEM_OBJECT_RESIDENT  = BIT(0),
>  	DRM_GEM_OBJECT_PURGEABLE = BIT(1),
>  	DRM_GEM_OBJECT_ACTIVE    = BIT(2),
> +	DRM_GEM_OBJECT_EVICTED   = BIT(3),
>  };
>  
>  /**
> 


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

* Claude review: Let userspace know about swapped out panthor GEM objects
  2026-04-21 10:45 [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects Nicolas Frattaroli
                   ` (2 preceding siblings ...)
  2026-04-21 10:45 ` [PATCH v2 3/3] drm/panthor: Reduce padding in gems debugfs for refcount Nicolas Frattaroli
@ 2026-04-22 22:36 ` Claude Code Review Bot
  3 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 22:36 UTC (permalink / raw)
  To: dri-devel-reviews

Overall Series Review

Subject: Let userspace know about swapped out panthor GEM objects
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Patches: 5
Reviewed: 2026-04-23T08:36:40.531736

---

This is a clean, well-structured 3-patch series that adds eviction observability for panthor GEM objects through both the standardized fdinfo interface and panthor's debugfs. The design is sound: using a saturating atomic counter to distinguish "evicted to swap" from "never yet backed by pages" is the right approach, and the integration with both the core DRM fdinfo framework (patch 1) and panthor's driver-specific debugfs (patch 2) is straightforward.

The main issue is a **missing documentation update**: the new `drm-evicted-<region>` fdinfo key must be documented in `Documentation/gpu/drm-usage-stats.rst`, which defines the standardized userspace-facing interface. Every other memory stat (`total`, `shared`, `resident`, `purgeable`, `active`) is documented there. This is a requirement for any new fdinfo key.

Beyond that, the implementation is correct. The ordering of the atomic increment before page cleanup in the eviction path avoids a race window where an object could appear as neither resident nor evicted. The saturation at `INT_MAX` is appropriate. The core DRM code additions are minimal and consistent with the existing pattern.

---

---
Generated by Claude Code Patch Reviewer

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

* Claude review: drm/fdinfo: Add "evicted" memory accounting
  2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
  2026-04-22 10:59   ` Steven Price
@ 2026-04-22 22:36   ` Claude Code Review Bot
  1 sibling, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 22:36 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

This patch adds `DRM_GEM_OBJECT_EVICTED = BIT(3)` to the status enum, an `evicted` field to `drm_memory_stats`, and wires them into the fdinfo printing/accumulation paths.

**Issue: Missing drm-usage-stats.rst documentation.**
The new `drm-evicted-<region>` key needs an entry in `Documentation/gpu/drm-usage-stats.rst` alongside the existing documented keys. This file explicitly says driver-specific stats "should be documented above and where possible, aligned with other drivers." Since this is being added to the core DRM framework for any driver to use, it's especially important to document the semantics — for example, that evicted is a subset of non-resident memory.

**Minor observation on semantics in `drm_show_memory_stats()`:**
The existing code clears `DRM_GEM_OBJECT_PURGEABLE` when the object is not resident:

```c
if (s & DRM_GEM_OBJECT_RESIDENT) {
    status.resident += add_size;
} else {
    s &= ~DRM_GEM_OBJECT_PURGEABLE;
}
```

The new `DRM_GEM_OBJECT_EVICTED` is accumulated without any filtering. This is correct — evicted objects are by definition not resident, so the semantics are different from purgeable (which is defined as resident + idle + marked). However, the core code doesn't enforce mutual exclusivity between RESIDENT and EVICTED. If a driver were to erroneously return both, both counters would be incremented. This is arguably fine (it's the driver's job to set bits correctly), but a brief comment on the enum doc noting that EVICTED implies non-resident would be helpful.

**Code is correct as written.** The additions to `drm_memory_stats_is_zero()`, `drm_print_memory_stats()`, and `drm_show_memory_stats()` all follow the established pattern.

---
Generated by Claude Code Patch Reviewer

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

* Claude review: drm/panthor: Implement evicted status for GEM objects
  2026-04-21 10:45 ` [PATCH v2 2/3] drm/panthor: Implement evicted status for GEM objects Nicolas Frattaroli
@ 2026-04-22 22:36   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 22:36 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

This is the meat of the series. It adds `atomic_t reclaimed_count` to `panthor_gem_object`, increments it during eviction, and uses it to report status via both fdinfo and debugfs.

**Correctness of the eviction path ordering is good:**
```c
atomic_add_unless(&bo->reclaimed_count, 1, INT_MAX);

panthor_gem_dev_map_cleanup_locked(bo);
panthor_gem_backing_cleanup_locked(bo);
```
The counter is incremented *before* pages are cleared, which avoids a window where a concurrent lockless reader in `panthor_gem_status()` could see the object as neither resident nor evicted. This is the right order.

**The status callback logic is correct:**
```c
if (drm_gem_is_imported(&bo->base) || bo->backing.pages)
    res |= DRM_GEM_OBJECT_RESIDENT;
else if (atomic_read(&bo->reclaimed_count))
    res |= DRM_GEM_OBJECT_EVICTED;
```
The `else if` correctly makes RESIDENT and EVICTED mutually exclusive, and the `reclaimed_count` check distinguishes evicted objects from objects that were never backed. The `atomic_read()` is appropriate here since `panthor_gem_status()` can be called under a spinlock without holding the BO's own lock.

**Debugfs evicted state flag logic:**
```c
if (drm_gem_is_imported(&bo->base))
    gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED;
else if (!resident_size && reclaimed_count)
    gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED;

if (bo->base.dma_buf)
    gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
```
Note that `EVICTED` and `IMPORTED` are mutually exclusive via `else if`, but `EVICTED` and `EXPORTED` are not (an exported BO that gets evicted would show both flags). Is that the desired behavior? An exported BO could conceivably be evicted, so allowing both flags seems reasonable. But the fdinfo path in `panthor_gem_status()` similarly makes EVICTED exclusive with imported — worth confirming this is intentional for imported buffers (which typically have backing managed by the exporter, so they shouldn't get evicted anyway).

**Minor: `int reclaimed_count` local variable.** The `atomic_read()` returns `int`, so the local is correctly typed. However, the debugfs format uses `%-11d` which handles 10-digit signed ints. Since the value saturates at INT_MAX (~2.1 billion, 10 digits), `%-11d` (10 digits + 1 space) is exactly right.

**No initialization needed** — `panthor_gem_object` is allocated via `kzalloc` (through `drm_gem_shmem_create`), so `reclaimed_count` starts at 0 implicitly. Good.

---
Generated by Claude Code Patch Reviewer

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

* Claude review: drm/panthor: Reduce padding in gems debugfs for refcount
  2026-04-21 10:45 ` [PATCH v2 3/3] drm/panthor: Reduce padding in gems debugfs for refcount Nicolas Frattaroli
@ 2026-04-22 22:36   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 22:36 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

Trivial cosmetic patch, reducing refcount column width from `%-16d` to `%-11d`.

The commit message correctly notes that `kref` uses `refcount_t` which is an `unsigned int` backed by `atomic_t`, so the maximum value is a 10-digit number. `%-11d` gives 10 digits plus 1 space for separation. This is correct.

**Ordering note:** This patch correctly depends on patch 2 (it modifies lines introduced by patch 2, including the format string and header lines). The interdependency is handled properly.

No issues with this patch.

---
Generated by Claude Code Patch Reviewer

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

* Claude review: drm/fdinfo: Add "evicted" memory accounting
  2026-04-20 15:46 ` [PATCH 1/2] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
@ 2026-04-22 23:29   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 23:29 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Summary:** Adds `DRM_GEM_OBJECT_EVICTED` (BIT(3)) to `enum drm_gem_object_status`, adds `u64 evicted` to `struct drm_memory_stats`, and wires both into the fdinfo printing and accumulation paths.

**Review:**

The changes correctly follow the established pattern used by `RESIDENT`, `PURGEABLE`, and `ACTIVE`. The new enum value is properly documented with a kdoc comment.

**Issue 1 (minor): The "evicted" accumulation in `drm_show_memory_stats` uses `add_size` unconditionally.**

```c
		if (s & DRM_GEM_OBJECT_EVICTED)
			status.evicted += add_size;
```

This uses `add_size`, which is the RSS size (from `obj->funcs->rss()` if available, otherwise `obj->size`). For an evicted object, `rss()` would typically return 0 since the pages are gone. In the panthor driver (patch 2), evicted objects won't have `DRM_GEM_OBJECT_RESIDENT` set, so they won't have backing pages — meaning `rss()` would return 0 (or not be meaningful).

For evicted objects, the interesting number is the *total* size of the object (how much was evicted to swap), not the RSS. Consider using `obj->size` instead of `add_size`, or document why `add_size` is correct here.

**Issue 2 (minor/doc): The `@DRM_GEM_OBJECT_EVICTED` doc says "object is evicted to swap".**

```c
 * @DRM_GEM_OBJECT_EVICTED: object is evicted to swap
```

The commit message mentions this is about pages being swapped out, but "evicted" in the GPU driver world often means "evicted from VRAM to system memory" (e.g., in TTM-based drivers). The doc comment and the enum value name could potentially be confused with VRAM eviction. Consider whether the description should be more specific, e.g. "object's backing pages have been reclaimed by the shrinker." This is a naming/documentation concern rather than a correctness issue.

**Issue 3 (question): Interaction with existing `RESIDENT`/`PURGEABLE` filtering logic.**

In `drm_show_memory_stats`, when an object is not `RESIDENT`, the code clears `PURGEABLE`:
```c
		if (s & DRM_GEM_OBJECT_RESIDENT) {
			status.resident += add_size;
		} else {
			s &= ~DRM_GEM_OBJECT_PURGEABLE;
		}
```

The new `EVICTED` status is accumulated *after* this block (based on the patch context), which is correct since evicted objects should be non-resident by definition. But there's no explicit mutual exclusivity check — a driver could theoretically return both `RESIDENT` and `EVICTED`, which would be nonsensical. This is not a bug (drivers shouldn't do this), but a comment noting that `EVICTED` is expected to be mutually exclusive with `RESIDENT` would be helpful in the enum documentation.

**Issue 4 (nit): Missing documentation update.**

The `drm_gem_object_status` enum doc block has a long comment about the interaction between `PURGEABLE`, `RESIDENT`, and `ACTIVE`. It would be good to add a similar note about `EVICTED` — specifically that it should only be set for non-resident objects whose pages were previously allocated and then reclaimed, and that it is mutually exclusive with `RESIDENT`.

**Positive:** The `drm_memory_stats_is_zero` check is correctly updated, and the printing order (after purgeable) is reasonable.

---

---
Generated by Claude Code Patch Reviewer

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

end of thread, other threads:[~2026-04-22 23:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 10:45 [PATCH v2 0/3] Let userspace know about swapped out panthor GEM objects Nicolas Frattaroli
2026-04-21 10:45 ` [PATCH v2 1/3] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
2026-04-22 10:59   ` Steven Price
2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
2026-04-21 10:45 ` [PATCH v2 2/3] drm/panthor: Implement evicted status for GEM objects Nicolas Frattaroli
2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
2026-04-21 10:45 ` [PATCH v2 3/3] drm/panthor: Reduce padding in gems debugfs for refcount Nicolas Frattaroli
2026-04-22 22:36   ` Claude review: " Claude Code Review Bot
2026-04-22 22:36 ` Claude review: Let userspace know about swapped out panthor GEM objects Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-04-20 15:46 [PATCH 0/2] " Nicolas Frattaroli
2026-04-20 15:46 ` [PATCH 1/2] drm/fdinfo: Add "evicted" memory accounting Nicolas Frattaroli
2026-04-22 23:29   ` Claude review: " Claude Code Review Bot

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