aux/pb: add a new slab alloc function for reclaiming all bo objects
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 17 Nov 2021 21:43:55 +0000 (16:43 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 18 Nov 2021 21:22:30 +0000 (21:22 +0000)
sometimes a driver might want to always reclaim all bo objects in the course
of allocating a new bo. this is useful when it's known that a given memory
heap is very small and will likely need to keep its usage minimized

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13850>

src/gallium/auxiliary/pipebuffer/pb_slab.c
src/gallium/auxiliary/pipebuffer/pb_slab.h

index 83c1a59..cbbef09 100644 (file)
@@ -95,6 +95,17 @@ pb_slabs_reclaim_locked(struct pb_slabs *slabs)
    }
 }
 
+static void
+pb_slabs_reclaim_all_locked(struct pb_slabs *slabs)
+{
+   struct pb_slab_entry *entry, *next;
+   LIST_FOR_EACH_ENTRY_SAFE(entry, next, &slabs->reclaim, head) {
+      if (slabs->can_reclaim(slabs->priv, entry)) {
+         pb_slab_reclaim(slabs, entry);
+      }
+   }
+}
+
 /* Allocate a slab entry of the given size from the given heap.
  *
  * This will try to re-use entries that have previously been freed. However,
@@ -105,7 +116,7 @@ pb_slabs_reclaim_locked(struct pb_slabs *slabs)
  * Note that slab_free can also be called by this function.
  */
 struct pb_slab_entry *
-pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap)
+pb_slab_alloc_reclaimed(struct pb_slabs *slabs, unsigned size, unsigned heap, bool reclaim_all)
 {
    unsigned order = MAX2(slabs->min_order, util_logbase2_ceil(size));
    unsigned group_index;
@@ -136,8 +147,12 @@ pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap)
     * entries, try reclaiming entries.
     */
    if (list_is_empty(&group->slabs) ||
-       list_is_empty(&LIST_ENTRY(struct pb_slab, group->slabs.next, head)->free))
-      pb_slabs_reclaim_locked(slabs);
+       list_is_empty(&LIST_ENTRY(struct pb_slab, group->slabs.next, head)->free)) {
+      if (reclaim_all)
+         pb_slabs_reclaim_all_locked(slabs);
+      else
+         pb_slabs_reclaim_locked(slabs);
+   }
 
    /* Remove slabs without free entries. */
    while (!list_is_empty(&group->slabs)) {
@@ -174,6 +189,12 @@ pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap)
    return entry;
 }
 
+struct pb_slab_entry *
+pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap)
+{
+   return pb_slab_alloc_reclaimed(slabs, size, heap, false);
+}
+
 /* Free the given slab entry.
  *
  * The entry may still be in use e.g. by in-flight command submissions. The
index c6b115e..e8e8f76 100644 (file)
@@ -135,6 +135,9 @@ struct pb_slabs
 };
 
 struct pb_slab_entry *
+pb_slab_alloc_reclaimed(struct pb_slabs *slabs, unsigned size, unsigned heap, bool reclaim_all);
+
+struct pb_slab_entry *
 pb_slab_alloc(struct pb_slabs *slabs, unsigned size, unsigned heap);
 
 void