Mesa (main): aux/pb: add a tolerance for reclaim failure

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 15 18:20:57 UTC 2021


Module: Mesa
Branch: main
Commit: 3d6c8829f54e52ae39b91b18d49acccf47755320
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3d6c8829f54e52ae39b91b18d49acccf47755320

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Oct 13 13:34:30 2021 -0400

aux/pb: add a tolerance for reclaim failure

originally, a slab attempts to reclaim a single bo. there are two outcomes
to this which can occur:
* the bo is reclaimed
* the bo is not reclaimed

if the bo is reclaimed, great.

if the bo is not reclaimed, it remains at the head of the list until it can
be reclaimed. this means that any bo with a "long" work queue which makes it
into a slab will effectively kill the entire slab. in a benchmarking scenario,
this can occur in rapid succession, and every slab will get 1-2 suballocations
before it reaches a bo that blocks long enough for a new slab to be needed.

the inevitable result of this scenario is that all memory is depleted almost instantly,
all because pb assumes that if the first bo in the reclaim list isn't ready, none of them
can be ready

for drivers like radeonsi, this happens to be a fine assumption

for drivers like zink, this is entirely not workable and explodes the gpu

Cc: mesa-stable

Reviewed-by: Witold Baryluk <witold.baryluk at gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Tested-by: Witold Baryluk <witold.baryluk at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13345>

---

 src/gallium/auxiliary/pipebuffer/pb_slab.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/pipebuffer/pb_slab.c b/src/gallium/auxiliary/pipebuffer/pb_slab.c
index edb52dca8c7..865ae92ee7f 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_slab.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_slab.c
@@ -71,17 +71,27 @@ pb_slab_reclaim(struct pb_slabs *slabs, struct pb_slab_entry *entry)
    }
 }
 
+#define MAX_FAILED_RECLAIMS 2
+
 static void
 pb_slabs_reclaim_locked(struct pb_slabs *slabs)
 {
-   while (!list_is_empty(&slabs->reclaim)) {
-      struct pb_slab_entry *entry =
-         LIST_ENTRY(struct pb_slab_entry, slabs->reclaim.next, head);
-
-      if (!slabs->can_reclaim(slabs->priv, entry))
+   struct pb_slab_entry *entry, *next;
+   unsigned num_failed_reclaims = 0;
+   LIST_FOR_EACH_ENTRY_SAFE(entry, next, &slabs->reclaim, head) {
+      if (slabs->can_reclaim(slabs->priv, entry)) {
+         pb_slab_reclaim(slabs, entry);
+      /* there are typically three possible scenarios when reclaiming:
+       * - all entries reclaimed
+       * - no entries reclaimed
+       * - all but one entry reclaimed
+       * in the scenario where a slab contains many (10+) unused entries,
+       * the driver should not walk the entire list, as this is likely to
+       * result in zero reclaims if the first few entries fail to reclaim
+       */
+      } else if (num_failed_reclaims++ > MAX_FAILED_RECLAIMS) {
          break;
-
-      pb_slab_reclaim(slabs, entry);
+      }
    }
 }
 



More information about the mesa-commit mailing list