All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Natalie Vock" <natalie.vock@gmx.de>
Cc: tj@kernel.org, dri-devel@lists.freedesktop.org, mkoutny@suse.com,
	hannes@cmpxchg.org
Subject: Re: [PATCH v8 5/6] drm/ttm: Be more aggressive when allocating below protection limit
Date: Tue, 04 Aug 2026 08:40:46 +0000	[thread overview]
Message-ID: <20260804084047.8B71D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804-dmemcg-aggressive-protect-v8-5-07af96681bf8@gmx.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Allocations protected by the dmem cgroup `min` limit will incorrectly evict their own cgroup's buffers during the early eviction pass, preventing the cgroup from reaching its `min` guarantee.
--

--- Patch [5]: [PATCH v8 5/6] drm/ttm: Be more aggressive when allocating below protection limit ---
commit 30d3ed5047eb42c7b72fcb6f1d1973210be68163
Author: Natalie Vock <nat@pixelcluster.dev>

drm/ttm: Be more aggressive when allocating below protection limit
    
When the cgroup's memory usage is below the low/min limit and allocation
fails, try evicting some unprotected buffers to make space. Otherwise,
application buffers may be forced to go into GTT even though usage is
below the corresponding low/min limit, if other applications filled VRAM
with their allocations first.

> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 3becddd2c43b8..6bbea148838e4 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
[ ... ]
> @@ -537,12 +541,50 @@ static int ttm_bo_alloc_at_place(struct ttm_buffer_object *bo,
[ ... ]
> +	/*
> +	 * Buffers protected by 'min' will never be considered for eviction
> +	 * anyway, so the regular eviction path should be triggered here.
> +	 * Buffers protected by 'low' but not 'min' will take a special
> +	 * eviction path that only evicts buffers covered by neither 'low' or
> +	 * 'min' protections.
> +	 */
> +	if (!alloc_state->in_evict) {
> +		may_evict |= dmem_cgroup_below_min(NULL, alloc_state->charge_pool);
> +		alloc_state->may_try_low = may_evict;
> +
> +		may_evict |= dmem_cgroup_below_low(NULL, alloc_state->charge_pool);
> +	}

[Severity: High]
Does this code inadvertently allow a cgroup to evict its own buffers when it is
below the min limit?

When dmem_cgroup_below_min() returns true, alloc_state->may_try_low is set
to true here.

Later in ttm_bo_evict_cb(), this causes the self-eviction skip check to be
bypassed:

	if (!evict_walk->alloc_state->may_try_low &&
			bo->resource->css == evict_walk->alloc_state->charge_pool)
		return 0;

Because dmem_cgroup_state_evict_valuable() allows a pool to evict from itself,
this means the cgroup will evict its own buffers instead of unprotected buffers
from other cgroups. Will this prevent the cgroup from reaching its min limit
guarantee?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804-dmemcg-aggressive-protect-v8-0-07af96681bf8@gmx.de?part=5

  reply	other threads:[~2026-08-04  8:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  8:25 [PATCH v8 0/6] cgroup/dmem,drm/ttm: Improve protection in contended cases Natalie Vock
2026-08-04  8:25 ` [PATCH v8 1/6] cgroup/dmem: Add queries for protection values Natalie Vock
2026-08-04  8:41   ` sashiko-bot
2026-08-04  8:25 ` [PATCH v8 2/6] cgroup,cgroup/dmem: Add (dmem_)cgroup_common_ancestor helper Natalie Vock
2026-08-04 20:18   ` Maarten Lankhorst
2026-08-04 20:26     ` Natalie Vock
2026-08-04 20:41       ` Maarten Lankhorst
2026-08-04 20:56         ` Thadeu Lima de Souza Cascardo
2026-08-04 21:08           ` Natalie Vock
2026-08-04 22:06             ` Thadeu Lima de Souza Cascardo
2026-08-05  2:08               ` Thadeu Lima de Souza Cascardo
2026-08-05  6:30           ` Maarten Lankhorst
2026-08-04  8:25 ` [PATCH v8 3/6] drm/ttm: Extract code for attempting allocation in a place Natalie Vock
2026-08-04  8:41   ` sashiko-bot
2026-08-04  8:25 ` [PATCH v8 4/6] drm/ttm: Split cgroup charge and resource allocation Natalie Vock
2026-08-04  8:44   ` sashiko-bot
2026-08-04  8:25 ` [PATCH v8 5/6] drm/ttm: Be more aggressive when allocating below protection limit Natalie Vock
2026-08-04  8:40   ` sashiko-bot [this message]
2026-08-04  8:25 ` [PATCH v8 6/6] drm/ttm: Use common ancestor of evictor and evictee as limit pool Natalie Vock
2026-08-04  8:53   ` sashiko-bot
2026-08-04 15:36 ` [PATCH v8 0/6] cgroup/dmem, drm/ttm: Improve protection in contended cases Timur Kristóf
2026-08-04 15:36   ` [PATCH v8 0/6] cgroup/dmem,drm/ttm: " Timur Kristóf
2026-08-05  8:42 ` Natalie Vock

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=20260804084047.8B71D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hannes@cmpxchg.org \
    --cc=mkoutny@suse.com \
    --cc=natalie.vock@gmx.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.