Subject: Re: [PATCH bpf-next v5 3/6] xdp: Add devmap_hash map type for looking up devices by hashed index

From: Jesper Dangaard Brouer <[email-masked]>
Date: Mon, 29 Jul 2019 18:16:12 +0200

On Fri, 26 Jul 2019 18:06:55 +0200
Toke Høiland-Jørgensen <[email-masked]> wrote:

> From: Toke Høiland-Jørgensen <[email-masked]>
> 
> A common pattern when using xdp_redirect_map() is to create a device map
> where the lookup key is simply ifindex. Because device maps are arrays,
> this leaves holes in the map, and the map has to be sized to fit the
> largest ifindex, regardless of how many devices actually are actually
> needed in the map.
> 
> This patch adds a second type of device map where the key is looked up
> using a hashmap, instead of being used as an array index. This allows maps
> to be densely packed, so they can be smaller.
> 
> Signed-off-by: Toke Høiland-Jørgensen <[email-masked]>
> Acked-by: Yonghong Song <[email-masked]>

Acked-by: Jesper Dangaard Brouer <[email-masked]>

[...]
> +static inline struct hlist_head *dev_map_index_hash(struct bpf_dtab *dtab,
> +						    int idx)
> +{
> +	return &dtab->dev_index_head[idx & (dtab->n_buckets - 1)];
> +}

I was about to complain about, that you are not using a pre-calculated
MASK value, instead of doing the -1 operation each time.  But I looked
at the ASM code, and the LEA operation used does the -1 operation in
the same instruction, so I guess this makes no performance difference.

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer