freenode
Desktop & Graphics

Intel proposes keeping Xe page reclaim off the path that stalls flips

A 35-patch series moves high-order allocation and buffer defrag out of the reservation lock so user-facing GPU paths fall back instead of compacting memory in the foreground.

Intel's Matthew Brost has posted a large update to the Xe driver and the DRM TTM memory manager that tries to stop user-facing GPU work from stalling while the kernel hunts for large, contiguous pages.

The problem is a familiar one on memory-constrained systems. Creating a buffer, validating it, executing a command, or handling a fault can all need higher-order pages. Doing that allocation, and the memory reclaim or compaction it triggers, while holding the buffer's reservation lock serializes other clients and can delay a page flip. Brost's stated goal is that those foreground paths never enter that reclaim. They try a beneficial page order if it is cheap, then fall back to smaller pages so the ioctl returns quickly even under pressure.

The expensive work moves to a background defragmenter. A buffer that was backed with scattered pages pays a translation-lookaside-buffer cost for its whole lifetime. TTM gains a way to record that the preferred order failed and to replace the backing of an already populated buffer in place. Xe runs a delayed worker that is allowed to reclaim aggressively, but only outside the reservation lock, then promotes the buffer on the GPU under a short lock hold. Brost reports that with both allocation and cache-mode changes hoisted out, the time the lock is held falls to the copy itself: a median of about 0.27 milliseconds, with a 95th percentile around 2 milliseconds, the remaining tail being waits behind active rendering.

Where the IOMMU allows it, eligible device buffers can also be mapped as one contiguous IOVA range instead of a scatter-gather list, which is cheaper to walk and program. Defrag of those buffers copies only the pages that actually changed and keeps the device-visible addresses, so ordinary 3D virtual machines do not have to rebind. Compute virtual machines still take a rebind.

Brost says 3D benchmarks on Ubuntu and Android, launched with memory already fragmented, start with lower scores on sub-optimally backed buffers and then recover as the worker promotes them.

The series also carries two unplug fixes Brost wants in stable kernels from 6.16 on. After the PCI device is removed, an exported dma-buf could be moved back into a mapping that outlives the device's IOMMU group, and a pinned-buffer unmap could race with an importer and free the same mapping twice. Non-eviction moves back to that placement are refused once the device is unplugged, and the unmap takes the buffer lock.