From patchwork Tue Jul 21 23:51:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin KaFai Lau X-Patchwork-Id: 498370 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 A6F261402ED for ; Wed, 22 Jul 2015 09:51:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b=mAs2okay; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933966AbbGUXv0 (ORCPT ); Tue, 21 Jul 2015 19:51:26 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:64413 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933284AbbGUXvZ (ORCPT ); Tue, 21 Jul 2015 19:51:25 -0400 Received: from pps.filterd (m0004060 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t6LNoq3x016836 for ; Tue, 21 Jul 2015 16:51:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=v6ZkHm46TJQ3eg2eTpMR7mxwYKQxiPLuYOKB0YL15X4=; b=mAs2okayzNai5sh5kCA+CKbLhcCq29okBW3++V9xhSWyD2JA0VVRdRPhx1cJpQBATy7k 2VpNi/gDbcT4Fg5MH49bNkwTZo+yaIMD87bhvGtWHk6M5+xvwVmGQE2wVRWCegCJxZ1j dJBJ/BkxBWMNXGrZl2NSwGu8XM5uCQfVdps= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1vsypar3n7-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Tue, 21 Jul 2015 16:51:24 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB10.TheFacebook.com (192.168.16.20) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 21 Jul 2015 16:51:22 -0700 Received: from facebook.com (2401:db00:20:7029:face:0:33:0) by mx-out.facebook.com (10.223.101.97) with ESMTP id 6313fc4a300311e5ba1424be0595f910-e03fd2b0 for ; Tue, 21 Jul 2015 16:51:21 -0700 Received: by devbig242.prn2.facebook.com (Postfix, from userid 6611) id 7757D520188; Tue, 21 Jul 2015 16:51:20 -0700 (PDT) From: Martin KaFai Lau To: netdev CC: Kernel Team , Hannes Frederic Sowa Subject: [PATCH net-next] ipv6: Avoid rt6_probe() taking writer lock in the fast path Date: Tue, 21 Jul 2015 16:51:20 -0700 Message-ID: <1437522680-3515872-1-git-send-email-kafai@fb.com> X-Mailer: git-send-email 1.8.1 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151, 1.0.33, 0.0.0000 definitions=2015-07-22_01:2015-07-21, 2015-07-21, 1970-01-01 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The patch checks neigh->nud_state before acquiring the writer lock. Note that rt6_probe() is only used in CONFIG_IPV6_ROUTER_PREF. I also take this chance to re-arrange the code. 40 udpflood processes and a /64 gateway route are used. The gateway has NUD_PERMANENT. Each of them is run for 30s. At the end, the total number of finished sendto(): Before After 55M 95M Signed-off-by: Martin KaFai Lau Cc: Hannes Frederic Sowa --- net/ipv6/route.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 6090969..a6c6b5a 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -544,6 +544,7 @@ static void rt6_probe_deferred(struct work_struct *w) static void rt6_probe(struct rt6_info *rt) { + struct __rt6_probe_work *work; struct neighbour *neigh; /* * Okay, this does not seem to be appropriate @@ -558,34 +559,32 @@ static void rt6_probe(struct rt6_info *rt) rcu_read_lock_bh(); neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); if (neigh) { - write_lock(&neigh->lock); if (neigh->nud_state & NUD_VALID) goto out; - } - - if (!neigh || - time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) { - struct __rt6_probe_work *work; + work = NULL; + write_lock(&neigh->lock); + if (!(neigh->nud_state & NUD_VALID) && + time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) { + work = kmalloc(sizeof(*work), GFP_ATOMIC); + if (work) { + __neigh_set_probe_once(neigh); + } + } + write_unlock(&neigh->lock); + } else { work = kmalloc(sizeof(*work), GFP_ATOMIC); + } - if (neigh && work) - __neigh_set_probe_once(neigh); - - if (neigh) - write_unlock(&neigh->lock); + if (work) { + INIT_WORK(&work->work, rt6_probe_deferred); + work->target = rt->rt6i_gateway; + dev_hold(rt->dst.dev); + work->dev = rt->dst.dev; + schedule_work(&work->work); + } - if (work) { - INIT_WORK(&work->work, rt6_probe_deferred); - work->target = rt->rt6i_gateway; - dev_hold(rt->dst.dev); - work->dev = rt->dst.dev; - schedule_work(&work->work); - } - } else { out: - write_unlock(&neigh->lock); - } rcu_read_unlock_bh(); } #else