Skip to content

iommu/vfio: introduce best-fit iova allocation - #40

Merged
minwooim merged 3 commits into
SamsungDS:mainfrom
minwooim:vfio-iova
Aug 17, 2025
Merged

iommu/vfio: introduce best-fit iova allocation#40
minwooim merged 3 commits into
SamsungDS:mainfrom
minwooim:vfio-iova

Conversation

@minwooim

@minwooim minwooim commented Aug 8, 2025

Copy link
Copy Markdown
Collaborator
Introduce a best-fit IOVA allocation policy to vfio_iommu_type1 device
to reuse previously allocated and freed IOVA ranges in the next
allocation.  Unlike `iommufd` which allocates the IOVA address in the
kernel side, `vfio_iommu_type1` device should manage the IOVA ranges in
libvfn to avoid permanently incremental memory allocation for a
long-lived application like ``unvme-cli``.

Firstly try to allocate from @free_iovas skiplist for a new IOVA
allocation with a best-fit allocation method, and if not, it goes to the
previous way with `__iova_reserve()`.  Other than this, no functional
changes.

Added two helpers to find adjacent range in the given @list.

  skiplist_find: To find a exact range matches with the @key (existing)
  skiplist_find_le: To find a largest range <= @key, previous adjacent
  skiplist_find_ge: To find a smallest range >= @key, next adjacent

Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
@minwooim
minwooim requested a review from birkelund August 8, 2025 10:38
@birkelund birkelund added the approved Approved for device testing label Aug 13, 2025
@birkelund

Copy link
Copy Markdown
Collaborator

LGTM.

It would be good to add a few tests in src/util/skiplist_test.c for this functionality. At some point it would be nice to try to refactor those three _find(), _find_ge() and _find_le() into one function if possible. Tests would help fight regressions.

@minwooim

Copy link
Copy Markdown
Collaborator Author

LGTM.

It would be good to add a few tests in src/util/skiplist_test.c for this functionality. At some point it would be nice to try to refactor those three _find(), _find_ge() and _find_le() into one function if possible. Tests would help fight regressions.

agreed. I will put some tests.

Add test cases for skiplist to test skiplist_find_le() and
skiplist_find_get().

Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
Introduce a best-fit IOVA allocation policy to vfio_iommu_type1 device
to reuse previously allocated and freed IOVA ranges in the next
allocation.  Unlike `iommufd` which allocates the IOVA address in the
kernel side, `vfio_iommu_type1` device should manage the IOVA ranges in
libvfn to avoid permanently incremental memory allocation for a
long-lived application like ``unvme-cli``.

Firstly try to allocate from @free_iovas skiplist for a new IOVA
allocation with a best-fit allocation method, and if not, it goes to the
previous way with `__iova_reserve()`.  Other than this, no functional
changes.

Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
@minwooim
minwooim merged commit 61064e3 into SamsungDS:main Aug 17, 2025
26 checks passed
iomartin added a commit to Eideticom/libvfn-pub that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Approved for device testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants