The important part is the change of the condition to <= 0. Otherwise the loop
gets stuck never actually growing the pool.
The change in the aux-need calculation guarantees max 2 iterations, and
avoids wasting memory in case a smaller item can't fit into a relatively larger
pool.
Reviewed-by: Bruno Jiménez <brunojimen@gmail.com>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
int64_t need = item->size_in_dw + 2048 -
(pool->size_in_dw - allocated);
- if (need < 0) {
- need = pool->size_in_dw / 10;
+ if (need <= 0) {
+ /* There's enough free space, but it's too
+ * fragmented. Assume half of the item can fit
+ * int the last chunk */
+ need = (item->size_in_dw / 2) + ITEM_ALIGNMENT;
}
need = align(need, ITEM_ALIGNMENT);