public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/panthor: Implement evicted status for GEM objects
Date: Thu, 23 Apr 2026 09:29:12 +1000	[thread overview]
Message-ID: <review-patch2-20260420-panthor-bo-reclaim-observability-v1-2-a4d1a36ee84f@collabora.com> (raw)
In-Reply-To: <20260420-panthor-bo-reclaim-observability-v1-2-a4d1a36ee84f@collabora.com>

Patch Review

**Summary:** Adds an `atomic_t reclaimed_count` field to `panthor_gem_object`, increments it in the evict path, and uses it to report `DRM_GEM_OBJECT_EVICTED` via the `.status` callback and the debugfs gems interface.

**Review:**

**Issue 1 (design): The wrap-around avoidance is over-engineered for a boolean need.**

```c
	/* 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);
```

The only consumer of `reclaimed_count` checks `!= 0`:
```c
	else if (atomic_read(&bo->reclaimed_count))
		res |= DRM_GEM_OBJECT_EVICTED;
```

If the sole purpose is "has this BO ever been evicted", a simple `bool` or even a flag bit would suffice. The commit message justifies the counter by saying "It's possible to distinguish evicted non-resident pages from newly allocated non-resident pages by checking whether reclaimed_count is != 0" — but that's the same as a boolean.

If there's a genuine use case for knowing *how many times* a BO was evicted (e.g., for future debugfs stats), the counter makes sense. But in that case, the wrap-around logic is wrong — after wrap-around, the count is no longer meaningful. And `atomic_inc_unless_negative` is not a cheap operation (it's a cmpxchg loop), unlike a simple `atomic_inc` or `atomic_set`.

Suggestion: Either use a simpler `bool evicted` (or a flag bit) if you only need the boolean, or use a plain `atomic_inc` if you want a counter (wrap-around after 2^31 evictions is not a real-world concern, and the count being "wrong" after wrap is no worse than clamping at 1).

**Issue 2 (atomics concern): `atomic_set` after failed `atomic_inc_unless_negative` is not atomic with respect to concurrent reads.**

```c
	if (!atomic_inc_unless_negative(&bo->reclaimed_count))
		atomic_set(&bo->reclaimed_count, 1);
```

If two threads hit this simultaneously when `reclaimed_count` is `INT_MIN`, both could see `atomic_inc_unless_negative` fail (since `INT_MIN` is negative), and both call `atomic_set(&bo->reclaimed_count, 1)`. That's fine — the result is still 1. But there's a window where a concurrent `atomic_read` from `panthor_gem_status` could observe 0 if the set hasn't completed. In practice, this is harmless since:
- Eviction holds a lock (`panthor_gem_evict_locked`)
- The status read is racy by design (documented in `drm_gem_object_funcs.status`)

But it would be cleaner to just use `atomic_inc` and accept that the counter can wrap, or use a simple flag.

**Issue 3 (logic): The `else if` chain in `panthor_gem_status` means imported objects can never be reported as evicted.**

```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;
```

Since imported objects always get `RESIDENT`, they can never get `EVICTED`. This is probably correct (imported objects shouldn't be evicted by the panthor shrinker), but worth confirming — does the panthor shrinker skip imported BOs? If an imported BO were somehow evicted, the status would incorrectly show it as `RESIDENT`.

**Issue 4 (debugfs): Same `else if` pattern with different condition for debugfs.**

```c
	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;

	if (bo->base.dma_buf)
		gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
```

Note the `else if` means an imported BO will never show as evicted in debugfs either. An exported BO *can* show as evicted (since the exported check uses a separate `if`), which is inconsistent with the imported BO treatment. If an exported BO is evicted, it will show both "exported" and "evicted" flags in debugfs, which seems correct. But an imported+evicted BO (if possible) would only show "imported". This is a minor consistency concern.

**Issue 5 (missing initialization): `reclaimed_count` is not explicitly initialized.**

The new `atomic_t reclaimed_count` field in `panthor_gem_object` is not explicitly initialized to 0 in any allocation path. This relies on the GEM object being allocated with `kzalloc` (via shmem helpers), which zero-initializes the entire struct. This works correctly for `atomic_t` since `ATOMIC_INIT(0)` is just `{ 0 }`, but it's worth noting that this is an implicit dependency on zero-initialization.

**Issue 6 (nit): Comment style.**

```c
	/* Don't ever wrap around as far as 0, jump from INT_MIN to 1 */
```

This is a reasonable comment given the non-obvious wrap-around handling, though it could be simplified if the approach itself is simplified.

**Positive aspects:**
- The debugfs flag naming table is correctly extended
- The `else if` logic in `panthor_gem_status` correctly makes `EVICTED` mutually exclusive with `RESIDENT`
- The commit message is well-written and clearly explains the rationale

---

**Summary:** The series is architecturally sound and fills a real observability gap. The main feedback is: (1) consider whether `obj->size` is more appropriate than `add_size` for the evicted counter in patch 1, (2) simplify the `reclaimed_count` to either a plain boolean flag or a simple `atomic_inc` counter in patch 2, and (3) add documentation about `EVICTED`/`RESIDENT` mutual exclusivity to the enum comments.

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-04-22 23:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 15:46 [PATCH 0/2] Let userspace know about swapped out panthor GEM objects 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
2026-04-20 15:47 ` [PATCH 2/2] drm/panthor: Implement evicted status for GEM objects Nicolas Frattaroli
2026-04-20 16:17   ` Boris Brezillon
2026-04-20 17:46     ` Nicolas Frattaroli
2026-04-21  7:22       ` Boris Brezillon
2026-04-22 23:29   ` Claude Code Review Bot [this message]
2026-04-22 23:29 ` Claude review: Let userspace know about swapped out panthor " Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-04-21 10:45 [PATCH v2 0/3] " Nicolas Frattaroli
2026-04-21 10:45 ` [PATCH v2 2/3] drm/panthor: Implement evicted status for " Nicolas Frattaroli
2026-04-22 22:36   ` Claude review: " Claude Code Review Bot

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=review-patch2-20260420-panthor-bo-reclaim-observability-v1-2-a4d1a36ee84f@collabora.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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