From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: drm/ttm: Fix GPU MM stats during pool shrinking Date: Tue, 05 May 2026 08:58:24 +1000 Message-ID: In-Reply-To: <20260502065338.2720646-1-matthew.brost@intel.com> References: <20260502065338.2720646-1-matthew.brost@intel.com> <20260502065338.2720646-1-matthew.brost@intel.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **The helper function (lines +105..+111):** ```c static void __free_pages_gpu_account(struct page *p, unsigned int order, bool reclaim) { mod_lruvec_page_state(p, reclaim ? NR_GPU_RECLAIM : NR_GPU_ACTIVE, -(1 << order)); __free_pages(p, order); } ``` This correctly mirrors the pattern already used in `ttm_pool_free_page()`. = The ordering (stat update before `__free_pages`) matches the existing code = and is safe since `mod_lruvec_page_state` only needs the page struct to loo= k up the lruvec, not the page contents. **Refactor in `ttm_pool_free_page()` (lines -120..+123):** Clean replacement of the inline `mod_lruvec_page_state` + `__free_pages` wi= th the new helper. No functional change. Good. **Fix in `ttm_pool_restore_commit()` (line +132):** ```c __free_pages_gpu_account(p, 0, false); ``` Correct. This is the restore path where old retained pages from `tt->pages[= ]` are copied and freed. These pages were allocated via `ttm_pool_alloc_pag= e()` which marks them `NR_GPU_ACTIVE` (line 175 of current tree). They were= never moved to the reclaim pool, so `reclaim=3Dfalse` is right. The order = is 0 because `ttm_pool_split_for_swap()` was called just above. **Fix in `ttm_pool_backup()` purge path (line +141):** ```c __free_pages_gpu_account(page, order, false); ``` Correct. In the purge path, pages from `tt->pages[]` are freed directly at = their original order (no split). These are `NR_GPU_ACTIVE` pages. `reclaim= =3Dfalse` is correct. The `page->private =3D 0` reset on the line above cle= ars the order stored in private, and the helper reads the order from the pa= rameter rather than from `page->private`, so ordering is fine. **Fix in `ttm_pool_backup()` swap path (line +150):** ```c __free_pages_gpu_account(page, 0, false); ``` Replacing `put_page(page)` =E2=80=94 this is the v2 change per Kenneth's fe= edback. After `ttm_pool_split_for_swap()`, these are individual order-0 non= -compound pages, so `__free_pages(p, 0)` is functionally equivalent to `put= _page(page)` here (both do `put_page_testzero` + free). `reclaim=3Dfalse` i= s correct; these pages are `NR_GPU_ACTIVE`. **Minor observation:** The `reclaim` parameter is always `false` at all thr= ee new call sites. The only caller that passes `true` is the existing `ttm_= pool_free_page()` code path. This is expected =E2=80=94 `ttm_pool_backup()`= returns `-EBUSY` for DMA alloc pools, and pages in `tt->pages[]` are never= in the reclaim pool (they'd need to go through `ttm_pool_type_add()` for t= hat). So the `reclaim` parameter is justified by the `ttm_pool_free_page()`= usage, but worth noting that the *new* sites are all `NR_GPU_ACTIVE` decre= ments. **No issues found.** The patch is a correct and minimal fix for a real acco= unting bug. The Fixes tag correctly references the commit that introduced t= he GPU MM stats. Reviewed-by: Dave Airlie --- Generated by Claude Code Patch Reviewer