I started looking into this after my Intel Xe desktop with 32 GiB of RAM would eventually freeze following repeated graphics allocations (A test program allocated around 12 GiB without freeing up). In a separate test, a standalone kernel module exercised the TTM page pool directly. On unpatched 7.4-rc4 in a single-node QEMU guest, 768 MiB remained in the pool 60s after the module returned its pages.
Patch 1 adds a 5s timeout after the last page return. It can stand on its own and drains the idle pool. In QEMU, the pool was empty at the eight-second sample. The trade-off is that the next burst may have to allocate and prepare those pages again. Patch 2 builds on the timeout and keeps a 128 MiB reserve per NUMA node to reduce that trade-off. With both patches, the same 768 MiB test left 128 MiB in the pool at the 8s and 60s samples. The shrinker can still reclaim the reserve under memory pressure. In a separate QEMU benchmark with a 750ms timeout, the median time to allocate 128 MiB after expiry was 185ms after a full drain and 0.45ms with the reserve. A 768 MiB request took 1.13s after a full drain and 0.95s with the reserve. The unpatched kernel kept the entire pool and reused those 768 MiB in about 2ms. These tests measure idle retention and allocation latency in QEMU. The test files can be downloaded at https://codeberg.org/EduApps-CDG/linux-ttm-pool. It includes 2 C files (one for test and another for benchmark), my logs, some build/test helping bash scripts and the compiled binary I'm using on my machine right now. Feedback and change requests are welcome. Eduardo P. Gomez (2): drm/ttm: reclaim pooled pages after a period of inactivity drm/ttm: retain a reserve during idle pool reclaim drivers/gpu/drm/ttm/ttm_pool.c | 92 +++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 7 deletions(-) base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc -- 2.55.0
