[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 21/31] util: Add iova_tree_alloc
|
From: |
Peter Xu |
|
Subject: |
Re: [PATCH 21/31] util: Add iova_tree_alloc |
|
Date: |
Mon, 24 Jan 2022 12:32:47 +0800 |
On Fri, Jan 21, 2022 at 09:27:23PM +0100, Eugenio Pérez wrote:
> +int iova_tree_alloc(IOVATree *tree, DMAMap *map, hwaddr iova_begin,
> + hwaddr iova_last)
> +{
> + const DMAMapInternal *last, *i;
> +
> + assert(iova_begin < iova_last);
> +
> + /*
> + * Find a valid hole for the mapping
> + *
> + * TODO: Replace all this with g_tree_node_first/next/last when available
> + * (from glib since 2.68). Using a sepparated QTAILQ complicates code.
> + *
> + * Try to allocate first at the end of the list.
> + */
> + last = QTAILQ_LAST(&tree->list);
> + if (iova_tree_alloc_map_in_hole(last, NULL, iova_begin, iova_last,
> + map->size)) {
> + goto alloc;
> + }
> +
> + /* Look for inner hole */
> + last = NULL;
> + for (i = QTAILQ_FIRST(&tree->list); i;
> + last = i, i = QTAILQ_NEXT(i, entry)) {
> + if (iova_tree_alloc_map_in_hole(last, i, iova_begin, iova_last,
> + map->size)) {
> + goto alloc;
> + }
> + }
> +
> + return IOVA_ERR_NOMEM;
> +
> +alloc:
> + map->iova = last ? last->map.iova + last->map.size + 1 : iova_begin;
> + return iova_tree_insert(tree, map);
> +}
Hi, Eugenio,
Have you tried with what Jason suggested previously?
https://lore.kernel.org/qemu-devel/CACGkMEtZAPd9xQTP_R4w296N_Qz7VuV1FLnb544fEVoYO0of+g@mail.gmail.com/
That solution still sounds very sensible to me even without the newly
introduced list in previous two patches.
IMHO we could move "DMAMap *previous, *this" into the IOVATreeAllocArgs*
stucture that was passed into the traverse func though, so it'll naturally work
with threading.
Or is there any blocker for it?
Thanks,
--
Peter Xu
- [PATCH 15/31] vdpa: Add vhost_svq_get_num, (continued)
- [PATCH 15/31] vdpa: Add vhost_svq_get_num, Eugenio Pérez, 2022/01/21
- [PATCH 16/31] vhost: pass queue index to vhost_vq_get_addr, Eugenio Pérez, 2022/01/21
- [PATCH 17/31] vdpa: adapt vhost_ops callbacks to svq, Eugenio Pérez, 2022/01/21
- [PATCH 18/31] vhost: Shadow virtqueue buffers forwarding, Eugenio Pérez, 2022/01/21
- [PATCH 19/31] utils: Add internal DMAMap to iova-tree, Eugenio Pérez, 2022/01/21
- [PATCH 21/31] util: Add iova_tree_alloc, Eugenio Pérez, 2022/01/21
- Re: [PATCH 21/31] util: Add iova_tree_alloc,
Peter Xu <=
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Eugenio Perez Martin, 2022/01/24
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Peter Xu, 2022/01/24
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Eugenio Perez Martin, 2022/01/25
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Peter Xu, 2022/01/27
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Eugenio Perez Martin, 2022/01/27
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Peter Xu, 2022/01/27
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Jason Wang, 2022/01/28
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Eugenio Perez Martin, 2022/01/28
- Re: [PATCH 21/31] util: Add iova_tree_alloc, Jason Wang, 2022/01/30
[PATCH 20/31] util: Store DMA entries in a list, Eugenio Pérez, 2022/01/21