[PATCH 1/3] can: raw: reorder struct uniqframe's members to optimise packing

Vincent Mailhol posted 3 patches 2 weeks, 3 days ago
There is a newer version of this series
[PATCH 1/3] can: raw: reorder struct uniqframe's members to optimise packing
Posted by Vincent Mailhol 2 weeks, 3 days ago
struct uniqframe has one hole. Reorder the fields to save 8 bytes.

Statistics before:

  $ pahole --class_name=uniqframe net/can/raw.o
  struct uniqframe {
  	int                        skbcnt;               /*     0     4 */

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

  	const struct sk_buff  *    skb;                  /*     8     8 */
  	unsigned int               join_rx_count;        /*    16     4 */

  	/* size: 24, cachelines: 1, members: 3 */
  	/* sum members: 16, holes: 1, sum holes: 4 */
  	/* padding: 4 */
  	/* last cacheline: 24 bytes */
  };

...and after:

  $ pahole --class_name=uniqframe net/can/raw.o
  struct uniqframe {
  	const struct sk_buff  *    skb;                  /*     0     8 */
  	int                        skbcnt;               /*     8     4 */
  	unsigned int               join_rx_count;        /*    12     4 */

  	/* size: 16, cachelines: 1, members: 3 */
  	/* last cacheline: 16 bytes */
  };

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
 net/can/raw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/can/raw.c b/net/can/raw.c
index 76b867d21def209f5c6d236604c0e434a1c55a4d..db21d8a8c54d1b6a25a72c7a9d11d5c94f3187b5 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -75,8 +75,8 @@ MODULE_ALIAS("can-proto-1");
  */
 
 struct uniqframe {
-	int skbcnt;
 	const struct sk_buff *skb;
+	int skbcnt;
 	unsigned int join_rx_count;
 };
 

-- 
2.49.1
Re: [PATCH 1/3] can: raw: reorder struct uniqframe's members to optimise packing
Posted by Oliver Hartkopp 2 weeks, 3 days ago

On 15.09.25 11:23, Vincent Mailhol wrote:
> struct uniqframe has one hole. Reorder the fields to save 8 bytes.
> 
> Statistics before:
> 
>    $ pahole --class_name=uniqframe net/can/raw.o
>    struct uniqframe {
>    	int                        skbcnt;               /*     0     4 */
> 
>    	/* XXX 4 bytes hole, try to pack */
> 
>    	const struct sk_buff  *    skb;                  /*     8     8 */
>    	unsigned int               join_rx_count;        /*    16     4 */
> 
>    	/* size: 24, cachelines: 1, members: 3 */
>    	/* sum members: 16, holes: 1, sum holes: 4 */
>    	/* padding: 4 */
>    	/* last cacheline: 24 bytes */
>    };
> 
> ...and after:
> 
>    $ pahole --class_name=uniqframe net/can/raw.o
>    struct uniqframe {
>    	const struct sk_buff  *    skb;                  /*     0     8 */
>    	int                        skbcnt;               /*     8     4 */
>    	unsigned int               join_rx_count;        /*    12     4 */
> 
>    	/* size: 16, cachelines: 1, members: 3 */
>    	/* last cacheline: 16 bytes */
>    };
> 
> Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

> ---
>   net/can/raw.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/can/raw.c b/net/can/raw.c
> index 76b867d21def209f5c6d236604c0e434a1c55a4d..db21d8a8c54d1b6a25a72c7a9d11d5c94f3187b5 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -75,8 +75,8 @@ MODULE_ALIAS("can-proto-1");
>    */
>   
>   struct uniqframe {
> -	int skbcnt;
>   	const struct sk_buff *skb;
> +	int skbcnt;
>   	unsigned int join_rx_count;
>   };
>   
>