Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/ttm: repeated empty-pool list_lru locking in ttm_pool_prealloc_fill_full() --
commit a9c3c46ffa013c41ec426391623e966b58881b75 Author: Matthew Brost <[email protected]> drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() This commit adds ttm_pool_prealloc_fill_full() to preallocate the entire backing of a system-memory ttm_tt at mixed orders outside the dma-resv lock. > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c > index fa76f880d5632..7b1736324f7e5 100644 > --- a/drivers/gpu/drm/ttm/ttm_pool.c > +++ b/drivers/gpu/drm/ttm/ttm_pool.c [ ... ] > +static struct page *ttm_pool_take_page(struct ttm_pool *pool, > + enum ttm_caching caching, > + unsigned int *order, gfp_t gfp, > + bool *need_caching, > + bool beneficial_reclaim_backoff) > +{ > + unsigned int beneficial = ttm_pool_beneficial_order(pool); > + struct ttm_pool_type *pt; > + struct page *p; > + > + *need_caching = false; > + > + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial && > + *order >= beneficial && > + should_fail(&beneficial_order_fault_inject, 1)) { > + *order = beneficial; > + return NULL; > + } > + > + pt = ttm_pool_select_type(pool, caching, *order); > + if (pt) { > + p = ttm_pool_type_take(pt, ttm_pool_nid(pool)); > + if (p) > + return p; /* pool page already carries @caching */ > + } > + > + p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff); > + if (!p) > + return NULL; > + > + /* Fresh system page is write-back; caller applies @caching in bulk. */ > + *need_caching = true; > + return p; > +} [ ... ] > +int ttm_pool_prealloc_fill_full(struct ttm_pool *pool, > + enum ttm_caching tt_caching, > + struct ttm_pool_prealloc *pp, > + unsigned int num_pages, > + bool beneficial_reclaim_backoff) > +{ [ ... ] > + while (remaining) { > + unsigned int order = min_t(unsigned int, highest, > + __fls(remaining)); > + bool need_caching; > + struct page *p; > + > + for (;;) { > + p = ttm_pool_take_page(pool, tt_caching, &order, gfp, > + &need_caching, > + beneficial_reclaim_backoff); > + if (p) > + break; > + if (!order) > + goto apply_caching; /* short fill */ > + /* > + * Genuine failure: retry one order down. A fault > + * injection lowered @order to the beneficial order > + * above, so this drops it below - landing on a > + * sub-optimal (defrag-worthy) chunk. > + */ > + order--; > + } [Severity: Medium] Should ttm_pool_prealloc_fill_full() stop probing the pool at the current order once ttm_pool_type_take() returns NULL, the way ttm_pool_iter_acquire_page() does with it->allow_pools? In the in-line allocator, once ttm_pool_type_take() misses at a given order, it->allow_pools is cleared until the allocator drops to a lower order. Here, ttm_pool_take_page() calls ttm_pool_type_take() on every iteration of the while (remaining) loop. On x86, ttm_write_combined and ttm_uncached use the global pool types, and ttm_pool_type_take() -> list_lru_walk_node() unconditionally acquires and releases the list_lru spinlock even when the list is empty. When the global WC or UC pool is empty and allocation falls back to order 0 (for instance when beneficial_reclaim_backoff skips reclaim at higher orders), preallocating a buffer object acquires and releases the global order-0 list_lru spinlock once per 4K page instead of once per order, contending across concurrent unlocked preallocations. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=11
