panfrost: Keep cached BOs mmap'd
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 19 May 2020 19:06:52 +0000 (15:06 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 21 May 2020 18:43:31 +0000 (14:43 -0400)
It doesn't make sense to munmap/mmap repeatedly; they're mapped GPU-side
anyway. So just munmap on free, which will happen in low-mem regardless.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5124>

src/panfrost/encoder/pan_bo.c

index 32fc84e13637b81cd82143d2548c4ef0a24b346f..a663d35d5b832adeaa2ac3c580dcaf442c6ed28f 100644 (file)
@@ -90,6 +90,11 @@ panfrost_bo_free(struct panfrost_bo *bo)
         struct drm_gem_close gem_close = { .handle = bo->gem_handle };
         int ret;
 
+        if (bo->cpu && os_munmap((void *) (uintptr_t)bo->cpu, bo->size)) {
+                perror("munmap");
+                abort();
+        }
+
         ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
         if (ret) {
                 fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %m\n");
@@ -344,20 +349,6 @@ panfrost_bo_mmap(struct panfrost_bo *bo)
         }
 }
 
-static void
-panfrost_bo_munmap(struct panfrost_bo *bo)
-{
-        if (!bo->cpu)
-                return;
-
-        if (os_munmap((void *) (uintptr_t)bo->cpu, bo->size)) {
-                perror("munmap");
-                abort();
-        }
-
-        bo->cpu = NULL;
-}
-
 struct panfrost_bo *
 panfrost_bo_create(struct panfrost_device *dev, size_t size,
                    uint32_t flags)
@@ -436,9 +427,6 @@ panfrost_bo_unreference(struct panfrost_bo *bo)
         if (p_atomic_read(&bo->refcnt) == 0) {
                 _mesa_set_remove_key(bo->dev->active_bos, bo);
 
-                /* When the reference count goes to zero, we need to cleanup */
-                panfrost_bo_munmap(bo);
-
                 /* Rather than freeing the BO now, we'll cache the BO for later
                  * allocations if we're allowed to.
                  */