[Mesa-dev] [PATCH 4/7] nir/phi_builder: Use slab allocator for temporary data structures

Jason Ekstrand jason at jlekstrand.net
Wed Nov 21 19:49:53 UTC 2018


The linear_alloc stuff that marek added to ralloc also does slab allocation
and can be parented off a ralloc context.  Did you consider that?

On Tue, Nov 20, 2018 at 6:40 PM Ian Romanick <idr at freedesktop.org> wrote:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> This pass allocates a large number of two different data structures.
> This data only lives during the pass.  Use the slab allocator to reduce
> the memory overhead (from 5 pointers + possible padding per allocation
> to nearly zero per allocation) and potentially improve performance.
>
> NOTE: I have not measured the performace delta across this patch
> individually.
>
> Changes in peak memory usage according to Valgrind massif:
>
> mean soft fp64 using uint64:   1,343,998,123 => 1,343,998,123
> gfxbench5 aztec ruins high 11:    62,415,414 =>    62,415,414
> deus ex mankind divided 148:      62,317,965 =>    62,317,965
> deus ex mankind divided 2890:     72,585,466 =>    72,603,614
> dirt showdown 676:                75,203,703 =>    72,450,311
> dolphin ubershaders 210:          83,185,248 =>    81,041,040
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/nir/nir_phi_builder.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/src/compiler/nir/nir_phi_builder.c
> b/src/compiler/nir/nir_phi_builder.c
> index 36ab9888f48..4d4d81fcd59 100644
> --- a/src/compiler/nir/nir_phi_builder.c
> +++ b/src/compiler/nir/nir_phi_builder.c
> @@ -23,6 +23,7 @@
>
>  #include "nir_phi_builder.h"
>  #include "nir/nir_vla.h"
> +#include "util/slab.h"
>
>  struct nir_phi_builder {
>     nir_shader *shader;
> @@ -60,6 +61,8 @@ struct nir_phi_builder {
>      *    one of the defs provided by
> nir_phi_builder_value_set_blocK_def().
>      */
>     struct hash_table *value_block_def_hash;
> +   struct slab_mempool value_pool;
> +   struct slab_mempool key_pool;
>  };
>
>  #define NEEDS_PHI ((nir_ssa_def *)(intptr_t)-1)
> @@ -134,6 +137,11 @@ nir_phi_builder_create(nir_function_impl *impl)
>
>  phi_builder_key_hash,
>
>  phi_builder_key_equals);
>
> +   slab_create(&pb->value_pool, sizeof(struct nir_phi_builder_value),
> +               (16 * 1024 - sizeof(void *)) / sizeof(struct
> nir_phi_builder_value));
> +   slab_create(&pb->key_pool, sizeof(struct phi_builder_key),
> +               (16 * 1024 - sizeof(void *)) / sizeof(struct
> phi_builder_key));
> +
>     return pb;
>  }
>
> @@ -144,7 +152,7 @@ nir_phi_builder_add_value(struct nir_phi_builder *pb,
> unsigned num_components,
>     struct nir_phi_builder_value *val;
>     unsigned i, w_start = 0, w_end = 0;
>
> -   val = rzalloc_size(pb, sizeof(*val));
> +   val = slab_alloc_st(&pb->value_pool);
>     val->builder = pb;
>     val->num_components = num_components;
>     val->bit_size = bit_size;
> @@ -211,7 +219,7 @@ nir_phi_builder_value_set_block_def(struct
> nir_phi_builder_value *val,
>     if (he != NULL) {
>        he->data = def;
>     } else {
> -      struct phi_builder_key *kp = ralloc(val->builder, struct
> phi_builder_key);
> +      struct phi_builder_key *kp = slab_alloc_st(&val->builder->key_pool);
>
>        kp->val = k.val;
>        kp->block_index = k.block_index;
> @@ -362,5 +370,9 @@ nir_phi_builder_finish(struct nir_phi_builder *pb)
>        }
>     }
>
> +   slab_flush_st(&pb->value_pool);
> +   slab_flush_st(&pb->key_pool);
> +   slab_destroy(&pb->value_pool);
> +   slab_destroy(&pb->key_pool);
>     ralloc_free(pb);
>  }
> --
> 2.14.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20181121/12462656/attachment-0001.html>


More information about the mesa-dev mailing list