Looks good, thanks.

Ethan

On Mon, Apr 16, 2012 at 17:18, Ben Pfaff <b...@nicira.com> wrote:
> Usually a facet has exactly one subfacet that has the same lifetime as
> the facet.  Allocating both the facet and its subfacet in a single memory
> block improves performance.
>
> Signed-off-by: Ben Pfaff <b...@nicira.com>
> ---
>  ofproto/ofproto-dpif.c |   22 +++++++++++++++++++---
>  1 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
> index 674dbd9..8c89b50 100644
> --- a/ofproto/ofproto-dpif.c
> +++ b/ofproto/ofproto-dpif.c
> @@ -394,6 +394,11 @@ struct facet {
>     bool has_fin_timeout;        /* Actions include NXAST_FIN_TIMEOUT? */
>     tag_type tags;               /* Tags that would require revalidation. */
>     mirror_mask_t mirrors;       /* Bitmap of dependent mirrors. */
> +
> +    /* Storage for a single subfacet, to reduce malloc() time and space
> +     * overhead.  (A facet always has at least one subfacet and in the common
> +     * case has exactly one subfacet.) */
> +    struct subfacet one_subfacet;
>  };
>
>  static struct facet *facet_create(struct rule_dpif *,
> @@ -3859,16 +3864,25 @@ subfacet_create(struct facet *facet, enum 
> odp_key_fitness key_fitness,
>         subfacet_destroy(subfacet);
>     }
>
> -    subfacet = xzalloc(sizeof *subfacet);
> +    subfacet = (list_is_empty(&facet->subfacets)
> +                ? &facet->one_subfacet
> +                : xmalloc(sizeof *subfacet));
>     hmap_insert(&ofproto->subfacets, &subfacet->hmap_node, key_hash);
>     list_push_back(&facet->subfacets, &subfacet->list_node);
>     subfacet->facet = facet;
> -    subfacet->used = time_msec();
>     subfacet->key_fitness = key_fitness;
>     if (key_fitness != ODP_FIT_PERFECT) {
>         subfacet->key = xmemdup(key, key_len);
>         subfacet->key_len = key_len;
> +    } else {
> +        subfacet->key = NULL;
> +        subfacet->key_len = 0;
>     }
> +    subfacet->used = time_msec();
> +    subfacet->dp_packet_count = 0;
> +    subfacet->dp_byte_count = 0;
> +    subfacet->actions_len = 0;
> +    subfacet->actions = NULL;
>     subfacet->installed = false;
>     subfacet->initial_tci = initial_tci;
>
> @@ -3906,7 +3920,9 @@ subfacet_destroy__(struct subfacet *subfacet)
>     list_remove(&subfacet->list_node);
>     free(subfacet->key);
>     free(subfacet->actions);
> -    free(subfacet);
> +    if (subfacet != &facet->one_subfacet) {
> +        free(subfacet);
> +    }
>  }
>
>  /* Destroys 'subfacet', as with subfacet_destroy__(), and then if this was 
> the
> --
> 1.7.9
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to