[Mesa-dev] [PATCH v2 3.2/7] util/slab: Add function to flush allocations from a child pool
Haehnle, Nicolai
Nicolai.Haehnle at amd.com
Wed Nov 28 09:38:06 UTC 2018
Both patches:
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
On 26.11.18 20:18, Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Ralloc has a feature that all allocations from a temporary memory
> context can be whisked away in a single call without fear of leaks. As
> the slab allocator is designed for use in multhreaded scenarios with a
> child pool per CPU, it lacks this feature. However, many users will be
> single threaded with a single child pool. For these users, we can have
> our cake and eat it too.
>
> v2: Fix incorrect pointer types in an assertion. Notice by Nicolai.
> Rename slab_mempool parameter.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Nicolai Hähnle <nicolai.haehnle at amd.com>
> ---
> src/util/slab.c | 21 +++++++++++++++++++++
> src/util/slab.h | 1 +
> 2 files changed, 22 insertions(+)
>
> diff --git a/src/util/slab.c b/src/util/slab.c
> index 5477c75d443..c11b485e587 100644
> --- a/src/util/slab.c
> +++ b/src/util/slab.c
> @@ -172,6 +172,27 @@ void slab_destroy_child(struct slab_child_pool *pool)
> pool->parent = NULL;
> }
>
> +/**
> + * Flush all allocations from a pool. Single-threaded (no mutex).
> + */
> +void
> +slab_flush_st(struct slab_mempool *mempool)
> +{
> + struct slab_child_pool *const pool = &mempool->child;
> +
> + assert(pool->migrated == NULL);
> + assert(pool->parent == &mempool->parent);
> +
> + while (pool->pages) {
> + struct slab_page_header *page = pool->pages;
> + pool->pages = page->u.next;
> +
> + free(page);
> + }
> +
> + pool->free = NULL;
> +}
> +
> static bool
> slab_add_new_page(struct slab_child_pool *pool)
> {
> diff --git a/src/util/slab.h b/src/util/slab.h
> index 5a25adaf7f4..6f309504a5f 100644
> --- a/src/util/slab.h
> +++ b/src/util/slab.h
> @@ -90,5 +90,6 @@ void slab_create(struct slab_mempool *mempool,
> void slab_destroy(struct slab_mempool *mempool);
> void *slab_alloc_st(struct slab_mempool *mempool);
> void slab_free_st(struct slab_mempool *mempool, void *ptr);
> +void slab_flush_st(struct slab_mempool *mempool);
>
> #endif
>
More information about the mesa-dev
mailing list