Skip to content

iova: switch to augmented rbtree to avoid linear search

Rik van Riel linux-iommu lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 2 repliesIn review
  2. v15 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- clean up selftests (thanks Jason Gunthorpe)
- address Sashiko concerns
- drop the search-with-alignment, since most iova requests should be of similar sizes, so the worst case behavior is unlikely to hit once ranges are excluded by the augmented rbtree

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4iova: switch to augmented rbtree for log(n) allocationdrivers/iommu/iova.c include/linux/iova.h+147 -800 replies
2/4iova: drop dead cached_node / cached32_node infrastructuredrivers/iommu/iova.c include/linux/iova.h+3 -340 replies
3/4iova: limit_pfn-aware augmentation for log(n) 32-bit allocdrivers/iommu/iova.c include/linux/iova.h+140 -292 replies
4/4iova: add KUnit test suitedrivers/iommu/.kunitconfig drivers/iommu/Kconfig drivers/iommu/Makefile +3 more+429 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/4] iova: switch to augmented rbtree to avoid linear search

Occasionally production workloads at Meta run into the linear search in alloc_iova() in ways that cause real issues. For example, when enough CPUs at a time fall into the linear search trap, systems have been known to get stuck for so long that it causes soft lockups.

With the old code, free_iova, find_iova, reserve_iova, iova_insert_rbtree, and remove_iova were all O(log n) already. They stay that way with these patches.

This patch series turns the iova rbtree into an augmented rbtree, which allows alloc_iova to also be O(log n).

It also adds some self tests for the iova code.

The code was written by Claude, and nitpicked by myself. Don't be shy if there are more nitpicks remaining.

It was tested both in a VM (running the selftests), and on an AMD Bergamo system with IOMMU enabled.

Unfortunately I do not know of any way to reproduce the linear search soft lockups at will, so I have not been able to verify that scenary in practice.

Based on 5d6919055dec Linux 7.1-rc3

v2:
- clean up selftests (thanks Jason Gunthorpe)
- address Sashiko concerns
- drop the search-with-alignment, since most iova requests should be of similar sizes, so the worst case behavior is unlikely to hit once ranges are excluded by the augmented rbtree