From mboxrd@z Thu Jan 1 00:00:00 1970 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 2EBED37EFED for ; Mon, 20 Apr 2026 17:47:20 +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=1776707241; cv=pass; b=QjfcNE4HY011bVfdhQ736RsDQb+IFlhrcYaq1i9IbK4QNS67Ice6IifRJp5J1hMPGzAeOZpYRDS8SOHeqr8quEmz0LXaXFfH8ISJQXAlT+E19Lxiwj6ZShPzmojfQwQWkhSkStFBEKRvq/USvZ3/ZdOttnrefuJM2fWz8kfzOUU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776707241; c=relaxed/simple; bh=ULLdlk7FTF/F1pgXKT/YZDL8Q+6FU1IT+Xs188my/8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SlUKx7efq7r+igWfneH+8dYMZFEZmDCsBx0vvwBG0NuHGisaYqhbS9XDw5QFL3rtSyP1Xqn+lFwenA22eerp7aOkdnuwwkakh/qw9GtpN3BkVrLo2h7VaEYje7qu/L0ObkflyMj9k15QV15KTzI8326+XN3bdooKd1rZN4kM6kY= 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=YS6+dYWw; 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="YS6+dYWw" ARC-Seal: i=1; a=rsa-sha256; t=1776707219; cv=none; d=zohomail.com; s=zohoarc; b=S++YgEaKjfXsPkIugzZV4hAO5yFqJ016OT+dPIdVNlQFkhn5snsei9HZygvenGiUBraUDkFGapRT2dV0SJ6H4L0SvArsNsCXcEOs2rdQC1+qgV8SEba8WQ3vRIbYAQ+JPtkLhJwpJf7/M6/u+fBFVkbXl2d1jlkpNjxYO5DjJSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776707219; 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=bm4FcGGu07nytUNI2kz1JShR0m/TlWoqE/3LBgeTZk4=; b=DrhXehMpF8Ca+jiKuUYJTLNdz8DanpUEdG8devJDa4TqZAqCC18FXxz8twBDsp3QgVWGppssLOiWgdoPXIPQDKBlzcYtzm3e/ex0Rqblnpjb9c7fAwBTe2XuHOFLm126G1ZjcEshZvYYhLW3Rgzx94iJfN8Zak1xVKFH4R+zbxE= 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=1776707219; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=bm4FcGGu07nytUNI2kz1JShR0m/TlWoqE/3LBgeTZk4=; b=YS6+dYWwq30ljBNnXA1uI3bVkP/uXk2Iu/cmRMdUJe8hZNj5p+l9nsNwnaz2twWa sTkE1UmB0GswuZma1+cVZxYqtV4OqWBhjK2YIYdDSfYFgV5hnk0rKqBYRoiuG6do0sN 0RukogpIOP/quGGWGXzLDyy4Izajd0Y4pYIwf2Pk= Received: by mx.zohomail.com with SMTPS id 1776707217181988.3795012862995; Mon, 20 Apr 2026 10:46:57 -0700 (PDT) From: Nicolas Frattaroli To: Boris Brezillon Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Steven Price , Liviu Dudau , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: Re: [PATCH 2/2] drm/panthor: Implement evicted status for GEM objects Date: Mon, 20 Apr 2026 19:46:52 +0200 Message-ID: In-Reply-To: <20260420181735.2990999e@fedora> References: <20260420-panthor-bo-reclaim-observability-v1-0-a4d1a36ee84f@collabora.com> <20260420-panthor-bo-reclaim-observability-v1-2-a4d1a36ee84f@collabora.com> <20260420181735.2990999e@fedora> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" On Monday, 20 April 2026 18:17:35 Central European Summer Time Boris Brezillon wrote: > On Mon, 20 Apr 2026 17:47:00 +0200 > Nicolas Frattaroli wrote: > > > 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 != 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/panthor/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_gem_object *bo) > > if (drm_WARN_ON_ONCE(bo->base.dev, !bo->backing.pages)) > > return; > > > > + /* 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); > > Can't we just go > > atomic_add_unless(&bo->reclaimed_count, 1, INT_MAX); > > here, to handle the INT_MAX saturation? Yeah, I was torn between the two. My way does keep a somewhat cyclical nature, so once it wraps, things could still detect that it's increasing from one observance to the next. But now that I think about it again, it's not a property of this count that's worth keeping, I think. Nothing relies on this behaviour currently, and at best it'll trip up any code that uses it for a < comparison later down the road. > > + > > 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(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 +1601,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[] = { > > @@ -1648,6 +1655,9 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo, > > > > if (drm_gem_is_imported(&bo->base)) > > gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED; > > + else if (!resident_size && atomic_read(&bo->reclaimed_count)) > > + gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EVICTED; > > I think it'd be interesting to know the number of times a BO got > evicted. Agreed. Should I add that as a separate column? I think I'll keep the state flag even if I add a column, because even if it's technically redundant, it'll still be useful to see without having to compare three different columns. > > + > > if (bo->base.dma_buf) > > gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED; > > > > diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/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 = 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,13 @@ 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. > > * > > > + * Never returns to 0 once incremented even on wrap-around, but may > > + * become < 0 and < the previous value if wrap-around occurs. > > With the saturation I suggested, I'd just add that when INT_MAX is > reached, it will stay there. > > > + */ > > + atomic_t reclaimed_count; > > + > > /** > > * @exclusive_vm_root_gem: Root GEM of the exclusive VM this GEM object > > * is attached to. > > > >