mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/3] iova: use maple tree for O(log n) allocation
@ 2026-06-03  3:35 Rik van Riel
  2026-06-03  3:35 ` [PATCH v3 1/3] iova: convert from rbtree to maple tree Rik van Riel
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Rik van Riel @ 2026-06-03  3:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-team, robin.murphy, joro, will, iommu, jgg, kyle


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 uses a maple tree to index the iova ranges.
This allows alloc_iova() to have O(log n) complexity, while
memory use stays about the same as before.

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

v3:
 - switch to maple tree (suggested by Robin Murphy)
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



^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2026-06-30 18:39 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03  3:35 [PATCH v3 0/3] iova: use maple tree for O(log n) allocation Rik van Riel
2026-06-03  3:35 ` [PATCH v3 1/3] iova: convert from rbtree to maple tree Rik van Riel
2026-06-17 19:55   ` Liam R. Howlett
2026-06-19  3:47     ` Rik van Riel
2026-06-03  3:35 ` [PATCH v3 2/3] iova: add KUnit test suite Rik van Riel
2026-06-03  3:35 ` [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure Rik van Riel
2026-06-09 13:04   ` Jason Gunthorpe
2026-06-11  2:22     ` Rik van Riel
2026-06-12 16:02     ` Rik van Riel
2026-06-12 16:48       ` Jason Gunthorpe
2026-06-12 17:23         ` Rik van Riel
2026-06-12 18:03           ` Jason Gunthorpe
2026-06-12 18:44             ` Liam R. Howlett
2026-06-15 11:56               ` Jason Gunthorpe
2026-06-17 17:45                 ` Liam R. Howlett
2026-06-17 18:04                   ` Jason Gunthorpe
2026-06-18 14:50                     ` Liam R. Howlett
2026-06-18 15:24                       ` Jason Gunthorpe
2026-06-18 17:27                         ` Liam R. Howlett
2026-06-18 17:30                           ` Rik van Riel
2026-06-18 19:13                             ` Liam R. Howlett
2026-06-19 12:08                           ` Jason Gunthorpe
2026-06-30 18:39                             ` Liam R. Howlett
2026-06-19  3:51                         ` Rik van Riel
2026-06-19  4:54                           ` Liam R. Howlett
2026-06-19 12:13                             ` Jason Gunthorpe
2026-06-19 18:54                               ` Rik van Riel
2026-06-21  0:08   ` Ashok Raj
2026-06-21  1:53     ` Rik van Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome