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/ttm: Split cgroup charge and resource allocation
Date: Tue, 03 Mar 2026 13:29:38 +1000	[thread overview]
Message-ID: <review-patch4-20260302-dmemcg-aggressive-protect-v5-4-ffd3a2602309@gmx.de> (raw)
In-Reply-To: <20260302-dmemcg-aggressive-protect-v5-4-ffd3a2602309@gmx.de>

Patch Review

**Purpose:** Decouples cgroup charging from resource allocation so the charge persists across allocation retries. This prevents a TOCTOU race where protection status is checked without the allocation being charged.

**Design:** This is a key enabler for patch 5. The new `ttm_resource_try_charge()` charges the cgroup first, then `ttm_resource_alloc()` takes the charged pool directly. The charge ownership is transferred to the TTM resource on success, with explicit cleanup on failure paths.

The ownership transfer is well-documented:
```c
	/*
	 * Ownership of charge_pool has been transferred to the TTM resource,
	 * don't make the caller think we still hold a reference to it.
	 */
	alloc_state->charge_pool = NULL;
```

**Eviction callback charge attempt:** In `ttm_bo_evict_cb`, after successful eviction:
```c
	if (!evict_walk->alloc_state->charge_pool) {
		lret = ttm_resource_try_charge(bo, evict_walk->place,
					       &evict_walk->alloc_state->charge_pool, NULL);
		if (lret == -EAGAIN)
			return -EBUSY;
		else if (lret)
			return lret;
	}
```
The `-EAGAIN` → `-EBUSY` mapping here will propagate up through `ttm_lru_walk_for_evict`. Since `lret` will be negative, the `!lret` checks in the retry loops won't trigger, effectively stopping the eviction walk. This seems correct — if the cgroup limit prevents charging even after eviction, there's no point continuing.

`NULL` is passed for `ret_limit_pool` in the eviction callback's charge attempt, which is fine since the limit pool was already established during the initial `ttm_bo_alloc_at_place` call.

The uncharge paths in `ttm_bo_alloc_resource` look correct — `dmem_cgroup_uncharge()` is called before `dmem_cgroup_pool_state_put()` on each failure path, and the `-EBUSY` continue path also uncharges.

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-03-03  3:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 12:37 [PATCH v5 0/6] cgroup/dmem,drm/ttm: Improve protection in contended cases Natalie Vock
2026-03-02 12:37 ` [PATCH v5 1/6] cgroup/dmem: Add queries for protection values Natalie Vock
2026-03-03  3:29   ` Claude review: " Claude Code Review Bot
2026-03-02 12:37 ` [PATCH v5 2/6] cgroup,cgroup/dmem: Add (dmem_)cgroup_common_ancestor helper Natalie Vock
2026-03-02 14:38   ` Maarten Lankhorst
2026-03-03  3:29   ` Claude review: " Claude Code Review Bot
2026-03-02 12:37 ` [PATCH v5 3/6] drm/ttm: Extract code for attempting allocation in a place Natalie Vock
2026-03-02 15:08   ` Tvrtko Ursulin
2026-03-03  3:29   ` Claude review: " Claude Code Review Bot
2026-03-02 12:37 ` [PATCH v5 4/6] drm/ttm: Split cgroup charge and resource allocation Natalie Vock
2026-03-02 15:25   ` Tvrtko Ursulin
2026-03-03  3:29   ` Claude Code Review Bot [this message]
2026-03-02 12:37 ` [PATCH v5 5/6] drm/ttm: Be more aggressive when allocating below protection limit Natalie Vock
2026-03-02 17:02   ` Tvrtko Ursulin
2026-03-03  3:29   ` Claude review: " Claude Code Review Bot
2026-03-02 12:37 ` [PATCH v5 6/6] drm/ttm: Use common ancestor of evictor and evictee as limit pool Natalie Vock
2026-03-03  3:29   ` Claude review: " Claude Code Review Bot
2026-03-03  3:29 ` Claude review: cgroup/dmem,drm/ttm: Improve protection in contended cases Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-03-13 11:39 [PATCH v6 0/6] " Natalie Vock
2026-03-13 11:40 ` [PATCH v6 4/6] drm/ttm: Split cgroup charge and resource allocation Natalie Vock
2026-03-13 21:10   ` Claude review: " Claude Code Review Bot
2026-02-25 12:10 [PATCH v4 0/6] cgroup/dmem,drm/ttm: Improve protection in contended cases Natalie Vock
2026-02-25 12:10 ` [PATCH v4 4/6] drm/ttm: Split cgroup charge and resource allocation Natalie Vock
2026-02-27  3: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-patch4-20260302-dmemcg-aggressive-protect-v5-4-ffd3a2602309@gmx.de \
    --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