netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Jeremy Kerr <jk@codeconstruct.com.au>,
	Matt Johnston <matt@codeconstruct.com.au>,
	"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>,
	netdev@vger.kernel.org
Subject: [PATCH net-next] mctp: Reorder fields in 'struct mctp_route'
Date: Sun, 18 Jun 2023 11:33:55 +0200	[thread overview]
Message-ID: <393ad1a5aef0aa28d839eeb3d7477da0e0eeb0b0.1687080803.git.christophe.jaillet@wanadoo.fr> (raw)

Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct mctp_route'
from 72 to 64 bytes.

It saves a few bytes of memory and is more cache-line friendly.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole

Before:
======
struct mctp_route {
	mctp_eid_t                 min;                  /*     0     1 */
	mctp_eid_t                 max;                  /*     1     1 */

	/* XXX 6 bytes hole, try to pack */

	struct mctp_dev *          dev;                  /*     8     8 */
	unsigned int               mtu;                  /*    16     4 */
	unsigned char              type;                 /*    20     1 */

	/* XXX 3 bytes hole, try to pack */

	int                        (*output)(struct mctp_route *, struct sk_buff *); /*    24     8 */
	struct list_head           list;                 /*    32    16 */
	refcount_t                 refs;                 /*    48     4 */

	/* XXX 4 bytes hole, try to pack */

	struct callback_head       rcu __attribute__((__aligned__(8))); /*    56    16 */

	/* size: 72, cachelines: 2, members: 9 */
	/* sum members: 59, holes: 3, sum holes: 13 */
	/* forced alignments: 1, forced holes: 1, sum forced holes: 4 */
	/* last cacheline: 8 bytes */
} __attribute__((__aligned__(8)));


After:
=====
struct mctp_route {
	mctp_eid_t                 min;                  /*     0     1 */
	mctp_eid_t                 max;                  /*     1     1 */
	unsigned char              type;                 /*     2     1 */

	/* XXX 1 byte hole, try to pack */

	unsigned int               mtu;                  /*     4     4 */
	struct mctp_dev *          dev;                  /*     8     8 */
	int                        (*output)(struct mctp_route *, struct sk_buff *); /*    16     8 */
	struct list_head           list;                 /*    24    16 */
	refcount_t                 refs;                 /*    40     4 */

	/* XXX 4 bytes hole, try to pack */

	struct callback_head       rcu __attribute__((__aligned__(8))); /*    48    16 */

	/* size: 64, cachelines: 1, members: 9 */
	/* sum members: 59, holes: 2, sum holes: 5 */
	/* forced alignments: 1, forced holes: 1, sum forced holes: 4 */
} __attribute__((__aligned__(8)));
---
 include/net/mctp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/mctp.h b/include/net/mctp.h
index 82800d521c3d..da86e106c91d 100644
--- a/include/net/mctp.h
+++ b/include/net/mctp.h
@@ -234,9 +234,9 @@ struct mctp_flow {
 struct mctp_route {
 	mctp_eid_t		min, max;
 
-	struct mctp_dev		*dev;
-	unsigned int		mtu;
 	unsigned char		type;
+	unsigned int		mtu;
+	struct mctp_dev		*dev;
 	int			(*output)(struct mctp_route *route,
 					  struct sk_buff *skb);
 
-- 
2.34.1


             reply	other threads:[~2023-06-18  9:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-18  9:33 Christophe JAILLET [this message]
2023-06-19 14:04 ` [PATCH net-next] mctp: Reorder fields in 'struct mctp_route' Simon Horman
2023-06-19 14:06 ` Jeremy Kerr
2023-06-19 14:41 ` Jiri Pirko
2023-06-21  3:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=393ad1a5aef0aa28d839eeb3d7477da0e0eeb0b0.1687080803.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jk@codeconstruct.com.au \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeconstruct.com.au \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).