LRU SCAN ROSTER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ 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:

  1. first a scan operation needs to be initialized with drm_mm_scan_init or drm_mm_scan_init_with_range. pick your fighter ✨
  2. the driver adds objects to the roster β€” probably by walking an LRU list, but this can be freely implemented. no rules, just vibes πŸ¦‹
  3. eviction candidates are added using drm_mm_scan_add_block until a suitable hole is found or there are no further evictable objects
  4. 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 πŸ”—


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