From patchwork Fri Aug 3 05:45:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 174889 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1F7542C0093 for ; Fri, 3 Aug 2012 15:45:36 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751079Ab2HCFpe (ORCPT ); Fri, 3 Aug 2012 01:45:34 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:51420 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794Ab2HCFpd (ORCPT ); Fri, 3 Aug 2012 01:45:33 -0400 Received: by weyx8 with SMTP id x8so177840wey.19 for ; Thu, 02 Aug 2012 22:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; bh=OJVo6aaNwAs+KUMo6KuZaXaNWB4SYecA11R/0fH5UA8=; b=e1t9AKg1j7ib9rfomg6vmUDVTOKNRWjw+jlR0HAhmziJE8ToBKr/IVZ2vgg1jTAov1 q9QVbqaxBsBzrRb/NDrtLXoZ9a8qd2cFWpFWmHcv0qZyKwo1KgI55lffzrYgbhnIWRKR bAmB1PwxKwvKVS38wvrghzgtSj7Cu/biGFHV4l+EMM2/ekxk4V7dIaIFnpjMdZ1BLCrJ pSyQADPE1hzO3T3BuEP6tO71xOwUdbultg2LdO6KM8LAv1eTTx/JNzlxiuuCsHtwibS/ /Gvpq6u76kL/c1hesXxerDtUfJav19stpNYxp4pnLUyR3DHUWYkpyUbAtr5IU+O/Arf+ nlew== Received: by 10.180.81.193 with SMTP id c1mr10393569wiy.12.1343972732055; Thu, 02 Aug 2012 22:45:32 -0700 (PDT) Received: from [172.30.42.18] (171.237.66.86.rev.sfr.net. [86.66.237.171]) by mx.google.com with ESMTPS id el6sm37587698wib.8.2012.08.02.22.45.30 (version=SSLv3 cipher=OTHER); Thu, 02 Aug 2012 22:45:30 -0700 (PDT) Subject: Re: [PATCH 1/2] net: Allow to create links with given ifindex From: Eric Dumazet To: David Miller Cc: ebiederm@xmission.com, xemul@parallels.com, netdev@vger.kernel.org In-Reply-To: <20120802.162601.2080519313891137444.davem@davemloft.net> References: <50179F66.1000604@parallels.com> <878ve0dtw3.fsf@xmission.com> <1343903310.9299.184.camel@edumazet-glaptop> <20120802.162601.2080519313891137444.davem@davemloft.net> Date: Fri, 03 Aug 2012 07:45:29 +0200 Message-ID: <1343972729.9299.596.camel@edumazet-glaptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, 2012-08-02 at 16:26 -0700, David Miller wrote: > From: Eric Dumazet > Date: Thu, 02 Aug 2012 12:28:30 +0200 > > > Strange because I see no false sharing on this ifindex location for > > loopback device. > > Are you sure netdev->rx_dropped isn't being incremented? That appears > as if it would land on the same cache line as netdev->ifindex. > Yes I am sure (by the way my output device was dummy0, not lo, but its the same for the case here) offsetof(struct net_device, features)=0x80 ... (all features are mostly read only) offsetof(struct net_device, ifindex)=0xa0 struct net_device_stats stats; is untouched on dummy device offsetof(struct net_device, rx_dropped)=0x160 So thats only the dereference done million times per second that show in the profiles, even if cache lines are clean and in cpu cache. I see that even more clear in the IN_DEV_ROUTE_LOCALNET(in_dev) macro in ip_route_input_slow(), doing so many derefs : Its actually faster to avoid it, if we already have the net pointer in hand : IN_DEV_NET_ROUTE_LOCALNET(in_dev, net) --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index 67f9dda..d032780 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -104,9 +104,14 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev) #define IN_DEV_ANDCONF(in_dev, attr) \ (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr) && \ IN_DEV_CONF_GET((in_dev), attr)) -#define IN_DEV_ORCONF(in_dev, attr) \ - (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr) || \ + +#define IN_DEV_NET_ORCONF(in_dev, net, attr) \ + (IPV4_DEVCONF_ALL(net, attr) || \ IN_DEV_CONF_GET((in_dev), attr)) + +#define IN_DEV_ORCONF(in_dev, attr) \ + IN_DEV_NET_ORCONF(in_dev, dev_net(in_dev->dev), attr) + #define IN_DEV_MAXCONF(in_dev, attr) \ (max(IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr), \ IN_DEV_CONF_GET((in_dev), attr))) @@ -133,6 +138,8 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev) IN_DEV_ORCONF((in_dev), \ PROMOTE_SECONDARIES) #define IN_DEV_ROUTE_LOCALNET(in_dev) IN_DEV_ORCONF(in_dev, ROUTE_LOCALNET) +#define IN_DEV_NET_ROUTE_LOCALNET(in_dev, net) \ + IN_DEV_NET_ORCONF(in_dev, net, ROUTE_LOCALNET) #define IN_DEV_RX_REDIRECTS(in_dev) \ ((IN_DEV_FORWARD(in_dev) && \ diff --git a/net/ipv4/route.c b/net/ipv4/route.c index e4ba974..5e88e3b 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1587,13 +1587,11 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, if (ipv4_is_zeronet(daddr)) goto martian_destination; - if (likely(!IN_DEV_ROUTE_LOCALNET(in_dev))) { - if (ipv4_is_loopback(daddr)) - goto martian_destination; + if (ipv4_is_loopback(daddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net)) + goto martian_destination; - if (ipv4_is_loopback(saddr)) - goto martian_source; - } + if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net)) + goto martian_source; /* * Now we are ready to route packet.