All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eduardo P. Gomez" <eduardoprocopiogomez@gmail.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v2] drm/ttm: reclaim excess pooled pages after a fixed delay
Date: Wed, 25 Nov 2026 02:10:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-232393@kernel.org> (raw)
In-Reply-To: <20261125015613.127297-1-eduardoprocopiogomez@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/ttm: unbatched set_pages_wb() IPI storm in
  ttm_pool_shrink_idle()
--

commit e91f541d87136a66bf36718752a8777d95e748f4
Author: Eduardo P. Gomez <eduardoprocopiogomez@gmail.com>

drm/ttm: reclaim excess pooled pages after a fixed delay

This commit schedules delayed work to reclaim pooled TTM pages above a
per-node reserve after a fixed five-second window and uses a single
counter read in ttm_pool_free() when checking the node limit.

> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 1bf37023fed66..09766496d8810 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
[ ... ]
> @@ -473,6 +511,46 @@ static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free)
>  	return num_pages;
>  }
>  
> +/* Trim excess pooled pages when the fixed reclaim window expires. */
> +static void ttm_pool_shrink_idle(struct work_struct *work)
> +{
> +	const unsigned long batch = 1UL << (MAX_PAGE_ORDER / 2);
> +	size_t nr_types;
> +	int nid;
> +
> +	spin_lock(&shrinker_lock);
> +	nr_types = list_count_nodes(&shrinker_list);
> +	spin_unlock(&shrinker_lock);
> +
> +	for_each_node_state(nid, N_MEMORY) {
> +		unsigned long reserve = min(page_pool_idle_reserve,
> +					    pool_node_limit[nid]);
> +		long pages = atomic_long_read(&allocated_pages[nid]);
> +		unsigned long budget;
> +		size_t empty = 0;
> +
> +		if (pages <= 0 || pages <= reserve)
> +			continue;
> +
> +		/* Bound freed pages and scans that make no progress. */
> +		budget = pages - reserve;
> +		while (budget && empty < nr_types && pages > 0 && pages > reserve) {
> +			unsigned long freed;
> +
> +			freed = ttm_pool_shrink(nid, batch, min(budget, pages - reserve));
> +			budget -= min(budget, freed);
> +			empty = freed ? 0 : empty + 1;
> +			cond_resched();
> +			pages = atomic_long_read(&allocated_pages[nid]);
> +		}

[Severity: Medium]
Can draining the entire excess in one ttm_pool_shrink_idle() pass cause an
unbatched set_pages_wb() TLB shootdown storm on x86?

ttm_pool_shrink() -> ttm_pool_dispose_list() calls ttm_pool_free_page()
once per isolated entry, which restores write-back caching individually:

drivers/gpu/drm/ttm/ttm_pool.c:ttm_pool_free_page() {
	...
#ifdef CONFIG_X86
	/* We don't care that set_pages_wb is inefficient here. This is only
	 * used when we have to shrink and CPU overhead is irrelevant then.
	 */
	if (caching != ttm_cached && !PageHighMem(p))
		set_pages_wb(p, 1 << order);
#endif
	...
}

Each set_pages_wb() call takes cpa_lock and broadcasts a synchronous
cross-CPU TLB shootdown IPI, so reclaiming 1 GiB of order-0 write-combined
pages in one pass issues 262,144 individual set_pages_wb() calls while also
rotating through all empty shrinker_list entries after every 32-entry
batch.  Because ttm_pool_note_return() uses a fixed five-second timer that
is not deferred by ongoing pool activity, an active GPU workload cycling
more than 128 MiB of WC/UC buffers will repeatedly pay this unbatched
set_pages_wb() shootdown storm and subsequent set_pages_array_wc() or
set_pages_array_uc() allocation shootdowns every five seconds.

Batching the caching transition across dispose list entries with
set_pages_array_wb() (as ttm_pool_backup() does) would avoid per-page CPA
shootdowns.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125015613.127297-1-eduardoprocopiogomez@gmail.com?part=1

      reply	other threads:[~2026-11-25  2:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:56 [RFC PATCH v2] drm/ttm: reclaim excess pooled pages after a fixed delay Eduardo P. Gomez
2026-11-25  2:10 ` sashiko-bot [this message]

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=sashiko-outbox-232393@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eduardoprocopiogomez@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.