Please review this new minimal version. It is way shorter, but this comes with a cost: * Iteration does not stop at the end of range (but an out of range allocation never happens) * Iteration must start from iova == 0 instead of first valid entry in the hole.
These should not be a big deal though. Another possible optimization that comes to my mind is to allocate always at the end of range. In the case of having to allocate and deallocate frequently, this should avoid to iterate over long lived entries. Better justify this with numbers, so I left that out. Thanks!