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 <[email protected]> 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/[email protected]?part=1
