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=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 C868CC43381 for ; Fri, 22 Feb 2019 03:52:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BAEA2086A for ; Fri, 22 Feb 2019 03:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726527AbfBVDwf (ORCPT ); Thu, 21 Feb 2019 22:52:35 -0500 Received: from m97179.mail.qiye.163.com ([220.181.97.179]:58766 "EHLO m97179.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbfBVDwf (ORCPT ); Thu, 21 Feb 2019 22:52:35 -0500 Received: from 10.19.61.167master (unknown [123.59.132.129]) by m97179.mail.qiye.163.com (Hmail) with ESMTPA id D9A6FE01714; Fri, 22 Feb 2019 11:52:30 +0800 (CST) From: wenxu@ucloud.cn To: davem@davemloft.net Cc: netdev@vger.kernel.org Subject: [PATCH net-next] route: Add a new fib_multipath_hash_policy base on cpu id for tunnel packet Date: Fri, 22 Feb 2019 11:52:29 +0800 Message-Id: <1550807549-22720-1-git-send-email-wenxu@ucloud.cn> X-Mailer: git-send-email 1.8.3.1 X-HM-Spam-Status: e1kIGBQJHllBS1VLV1koWUFJQjdXWS1ZQUlXWQkOFx4IWUFZMjUtOjcyP0 FLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OBg6Fhw*SjlCLw8xUSEoGRk3 ITAKChVVSlVKTk5LQ0tMTk5KS0lLVTMWGhIXVQweFQMOOw4YFxQOH1UYFUVZV1kSC1lBWUpJSFVO QlVKSElVSklCWVdZCAFZQUlMSk43Bg++ X-HM-Tid: 0a6913554bd820bdkuqyd9a6fe01714 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: wenxu Current fib_multipath_hash_policy can make hash based on the L3 or L4. But it only work on the outer IP. So a specific tunnel always has the same hash value. But a specific tunnel may contain so many inner connection. However there is no good ways for tunnel packet. A specific tunnel route based on the percpu dst_cache, It will not lookup route table each packet. This patch provide a based cpu id hash policy. The different connection run on differnt cpu and There will differnet hash value for percpu dst_cache. Signed-off-by: wenxu --- net/ipv4/route.c | 6 ++++++ net/ipv4/sysctl_net_ipv4.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index ecc12a7..6cf2fd4 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1821,6 +1821,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, const struct sk_buff *skb, struct flow_keys *flkeys) { struct flow_keys hash_keys; + u32 cpu = 0; u32 mhash; switch (net->ipv4.sysctl_fib_multipath_hash_policy) { @@ -1834,6 +1835,8 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.addrs.v4addrs.dst = fl4->daddr; } break; + case 2: + cpu = smp_processor_id() + 1; case 1: /* skb is currently provided only when forwarding */ if (skb) { @@ -1870,6 +1873,9 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, } mhash = flow_hash_from_keys(&hash_keys); + if (cpu) + mhash = jhash_2words(mhash, cpu, 0); + return mhash >> 1; } #endif /* CONFIG_IP_ROUTE_MULTIPATH */ diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index ba0fc4b..708bbbb 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -951,7 +951,7 @@ static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write, .mode = 0644, .proc_handler = proc_fib_multipath_hash_policy, .extra1 = &zero, - .extra2 = &one, + .extra2 = &two, }, #endif { -- 1.8.3.1