[Mesa-dev] [PATCH] util/slab: add slab_free_fast()

Jason Ekstrand jason at jlekstrand.net
Wed Aug 7 23:58:34 UTC 2019


Do you have any actual numbers for this?

On August 7, 2019 17:02:22 Rob Clark <robdclark at gmail.com> wrote:

> From: Rob Clark <robdclark at chromium.org>
>
> I noticed slab_free() showing up at the top of perf results in
> gl_driver2, due to "streaming" GPU state objects, which are allocated
> and destroyed within a single draw call.
>
> In this case, it is guaranteed that we free on the same child pool,
> from the same (only) thread accessing the child pool.  So add a faster,
> but more restricted version of slab_free() to cut the overhead.
>
> Signed-off-by: Rob Clark <robdclark at chromium.org>
> ---
> src/util/slab.c | 20 ++++++++++++++++++++
> src/util/slab.h |  1 +
> 2 files changed, 21 insertions(+)
>
> diff --git a/src/util/slab.c b/src/util/slab.c
> index 62634034fdc..21076a80238 100644
> --- a/src/util/slab.c
> +++ b/src/util/slab.c
> @@ -276,6 +276,26 @@ void slab_free(struct slab_child_pool *pool, void *ptr)
>    }
> }
>
> +/**
> + * Similar to slab_free(), except that freeing an object in a different pool
> + * from the one it was allocated from is *not* allowed.
> + */
> +void slab_free_fast(struct slab_child_pool *pool, void *ptr)
> +{
> +   struct slab_element_header *elt = ((struct slab_element_header*)ptr - 1);
> +
> +   CHECK_MAGIC(elt, SLAB_MAGIC_ALLOCATED);
> +   SET_MAGIC(elt, SLAB_MAGIC_FREE);
> +
> +   assert(p_atomic_read(&elt->owner) == (intptr_t)pool);
> +
> +   /* This is the simple case: The caller guarantees that we can safely
> +    * access the free list.
> +    */
> +   elt->next = pool->free;
> +   pool->free = elt;
> +}
> +
> /**
>  * Allocate an object from the slab. Single-threaded (no mutex).
>  */
> diff --git a/src/util/slab.h b/src/util/slab.h
> index 5a25adaf7f4..9748cd95858 100644
> --- a/src/util/slab.h
> +++ b/src/util/slab.h
> @@ -78,6 +78,7 @@ void slab_create_child(struct slab_child_pool *pool,
> void slab_destroy_child(struct slab_child_pool *pool);
> void *slab_alloc(struct slab_child_pool *pool);
> void slab_free(struct slab_child_pool *pool, void *ptr);
> +void slab_free_fast(struct slab_child_pool *pool, void *ptr);
>
> struct slab_mempool {
>    struct slab_parent_pool parent;
> --
> 2.21.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev





More information about the mesa-dev mailing list