From patchwork Tue Mar 26 15:30:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 1065727 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=arista.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=arista.com header.i=@arista.com header.b="dJR+zona"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44TFTH1jPLz9sSq for ; Wed, 27 Mar 2019 02:30:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732090AbfCZPac (ORCPT ); Tue, 26 Mar 2019 11:30:32 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:37693 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726285AbfCZPab (ORCPT ); Tue, 26 Mar 2019 11:30:31 -0400 Received: by mail-ed1-f66.google.com with SMTP id v21so11148659edq.4 for ; Tue, 26 Mar 2019 08:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tThm/x2p9W+i8tJU44hM6YhgVB9o3kMMPHMITeV1Iuc=; b=dJR+zona8sRJfBWWxpFZXMnyPOVdlg/YoP59nDbOjIlHopFKxHy6TM6lISzy+x27wE K5DgnJ31nun8ca4qyHllwI+u2lQUSIzPvjS7eeIIKHxTNSMKn/SPwltQdpbOqVgCrC4t t9Tv/iFQgdtieeSKGMLbH1dCWY2EdrnWKDRSnm9M39qVo4Z3pI1himljyKRWF30t8RTa FDf52igzEuhbxWkhh/TYYzGvAg76VxWs8dwY/vsC6Hq2TRlhKBkAHX5rgA3mtDB/2QGB bMMVrIkheMHTd2aomLDPqZoy6v77ynKGzRDG7TJ0X3sDAG3QICsh5W4WpQ+t6U1mIPoX CqXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tThm/x2p9W+i8tJU44hM6YhgVB9o3kMMPHMITeV1Iuc=; b=cT46iDGky5foQ+Of1wzuK/UnMO96f/eVysaFvETmphlE2kxxRLS9AsIwqLVMtBOA2w VxhAn/f7jxWc0gy0/ra+Ow2RZu6xPyvCGgEZW2Kn/ascCTvJp0DoFSJo9kZGGFwenPv9 6pWVoymGTsRuf02K2K/a43wpKcx4xUAyS3TZhV076iJ/jtmNbhFiG0qn5Oiy5atqYTf4 291Qa1Yt+1m6Kh9tcAANb6YIyuKEnTf+c0CiewFrrMWaDNtPHOZN4tVAeaaDk89ESYoi 3nRzlbXVzFNjYhVFu9zhq3tvAE4yLZGrcYRvi6sQq4BzNDSYbkmTbyTFOUWwycz7hKIf EviQ== X-Gm-Message-State: APjAAAXygWuvjEuDneeKjYqIgJUW9FT57caHWJ+rc7vramTcdkKhAqoA RoY47on8uj6K0qA7zEPbrOk+Hw== X-Google-Smtp-Source: APXvYqwJuVDDu/mOYKzGkZFB0X1UqTn0Qa+OVaLwLB95oIEcxAwYN0wOok1qesvkSn2uo7Jzyq10Dw== X-Received: by 2002:a17:906:69c3:: with SMTP id g3mr17466229ejs.245.1553614229385; Tue, 26 Mar 2019 08:30:29 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id b2sm5310830eda.36.2019.03.26.08.30.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 26 Mar 2019 08:30:28 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov , Alexander Duyck , Alexey Kuznetsov , David Ahern , "David S. Miller" , Eric Dumazet , Hideaki YOSHIFUJI , Ido Schimmel , netdev@vger.kernel.org Subject: [RFC 1/4] net/ipv4/fib: Remove run-time check in tnode_alloc() Date: Tue, 26 Mar 2019 15:30:22 +0000 Message-Id: <20190326153026.24493-2-dima@arista.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326153026.24493-1-dima@arista.com> References: <20190326153026.24493-1-dima@arista.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org TNODE_KMALLOC_MAX is not used anywhere, while TNODE_VMALLOC_MAX check in tnode_alloc() only adds additional cmp/jmp instructions to tnode allocation. During rebalancing of the trie the function can be called thousands of times. Runtime check takes cache line and predictor entry. Futhermore, this check is always false on 64-bit platfroms and ipv4 has only 4 byte address range and bits are limited by KEYLENGTH (32). Move the check under unlikely() and change comparison to BITS_PER_LONG, optimizing allocation of tnode during rebalancing (and removing it complitely for platforms with BITS_PER_LONG > KEYLENGTH). Signed-off-by: Dmitry Safonov --- net/ipv4/fib_trie.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index a573e37e0615..ad7d56c421cb 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -312,11 +312,6 @@ static inline void alias_free_mem_rcu(struct fib_alias *fa) call_rcu(&fa->rcu, __alias_free_mem); } -#define TNODE_KMALLOC_MAX \ - ilog2((PAGE_SIZE - TNODE_SIZE(0)) / sizeof(struct key_vector *)) -#define TNODE_VMALLOC_MAX \ - ilog2((SIZE_MAX - TNODE_SIZE(0)) / sizeof(struct key_vector *)) - static void __node_free_rcu(struct rcu_head *head) { struct tnode *n = container_of(head, struct tnode, rcu); @@ -333,8 +328,7 @@ static struct tnode *tnode_alloc(int bits) { size_t size; - /* verify bits is within bounds */ - if (bits > TNODE_VMALLOC_MAX) + if ((BITS_PER_LONG <= KEYLENGTH) && unlikely(bits >= BITS_PER_LONG)) return NULL; /* determine size and verify it is non-zero and didn't overflow */