Message ID | 5cdb1f50f2e9dc80dbf86cf8667056eacfd36a09.1683564754.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2296889vqo; Mon, 8 May 2023 10:00:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kctQS91S6jjSfQVXwAXFijgHX0xVijVNzUTMVIQUf7wt/I5wzEdHYs1mF4IFlpJBihVwX X-Received: by 2002:a17:90b:3109:b0:247:42bf:380e with SMTP id gc9-20020a17090b310900b0024742bf380emr11384026pjb.4.1683565231890; Mon, 08 May 2023 10:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683565231; cv=none; d=google.com; s=arc-20160816; b=ZO+mO70/Mz1ZoyZ5sDbgbALIzJClfTQKhoNpVcCSmW6F8rUQRVYGMgX8AdOKl3kF0u ALph9P6k3yHzfjJA6Z6c1oASxAf7xgqTi1S+d1t3KjFcfTRxG5/2sU2hshrL6bnmQW9F M0GRJxoXYiYvfczV3w8PTNBB/47o2QYXHgpQTSS7wF1AtoxHUvoMk54FhDsJNDgHYFcm GIKzoRInv3j5slLOR7FO5PfWFW9FTbL7Afs//G6tExSOoOxrP11tKqeE7S0yY03by4Ek ra9SpmNrQcMTlQUbk4svttD3Q+rNUh2myUu1IyG73DFWSupn9TdxG9NlcO2JZYojOQaa US5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=lm5x+NwYR0+zI73AdgqIwZ7OxGK1VHk4xnXiyrCtxyI=; b=zemuRlya1B1IU57lQS6xHJdtBm/g1Mh+iabf61zBpHeza6YFLu1+6HBMxngin9JthJ fR1qS8JgzEyEo7sRTVnXIJ6cw15pvuCYcl0mscqxJnzoBFKskAldirBJ8a2MHM/WZvl2 IkOmU3Q6BbVNoQhqYKOnlKSdushHSreM60uG1Di5pR3iNd/z21ghKj3tjBKKZ7e6alGV FnUPp8Ih9TEnAjrXLMGyMtbWy5XYNi9Bcv/McfIXu0CUldpSBCeE8t98p8xfgZOQSel8 bTE4b/7SQtPnzQ9x2/Xzj3fxytJprcskAvoiIlByxa1pGNLXEG+9qOastnXTgS5gi/AX p0dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=TffSdUf8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902ec8100b001ac4e2d2b58si7023187plg.112.2023.05.08.10.00.12; Mon, 08 May 2023 10:00:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=TffSdUf8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232753AbjEHQxa (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Mon, 8 May 2023 12:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjEHQx3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 8 May 2023 12:53:29 -0400 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCB049DE for <linux-kernel@vger.kernel.org>; Mon, 8 May 2023 09:53:25 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id w46xpAkeMfMwtw46xpf0cB; Mon, 08 May 2023 18:53:23 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1683564803; bh=lm5x+NwYR0+zI73AdgqIwZ7OxGK1VHk4xnXiyrCtxyI=; h=From:To:Cc:Subject:Date; b=TffSdUf8plGRs/fzLhYW2m+zoyex7bE0y+J2jIt9i6EFeFdGap/wrfNTUt4hfOAD4 6hg7Rja0JgT98UjFX9lI6MgVAXfJiboQ01sQiV+qLQimAy6cwkQKY4Adg1/3BvV1Eq Pe2qRSRCcKRv9jmq52vGIYVZpSvXRPAVQNa7qo7RBmglCKs8YvpWqTe7RaUhZ1sDfD wGtE1gdhkYosYQlcn9jhjeQZUFOCPtfeyVpTuH7P/eqkdcw16IU/pllrekehtUXHme iXKoxhMMWioWmwV/MGsDSmDLJ6df2NpYxfqA+pMTxJE1OyRoc3lrMQ2+6zh42oqw8s 9ZxmWry12MF5g== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 08 May 2023 18:53:23 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Pablo Neira Ayuso <pablo@netfilter.org>, Jozsef Kadlecsik <kadlec@netfilter.org>, Florian Westphal <fw@strlen.de>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH net-next] netfilter: Reorder fields in 'struct nf_conntrack_expect' Date: Mon, 8 May 2023 18:53:14 +0200 Message-Id: <5cdb1f50f2e9dc80dbf86cf8667056eacfd36a09.1683564754.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765346096751440045?= X-GMAIL-MSGID: =?utf-8?q?1765346096751440045?= |
Series |
[net-next] netfilter: Reorder fields in 'struct nf_conntrack_expect'
|
|
Commit Message
Christophe JAILLET
May 8, 2023, 4:53 p.m. UTC
Group some variables based on their sizes to reduce holes.
On x86_64, this shrinks the size of 'struct nf_conntrack_expect' from 264
to 256 bytes.
This structure deserve a dedicated cache, so reducing its size looks nice.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole
Before:
======
struct nf_conntrack_expect {
struct hlist_node lnode; /* 0 16 */
struct hlist_node hnode; /* 16 16 */
struct nf_conntrack_tuple tuple; /* 32 40 */
/* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
struct nf_conntrack_tuple_mask mask; /* 72 20 */
/* XXX 4 bytes hole, try to pack */
void (*expectfn)(struct nf_conn *, struct nf_conntrack_expect *); /* 96 8 */
struct nf_conntrack_helper * helper; /* 104 8 */
struct nf_conn * master; /* 112 8 */
struct timer_list timeout; /* 120 88 */
/* --- cacheline 3 boundary (192 bytes) was 16 bytes ago --- */
refcount_t use; /* 208 4 */
unsigned int flags; /* 212 4 */
unsigned int class; /* 216 4 */
union nf_inet_addr saved_addr; /* 220 16 */
union nf_conntrack_man_proto saved_proto; /* 236 2 */
/* XXX 2 bytes hole, try to pack */
enum ip_conntrack_dir dir; /* 240 4 */
/* XXX 4 bytes hole, try to pack */
struct callback_head rcu __attribute__((__aligned__(8))); /* 248 16 */
/* size: 264, cachelines: 5, members: 15 */
/* sum members: 254, holes: 3, sum holes: 10 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 4 */
/* last cacheline: 8 bytes */
} __attribute__((__aligned__(8)));
After:
=====
struct nf_conntrack_expect {
struct hlist_node lnode; /* 0 16 */
struct hlist_node hnode; /* 16 16 */
struct nf_conntrack_tuple tuple; /* 32 40 */
/* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
struct nf_conntrack_tuple_mask mask; /* 72 20 */
refcount_t use; /* 92 4 */
unsigned int flags; /* 96 4 */
unsigned int class; /* 100 4 */
void (*expectfn)(struct nf_conn *, struct nf_conntrack_expect *); /* 104 8 */
struct nf_conntrack_helper * helper; /* 112 8 */
struct nf_conn * master; /* 120 8 */
/* --- cacheline 2 boundary (128 bytes) --- */
struct timer_list timeout; /* 128 88 */
/* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */
union nf_inet_addr saved_addr; /* 216 16 */
union nf_conntrack_man_proto saved_proto; /* 232 2 */
/* XXX 2 bytes hole, try to pack */
enum ip_conntrack_dir dir; /* 236 4 */
struct callback_head rcu __attribute__((__aligned__(8))); /* 240 16 */
/* size: 256, cachelines: 4, members: 15 */
/* sum members: 254, holes: 1, sum holes: 2 */
/* forced alignments: 1 */
} __attribute__((__aligned__(8)));
---
include/net/netfilter/nf_conntrack_expect.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
Comments
On Mon, May 08, 2023 at 06:53:14PM +0200, Christophe JAILLET wrote: > Group some variables based on their sizes to reduce holes. > On x86_64, this shrinks the size of 'struct nf_conntrack_expect' from 264 > to 256 bytes. > > This structure deserve a dedicated cache, so reducing its size looks nice. > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Thanks, this much nicer to me. I slightly concerned that there may be implications for fields that were on the same cacheline now being on different cachelines. But only very slightly. Reviewed-by: Simon Horman <simon.horman@corigine.com> > --- > Using pahole > > Before: > ====== > struct nf_conntrack_expect { > struct hlist_node lnode; /* 0 16 */ > struct hlist_node hnode; /* 16 16 */ > struct nf_conntrack_tuple tuple; /* 32 40 */ > /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */ > struct nf_conntrack_tuple_mask mask; /* 72 20 */ > > /* XXX 4 bytes hole, try to pack */ > > void (*expectfn)(struct nf_conn *, struct nf_conntrack_expect *); /* 96 8 */ > struct nf_conntrack_helper * helper; /* 104 8 */ > struct nf_conn * master; /* 112 8 */ > struct timer_list timeout; /* 120 88 */ > /* --- cacheline 3 boundary (192 bytes) was 16 bytes ago --- */ > refcount_t use; /* 208 4 */ > unsigned int flags; /* 212 4 */ > unsigned int class; /* 216 4 */ > union nf_inet_addr saved_addr; /* 220 16 */ > union nf_conntrack_man_proto saved_proto; /* 236 2 */ > > /* XXX 2 bytes hole, try to pack */ > > enum ip_conntrack_dir dir; /* 240 4 */ > > /* XXX 4 bytes hole, try to pack */ > > struct callback_head rcu __attribute__((__aligned__(8))); /* 248 16 */ > > /* size: 264, cachelines: 5, members: 15 */ > /* sum members: 254, holes: 3, sum holes: 10 */ > /* forced alignments: 1, forced holes: 1, sum forced holes: 4 */ > /* last cacheline: 8 bytes */ > } __attribute__((__aligned__(8))); > > > After: > ===== > struct nf_conntrack_expect { > struct hlist_node lnode; /* 0 16 */ > struct hlist_node hnode; /* 16 16 */ > struct nf_conntrack_tuple tuple; /* 32 40 */ > /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */ > struct nf_conntrack_tuple_mask mask; /* 72 20 */ > refcount_t use; /* 92 4 */ > unsigned int flags; /* 96 4 */ > unsigned int class; /* 100 4 */ > void (*expectfn)(struct nf_conn *, struct nf_conntrack_expect *); /* 104 8 */ > struct nf_conntrack_helper * helper; /* 112 8 */ > struct nf_conn * master; /* 120 8 */ > /* --- cacheline 2 boundary (128 bytes) --- */ > struct timer_list timeout; /* 128 88 */ > /* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */ > union nf_inet_addr saved_addr; /* 216 16 */ > union nf_conntrack_man_proto saved_proto; /* 232 2 */ > > /* XXX 2 bytes hole, try to pack */ > > enum ip_conntrack_dir dir; /* 236 4 */ > struct callback_head rcu __attribute__((__aligned__(8))); /* 240 16 */ > > /* size: 256, cachelines: 4, members: 15 */ > /* sum members: 254, holes: 1, sum holes: 2 */ > /* forced alignments: 1 */ > } __attribute__((__aligned__(8))); > --- > include/net/netfilter/nf_conntrack_expect.h | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/include/net/netfilter/nf_conntrack_expect.h b/include/net/netfilter/nf_conntrack_expect.h > index 0855b60fba17..cf0d81be5a96 100644 > --- a/include/net/netfilter/nf_conntrack_expect.h > +++ b/include/net/netfilter/nf_conntrack_expect.h > @@ -26,6 +26,15 @@ struct nf_conntrack_expect { > struct nf_conntrack_tuple tuple; > struct nf_conntrack_tuple_mask mask; > > + /* Usage count. */ > + refcount_t use; > + > + /* Flags */ > + unsigned int flags; > + > + /* Expectation class */ > + unsigned int class; > + > /* Function to call after setup and insertion */ > void (*expectfn)(struct nf_conn *new, > struct nf_conntrack_expect *this); > @@ -39,15 +48,6 @@ struct nf_conntrack_expect { > /* Timer function; deletes the expectation. */ > struct timer_list timeout; > > - /* Usage count. */ > - refcount_t use; > - > - /* Flags */ > - unsigned int flags; > - > - /* Expectation class */ > - unsigned int class; > - > #if IS_ENABLED(CONFIG_NF_NAT) > union nf_inet_addr saved_addr; > /* This is the original per-proto part, used to map the > -- > 2.34.1 > >
diff --git a/include/net/netfilter/nf_conntrack_expect.h b/include/net/netfilter/nf_conntrack_expect.h index 0855b60fba17..cf0d81be5a96 100644 --- a/include/net/netfilter/nf_conntrack_expect.h +++ b/include/net/netfilter/nf_conntrack_expect.h @@ -26,6 +26,15 @@ struct nf_conntrack_expect { struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple_mask mask; + /* Usage count. */ + refcount_t use; + + /* Flags */ + unsigned int flags; + + /* Expectation class */ + unsigned int class; + /* Function to call after setup and insertion */ void (*expectfn)(struct nf_conn *new, struct nf_conntrack_expect *this); @@ -39,15 +48,6 @@ struct nf_conntrack_expect { /* Timer function; deletes the expectation. */ struct timer_list timeout; - /* Usage count. */ - refcount_t use; - - /* Flags */ - unsigned int flags; - - /* Expectation class */ - unsigned int class; - #if IS_ENABLED(CONFIG_NF_NAT) union nf_inet_addr saved_addr; /* This is the original per-proto part, used to map the