LRU SCAN ROSTER(9)
π¦ lru scan roster(9) π¦
okay so hi bestie π you've wandered into the Kernel API Manual, and today's main character is the lru scan roster β aka the DRM range allocator's whole scanning situation. ngl it's lowkey iconic once you get the vibe, so let's get into it β¨
πΈ NAME πΈ
lru scan roster β the scanning interfaces the DRM range allocator uses so GPUs can snag continuous allocations without evicting a million tiny objects for absolutely no reason π
π DESCRIPTION π
okay so picture this: very often GPUs need to have continuous allocations for a given object. so when you're evicting objects to make space for a new one, it is therefore not most efficient when we simply start to select all objects from the tail of an LRU until there's a suitable hole π«
especially for big objects, or nodes that otherwise have special allocation constraints β there's a good chance we evict lots of (smaller) objects unnecessarily. and bestie, that's giving wasteful π
the DRM range allocator supports this use-case through the scanning interfaces. here's the whole flow, step by step:
- first a scan operation needs to be initialized with
drm_mm_scan_initordrm_mm_scan_init_with_range. pick your fighter β¨ - the driver adds objects to the roster β probably by walking an LRU list, but this can be freely implemented. no rules, just vibes π¦
- eviction candidates are added using
drm_mm_scan_add_blockuntil a suitable hole is found or there are no further evictable objects - eviction roster metadata is tracked in
struct drm_mm_scanβ that's where the whole roster's lore lives π
β οΈ okay this part is important bestie: the driver must walk through all objects again in exactly the reverse order to restore the allocator state. and note that while the allocator is used in the scan mode, no other operation is allowed. like, none. the allocator is booked and busy, do not interrupt π
finally, the driver evicts all objects selected in the scan (the ones where drm_mm_scan_remove_block reported true), and any overlapping nodes after color adjustment (drm_mm_scan_color_evict) π
and now the complexity tea β β adding and removing an object is O(1), and since freeing a node is also O(1), the overall complexity is O(scanned_objects) π₯ so like the free stack, which needs to be walked before a scan operation even begins, this is linear in the number of objects. it doesn't seem to hurt too badly β and honestly? periodt π
π SEE ALSO π
- Kernel file
./drivers/gpu/drm/drm_mm.cOverview(9) DECLARE_NEXT_HOLE_ADDR(9)drm_mm_reserve_node(9)drm_mm_insert_node_in_range(9)drm_mm_remove_node(9)drm_mm_scan_init_with_range(9)drm_mm_scan_add_block(9)drm_mm_scan_remove_block(9)drm_mm_scan_color_evict(9)drm_mm_init(9)drm_mm_takedown(9)drm_mm_print(9)
and that's the whole page bestie π«Ά this little gem lives over in ./drivers/gpu/drm and is dated October 2026 β go off, kernel docs, we love to see it πβπ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms