diff mbox series

[net-next] mctp: Reorder fields in 'struct mctp_route'

Message ID 393ad1a5aef0aa28d839eeb3d7477da0e0eeb0b0.1687080803.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Commit 066768b7305b1524d261fdc543d25fd60d955254
Delegated to: Netdev Maintainers
Headers show
Series [net-next] mctp: Reorder fields in 'struct mctp_route' | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 12 this patch: 12
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 12 this patch: 12
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christophe JAILLET June 18, 2023, 9:33 a.m. UTC
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(-)

Comments

Simon Horman June 19, 2023, 2:04 p.m. UTC | #1
On Sun, Jun 18, 2023 at 11:33:55AM +0200, Christophe JAILLET wrote:
> 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>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Jeremy Kerr June 19, 2023, 2:06 p.m. UTC | #2
Hi Christoph,

> 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.

The savings will be fairly minimal, but this doesn't affect readability
for the route struct. LGTM.

Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>

Thanks!


Jeremy
Jiri Pirko June 19, 2023, 2:41 p.m. UTC | #3
Sun, Jun 18, 2023 at 11:33:55AM CEST, christophe.jaillet@wanadoo.fr wrote:
>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>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
patchwork-bot+netdevbpf@kernel.org June 21, 2023, 3:40 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 18 Jun 2023 11:33:55 +0200 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [net-next] mctp: Reorder fields in 'struct mctp_route'
    https://git.kernel.org/netdev/net-next/c/066768b7305b

You are awesome, thank you!
diff mbox series

Patch

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);