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: Introduce ttm_bo_shrink_kswap_maybe_fragmented() Date: Tue, 05 May 2026 10:00:01 +1000 Message-ID: In-Reply-To: <20260430191809.2142544-5-matthew.brost@intel.com> References: <20260430191809.2142544-1-matthew.brost@intel.com> <20260430191809.2142544-5-matthew.brost@intel.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Patch Review **Subject:** `[PATCH v4 4/6] drm/ttm: Introduce ttm_bo_shrink_kswap_maybe_fragmented()` Adds a helper in `ttm_bo_util.c`: ```c +bool ttm_bo_shrink_kswap_maybe_fragmented(int nid, s8 order) +{ + if (!order) + return false; + + if (!current_is_kswapd()) + return false; + + if (!numa_valid_node(nid)) + return false; + +#if IS_ENABLED(CONFIG_ZONE_DMA32) + zone_type = ZONE_DMA32; +#else + zone_type = ZONE_NORMAL; +#endif + + for (; zone_type <= ZONE_NORMAL; ++zone_type) { + struct zone *zone = &NODE_DATA(nid)->node_zones[zone_type]; + if (zone_maybe_fragmented_in_shrinker(zone)) + return true; + } + return false; +} ``` **Concerns:** 1. **The zone iteration logic is confusing.** When `CONFIG_ZONE_DMA32` is enabled, it iterates from `ZONE_DMA32` to `ZONE_NORMAL`. When it's disabled, it only checks `ZONE_NORMAL` (since `zone_type = ZONE_NORMAL` and the loop condition is `<= ZONE_NORMAL`). This is correct but the `#if`/`#else` makes it harder to read than necessary. A comment explaining the iteration range would help. 2. **`ZONE_DMA` is excluded.** The helper only checks DMA32 and NORMAL zones. This is probably intentional (GPU memory typically comes from these zones) but isn't documented. 3. **Return semantics are good.** The early returns for `!order` (order-0 allocations shouldn't trigger fragmentation avoidance), `!current_is_kswapd()` (only affects background reclaim), and `!numa_valid_node(nid)` are sensible guards. 4. **Docstring typo:** "false is not" should be "false if not". ```c * Return: true if in kswap and memory appears fragmented, false is not. ``` 5. **The `order` parameter is `s8` but only tested for non-zero.** The actual order value isn't used beyond the zero check. If the intent is only "was this a higher-order allocation?", a bool would be clearer. However, passing `order` through is forward-compatible for future refinements that may want the actual value. **Minor issues only. Functionally sound.** --- --- Generated by Claude Code Patch Reviewer