From: sashiko-bot@kernel.org
To: "Eduardo P. Gomez" <eduardoprocopiogomez@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH 2/2] drm/ttm: retain a reserve during idle pool reclaim
Date: Wed, 25 Nov 2026 09:00:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-232965@kernel.org> (raw)
In-Reply-To: <20261124222812.511867-3-eduardoprocopiogomez@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/ttm: unit mismatch between num_to_free and page_budget in
ttm_pool_shrink()
- [Medium] drm/ttm: reserve underrun and spin in ttm_pool_shrink_idle()
on in-flight dispose
--
commit 4e83ddb6cbf7cc0eb4ace5ed5228122c85cb44a0
Author: Eduardo P. Gomez <eduardoprocopiogomez@gmail.com>
drm/ttm: retain a reserve during idle pool reclaim
This commit adds a configurable per-NUMA-node page reserve that is
retained during idle TTM page pool reclaim.
> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 6af8a9c894b4e..3aad264fa11f8 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
[ ... ]
> @@ -485,7 +491,8 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool,
> }
>
> /* Free pages using the per-node shrinker list */
> -static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free)
> +static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free,
> + unsigned long page_budget)
> {
> LIST_HEAD(dispose);
> struct ttm_pool_type *pt;
> @@ -497,6 +504,10 @@ static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free)
> list_move_tail(&pt->shrinker_list, &shrinker_list);
> spin_unlock(&shrinker_lock);
>
> + /* A list entry represents a whole compound allocation. */
> + if (page_budget)
> + num_to_free = min(num_to_free, ((page_budget - 1) >> pt->order) + 1);
> +
> num_pages = list_lru_walk_node(&pt->pages, nid, pool_move_to_dispose_list, &dispose, &num_to_free);
> num_pages *= 1 << pt->order;
[Severity: Medium]
Should num_to_free also be converted from base pages to pt->order compound
list entries?
page_budget is shifted by pt->order, but num_to_free is passed directly to
list_lru_walk_node() as a count of compound entries. In
ttm_pool_shrink_idle(), batch is 32, so when pt->order is 10 and
pages - reserve is large, a single ttm_pool_shrink() call can isolate and
free up to 32 order-10 allocations (128 MiB) under pool_shrink_rwsem
before re-checking pool_last_return or calling cond_resched(). Meanwhile,
ttm_pool_free() and ttm_pool_shrinker_scan() pass base-page counts (diff
and sc->nr_to_scan) as num_to_free with page_budget = 0, over-shrinking
high-order pools by a factor of 1 << pt->order.
Converting num_to_free from base pages to compound entries inside
ttm_pool_shrink() and passing min(batch, pages - reserve) from
ttm_pool_shrink_idle() would keep all callers in base-page units without
needing a separate page_budget parameter.
> @@ -513,7 +524,12 @@ static void ttm_pool_shrink_idle(struct work_struct *work)
> int nid;
>
> for_each_node_state(nid, N_MEMORY) {
> - while (atomic_long_read(&allocated_pages[nid]) > 0) {
> + unsigned long reserve = min(page_pool_idle_reserve,
> + pool_node_limit[nid]);
> + long pages;
> +
> + while ((pages = atomic_long_read(&allocated_pages[nid])) > 0 &&
> + pages > reserve) {
> unsigned long now = jiffies;
> unsigned long expires = READ_ONCE(pool_last_return) +
> pool_idle_delay;
> @@ -524,7 +540,7 @@ static void ttm_pool_shrink_idle(struct work_struct *work)
> return;
> }
>
> - ttm_pool_shrink(nid, batch);
> + ttm_pool_shrink(nid, batch, pages - reserve);
> cond_resched();
> }
> }
[Severity: Medium]
Can ttm_pool_shrink_idle() drain the pool below reserve and busy-spin when
another thread is concurrently disposing pages?
list_lru_walk_node() isolates a batch of entries from pt->pages onto a
local dispose list, while ttm_pool_dispose_list() decrements
allocated_pages[nid] one entry at a time across ttm_pool_free_page()
calls:
CPU0 (ttm_pool_shrinker_scan) CPU1 (ttm_pool_shrink_idle)
ttm_pool_shrink()
list_lru_walk_node()
/* isolates pages to dispose */
pages = atomic_long_read(&allocated_pages[nid])
/* still includes CPU0's isolated pages */
ttm_pool_shrink(nid, batch, pages - reserve)
/* drains pt->pages below reserve */
ttm_pool_dispose_list()
atomic_long_sub(...)
ttm_pool_free_page(...)
While CPU0 is freeing its dispose list (which on x86 issues per-entry
set_pages_wb() TLB shootdowns for WC/UC pages), allocated_pages[nid] stays
elevated above the number of pages still on pt->pages. CPU1 computes
pages - reserve from that stale total and drains remaining pooled pages
below reserve. If all pt->pages on the node become empty while CPU0's
in-flight dispose list still holds more than reserve pages, CPU1 loops
with ttm_pool_shrink() returning 0, repeatedly rotating shrinker_list
under pool_shrink_rwsem and shrinker_lock until CPU0 decrements
allocated_pages[nid] to or below reserve.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124222812.511867-2-eduardoprocopiogomez@gmail.com?part=2
next prev parent reply other threads:[~2026-11-25 9:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:28 [RFC PATCH 0/2] drm/ttm: fix excessive idle memory retention Eduardo P. Gomez
2026-11-24 22:28 ` [RFC PATCH 1/2] drm/ttm: reclaim pooled pages after a period of inactivity Eduardo P. Gomez
2026-11-25 9:04 ` sashiko-bot
2026-11-24 22:28 ` [RFC PATCH 2/2] drm/ttm: retain a reserve during idle pool reclaim Eduardo P. Gomez
2026-11-25 9:00 ` sashiko-bot [this message]
2026-11-25 10:14 ` [RFC PATCH 0/2] drm/ttm: fix excessive idle memory retention Thomas Hellström
2026-11-25 13:27 ` Eduardo P. Gomez
2026-11-25 15:47 ` Thomas Hellström
2026-11-25 19:36 ` Eduardo P. Gomez
2026-11-26 10:35 ` Thomas Hellström
2026-11-29 3:46 ` Eduardo P. Gomez
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-232965@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.