From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D018C43381 for ; Thu, 21 Feb 2019 21:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DBDEC2080F for ; Thu, 21 Feb 2019 21:49:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="lUKCrTg+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726381AbfBUVtm (ORCPT ); Thu, 21 Feb 2019 16:49:42 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:38759 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbfBUVtm (ORCPT ); Thu, 21 Feb 2019 16:49:42 -0500 Received: by mail-qt1-f196.google.com with SMTP id s1so178982qte.5 for ; Thu, 21 Feb 2019 13:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=tGi7IIa8NICo1FrJogB91jrqsN1kWF+cfsmn1xXbS2M=; b=lUKCrTg+it2KD8C7HQo19aksxxYBtlsEndBNDpuvvsegZlqP8VGPfSajKT/0Qh3Gqq BThfWA0kPTd57E3K86+E/3SN+wKtD6S+3ETFzO8daEAxlQ2H5g0ZYQhIj2brALpfjTaX v6tM8IfVY+RDKvzfgACM6bDi9me5dl7dlWY3l/vSrh+kNA+5wLoKtkZcARYiYW+aLvR1 S7yPSOO76ZrBPbkfu/otFR4k6rbxhZvqpNfhkPdtioCDvV2V5qrVWMyT7yHlOOAyiRXg bRbpky2E9nTlIKXa+OW7Qyp33s1DWhIfSw2c2lJppI7UNzG+Ey1zsaJu8qBysbxlapw1 oi6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=tGi7IIa8NICo1FrJogB91jrqsN1kWF+cfsmn1xXbS2M=; b=nnv9Q1LFcsETZK7no7LC+b2+5sHNaVMiV5IJWss132vQG05nQpVeOElieHxP9UyUSl TDZKt3jBe1JjT6y6nnrEtoyNp5gjTNfg1nsRxZbK9v/rJ1pA8bCQGMw7klKbjOQwnYs9 marzCCvyGPe9MUs2yH+jz9Ly5X3J42Ba8uSK6ET0FLbirUrZ4CX547ZMvqXDWU/XUTgc z4/qU+W2QtN0onVqFqOPEZwscnLjplBxDVXn8pepQvyzOyZM6G9nClsFRCMLiByFhQsQ /6S8dDqX50m2n19XbZluoRtvJNFXhaarcLwU0HYdnqMmROzUJWiWkEvRHaIkqNwuHSr7 oUjA== X-Gm-Message-State: AHQUAuZGAuVFp9dgHUoONCYnPZBd0O/ywfQM2R0DhPyNI/0XxmgG+Sx7 ai83NAAvjto7VuPQqt6+vwlVRO7bQOA= X-Google-Smtp-Source: AHgI3IbHOQE5oMY4kfdS63xDC3PVIHQPp7wKYi51zd2ucVdXP6Xj0lghdlGYylikWO3lzas0PidD7w== X-Received: by 2002:ac8:186f:: with SMTP id n44mr486715qtk.279.1550785781042; Thu, 21 Feb 2019 13:49:41 -0800 (PST) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id 32sm3420qto.55.2019.02.21.13.49.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Feb 2019 13:49:40 -0800 (PST) Date: Thu, 21 Feb 2019 13:49:33 -0800 From: Jakub Kicinski To: Toke =?UTF-8?B?SMO4aWxhbmQtSsO4cmdlbnNlbg==?= Cc: David Miller , netdev@vger.kernel.org, Jesper Dangaard Brouer , Daniel Borkmann , Alexei Starovoitov Subject: Re: [PATCH net-next 2/2] xdp: Add devmap_idx map type for looking up devices by ifindex Message-ID: <20190221134923.53c40b11@cakuba.netronome.com> In-Reply-To: <155075021407.13610.6656977312753058829.stgit@alrua-x1> References: <155075021399.13610.12521373406832889226.stgit@alrua-x1> <155075021407.13610.6656977312753058829.stgit@alrua-x1> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, 21 Feb 2019 12:56:54 +0100, Toke H=C3=B8iland-J=C3=B8rgensen wrote: > 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. >=20 > This patch adds a second type of device map where the key is interpreted = as > an ifindex and looked up using a hashmap, instead of being used as an arr= ay > index. This leads to maps being densely packed, so they can be smaller. >=20 > The default maps used by xdp_redirect() are changed to use the new map > type, which means that xdp_redirect() is no longer limited to ifindex < 6= 4, > but instead to 64 total simultaneous interfaces per network namespace. Th= is > also provides an easy way to compare the performance of devmap and > devmap_idx: >=20 > xdp_redirect_map (devmap): 8394560 pkt/s > xdp_redirect (devmap_idx): 8179480 pkt/s >=20 > Difference: 215080 pkt/s or 3.1 nanoseconds per packet. Could you share what the ifindex mix was here, to arrive at these numbers? How does it compare to using an array but not keying with ifindex? > Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen > +static int dev_map_idx_update_elem(struct bpf_map *map, void *key, void = *value, > + u64 map_flags) > +{ > + struct bpf_dtab *dtab =3D container_of(map, struct bpf_dtab, map); > + struct bpf_dtab_netdev *dev, *old_dev; > + u32 idx =3D *(u32 *)key; > + u32 val =3D *(u32 *)value; > + u32 bit; > + > + if (unlikely(map_flags > BPF_EXIST)) > + return -EINVAL; > + if (unlikely(map_flags =3D=3D BPF_NOEXIST)) > + return -EEXIST; > + > + old_dev =3D __dev_map_idx_lookup_elem(map, idx); > + if (!val) { > + if (!old_dev) > + return 0; IMHO this is a fairly strange mix of array and hashmap semantics. I think you should stick to hashmap behaviour AFA flags and update/delete goes. > + xchg(&dtab->netdev_map[old_dev->bit], NULL); > + spin_lock(&dtab->index_lock); > + hlist_del_rcu(&old_dev->index_hlist); > + spin_unlock(&dtab->index_lock); > + > + clear_bit_unlock(old_dev->bit, dtab->bits_used); > + call_rcu(&old_dev->rcu, __dev_map_entry_free); > + } else { > + if (idx !=3D val) > + return -EINVAL; > + if (old_dev) > + return 0; > + if (!__dev_map_find_bit(dtab, &bit)) > + return -E2BIG; > + dev =3D __dev_map_alloc_node(dtab, idx, bit); > + if (IS_ERR(dev)) > + return PTR_ERR(dev); > + > + xchg(&dtab->netdev_map[bit], dev); > + spin_lock(&dtab->index_lock); > + hlist_add_head_rcu(&dev->index_hlist, > + dev_map_index_hash(dtab, dev->ifindex)); > + spin_unlock(&dtab->index_lock); > + } > + return 0; > +} > + > const struct bpf_map_ops dev_map_ops =3D { > .map_alloc =3D dev_map_alloc, > .map_free =3D dev_map_free,