From nobody Tue Jun 16 19:36:41 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558AD341ADF for ; Mon, 20 Apr 2026 15:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700063; cv=pass; b=TzzHJ4KR7pDdl4Df0V3NA43cSyUz8H8YwA+P+2O0o2fZBCz6+MV5iiaN9tTJ0C8JeujcKtrRlhv+rBfVkbrdbXtbCrwPQJRuj7StH5dTAQq3EB573pfeuXeWCOP+Ku0cP2Yr1YLtqFMESXjCHKA9KZxWS+Ur8Cu+BBglAFK+Pmc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700063; c=relaxed/simple; bh=MbN8PXfYR9yX04y/hkDV7WMxfIZwYPuFh3iZ2FThZJk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KGSVXqbUB/7lSemj9lQibxkNe+5Av+XaaPgzlJ86CqDY9IDGAcKo2IVvDjVvgGgY3/Q/BauKHtJRPdv9BQwk9YNcoxqYV9VZACQ+Sib8/FfGw2GoHiqJoktHCRNkIU37Tj/1RjmSs0QOzahsfmpGvbOQdtTL5LcBPJ1W66Gtwy0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=Lzj7sJyt; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="Lzj7sJyt" ARC-Seal: i=1; a=rsa-sha256; t=1776700047; cv=none; d=zohomail.com; s=zohoarc; b=SSOsJ1d6ae8xIQTXoUr+POzORLusMW4b6+EAGL1nQEXdjKkk+OdERv6/Ta5RHx0J2KqKU10TwpyBF/qbbvacmSG7FfzZLfCyD8zUIucm3Z3DEY7uMAWhnrzYSskWM4FVBuhftIYEx3QflnZ1VUG7Sgnw/AJCDkOF+U/3sGpA9PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776700047; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=MqNz68fIchot62Kb5x/KPq5UFBE2Y0IMEav67Kx8nVI=; b=DEitEI8HoGLp0QfrquJqWIHJKmDi9hqpz6BJ2diDlglu/vtdcS2QnuGixc50VJP55S0bYOQ6P2oIVigGWshsMf1zDfmTiNiKfyCuRjZ4foM+c5I0dBM3QU75SWohhu5Bkrg2h+ouMLt+Q7GFXs5jytLOCTR2/anQMbMP+8p3L+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1776700047; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=MqNz68fIchot62Kb5x/KPq5UFBE2Y0IMEav67Kx8nVI=; b=Lzj7sJytUV74DHCvhEAY1J3xPo6apspYbViqNftpQ5asHgCrTcg+zYBHRxKhq6hb DMwf2ilf+C4DC4QAm1TL0wYxNAxfO4JXE0dZuKQZqBnempqzzV8YwcQ5SooS04r5Uv9 fSM/f8GSuLZ95TcnWb63Ln+B1Zrv3Wtlg67O3j3E= Received: by mx.zohomail.com with SMTPS id 1776700044898157.4547424113332; Mon, 20 Apr 2026 08:47:24 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 20 Apr 2026 17:46:59 +0200 Subject: [PATCH 1/2] drm/fdinfo: Add "evicted" memory accounting Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-panthor-bo-reclaim-observability-v1-1-a4d1a36ee84f@collabora.com> References: <20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com> In-Reply-To: <20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Boris Brezillon , Steven Price , Liviu Dudau Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Nicolas Frattaroli X-Mailer: b4 0.15.2 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 --- 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_st= ats *stats) stats->private =3D=3D 0 && stats->resident =3D=3D 0 && stats->purgeable =3D=3D 0 && + stats->evicted =3D=3D 0 && stats->active =3D=3D 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); =20 @@ -954,6 +959,9 @@ void drm_show_memory_stats(struct drm_printer *p, struc= t drm_file *file) =20 if (s & DRM_GEM_OBJECT_PURGEABLE) status.purgeable +=3D add_size; + + if (s & DRM_GEM_OBJECT_EVICTED) + status.evicted +=3D add_size; } spin_unlock(&file->table_lock); =20 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; }; =20 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 unpinne= d) * @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_fun= cs.status * and drm_show_fdinfo(). Note that an object can report DRM_GEM_OBJECT_P= URGEABLE @@ -67,6 +68,7 @@ enum drm_gem_object_status { DRM_GEM_OBJECT_RESIDENT =3D BIT(0), DRM_GEM_OBJECT_PURGEABLE =3D BIT(1), DRM_GEM_OBJECT_ACTIVE =3D BIT(2), + DRM_GEM_OBJECT_EVICTED =3D BIT(3), }; =20 /** --=20 2.53.0 From nobody Tue Jun 16 19:36:41 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC2533A70A for ; Mon, 20 Apr 2026 15:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700068; cv=pass; b=HMLXgAJl8hxCHbU9Eu5plMOgPYCx/kCnEp3vzT0FQPZJZaxSDxPiV8KBCY7A9/BvERiEz7s+eHoQWGSwz7zBSai25BET+bRSPSDI852a7sZDHq4p2mcOdy/Li4fhGnPPFjouWf1XxMnHe39+9cr2vY77c+myKPjUk6oxr7I4rM4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700068; c=relaxed/simple; bh=iWbln0kb6MAnDVy7RYe3SxgnEdkyLVqAYyYV6kFfh+4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NfhrZfFlKWmjHglnIjDmksn+RSL0j/mKdYaonTgBp3wCHlGVKljZScHAnnbUmW7UiDAk5Re52QGax78AGQZvGLM5DGNOvqOnPqyo1ZLWu+NrkCauIZBlzZOoJZi7SscfltxVCo42GkUFKrYGxkV9diDIiDCFlIhijicJK+BNGmg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=Uu4t6lAt; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="Uu4t6lAt" ARC-Seal: i=1; a=rsa-sha256; t=1776700049; cv=none; d=zohomail.com; s=zohoarc; b=MZlgf72qDO1sFAnt+UMlfn85QcalahqCYTr9vT40uSPEcT191yN3yT4Av8C+w57Zq0UX98SxMP7WTsR+mU7nfcI5HvcV3aKPt2uZOgapCh6qo26VulDyY9sy4KRcYn978XpgxsBC1B3oVYKQFEzGys3hCUFYLuGgOf1K3C/jIhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776700049; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=xQpRGvw6MVSzQc3l2J0bETsoimh+LbDNTxaGkXZ6Cow=; b=R8aPGEZ3YwuH8lWLNFD7rqnJC+f5cWnfmvNhM/LWcmdyqtw7lYATPV+848nxw8lIvDMSdiO/nPdRyWNeMpMQ17lZMwoTd5kR6mu/7bfGb+BC4mUGPDSRy6YuH8kMKigUJI62JyM1qEvZ3w5kN6ShmOHNpDEnwBU0WymyOTVvJG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1776700049; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=xQpRGvw6MVSzQc3l2J0bETsoimh+LbDNTxaGkXZ6Cow=; b=Uu4t6lAtvypDVcn1eEL2yMFxGTa/pTemM3syGT7N85PZ9+8E45F9OA376a+8GITq 5JtLtbIdGapS0OA0ZQgYy6YDcaw3sqJTWZ+0eD9gYXcxaRX1hjx05T3KcTZW5Fyvdb1 zDFfOzn2qEI/m2uLtWRq+GZnvIk0PGUusCK45uRs= Received: by mx.zohomail.com with SMTPS id 1776700047497556.3638450179424; Mon, 20 Apr 2026 08:47:27 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 20 Apr 2026 17:47:00 +0200 Subject: [PATCH 2/2] drm/panthor: Implement evicted status for GEM objects Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-panthor-bo-reclaim-observability-v1-2-a4d1a36ee84f@collabora.com> References: <20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com> In-Reply-To: <20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Boris Brezillon , Steven Price , Liviu Dudau Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Nicolas Frattaroli X-Mailer: b4 0.15.2 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. While it's allowed to wrap around to below zero and assume a value less than a previous observed value, the reclaim counter will never return to 0 for any particular object once it's been reclaimed at least once. Use this new member to then set the appropriate DRM_GEM_OBJECT_EVICTED status flag for fdinfo, and use it in the gems debugfs. It's possible to distinguish evicted non-resident pages from newly allocated non-resident pages by checking whether reclaimed_count is !=3D 0. Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/panthor/panthor_gem.c | 10 ++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/pantho= r/panthor_gem.c index 69cef05b6ef7..4b761b39565d 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -687,6 +687,10 @@ static void panthor_gem_evict_locked(struct panthor_ge= m_object *bo) if (drm_WARN_ON_ONCE(bo->base.dev, !bo->backing.pages)) return; =20 + /* Don't ever wrap around as far as 0, jump from INT_MIN to 1 */ + if (!atomic_inc_unless_negative(&bo->reclaimed_count)) + atomic_set(&bo->reclaimed_count, 1); + panthor_gem_dev_map_cleanup_locked(bo); panthor_gem_backing_cleanup_locked(bo); panthor_gem_update_reclaim_state_locked(bo, NULL); @@ -788,6 +792,8 @@ static enum drm_gem_object_status panthor_gem_status(st= ruct drm_gem_object *obj) =20 if (drm_gem_is_imported(&bo->base) || bo->backing.pages) res |=3D DRM_GEM_OBJECT_RESIDENT; + else if (atomic_read(&bo->reclaimed_count)) + res |=3D DRM_GEM_OBJECT_EVICTED; =20 return res; } @@ -1595,6 +1601,7 @@ static void panthor_gem_debugfs_print_flag_names(stru= ct seq_file *m) static const char * const gem_state_flags_names[] =3D { [PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT] =3D "imported", [PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT] =3D "exported", + [PANTHOR_DEBUGFS_GEM_STATE_EVICTED_BIT] =3D "evicted", }; =20 static const char * const gem_usage_flags_names[] =3D { @@ -1648,6 +1655,9 @@ static void panthor_gem_debugfs_bo_print(struct panth= or_gem_object *bo, =20 if (drm_gem_is_imported(&bo->base)) gem_state_flags |=3D PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED; + else if (!resident_size && atomic_read(&bo->reclaimed_count)) + gem_state_flags |=3D PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED; + if (bo->base.dma_buf) gem_state_flags |=3D PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED; =20 diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/pantho= r/panthor_gem.h index ae0491d0b121..1ab573f03330 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 =3D 0, PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT =3D 1, + PANTHOR_DEBUGFS_GEM_STATE_EVICTED_BIT =3D 2, =20 /** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */ PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED =3D BIT(PANTHOR_DEBUGFS_GEM_STATE= _IMPORTED_BIT), =20 /** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */ PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED =3D 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 =3D BIT(PANTHOR_DEBUGFS_GEM_STATE_= EVICTED_BIT), }; =20 enum panthor_debugfs_gem_usage_flags { @@ -172,6 +176,13 @@ struct panthor_gem_object { /** @reclaim_state: Cached reclaim state */ enum panthor_gem_reclaim_state reclaim_state; =20 + /** + * @reclaimed_count: How many times object has been evicted to swap. + * Never returns to 0 once incremented even on wrap-around, but may + * become < 0 and < the previous value if wrap-around occurs. + */ + atomic_t reclaimed_count; + /** * @exclusive_vm_root_gem: Root GEM of the exclusive VM this GEM object * is attached to. --=20 2.53.0