From nobody Thu Oct 2 11:49:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DD9F2609D4; Wed, 17 Sep 2025 04:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084536; cv=none; b=RLK0w6gz5sjIu2iXafNzcnBKWMu0DyECjUWju+NrSFue/ev2f9xP/z+l1VxuVTPKeqKtCJWYw8gmaDa9HBowGfVBN2tnjrjk3qE202aNxipncpnwFC8xLwR0Blne0T209W/PDpRtyjD/UdBjdnsQ7zfscdLH7hv+xUGLhXWg+Y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084536; c=relaxed/simple; bh=uYbj8hTFtyXtNzgUkUNpzdgT2RSzDLC9LUc8bQgRZBs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a43bTnbT6Heu3aGvyw31dbjzcTQQJ0c2CulhWIRuu+ZaV0NxsrXuKi7RKYrI+vHqlWTCq7ptVq2RfH/R9N8VQm4iAZiv9Xj6SetnxsXWvzrytfChAgiuNNIEJr1u4Mj0nON41FyZPm1BCL3sjkfIupmeb0C04yqDL5OwSMHBdJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rv/7f1w9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rv/7f1w9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4105CC4CEF5; Wed, 17 Sep 2025 04:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758084536; bh=uYbj8hTFtyXtNzgUkUNpzdgT2RSzDLC9LUc8bQgRZBs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rv/7f1w9zJFR7lca0t8VtMj/kgaxGo/1dGTPBQ8O659Xd2vSu8Kj1ouUcgLK68wo0 oazd3xRb7o6Zzz+qrZwtsuCQj/60M3YUr0SBRjJ3GiXA1DNjncg+HVRZvOhMvRFHuc nbJNPN1zAkeRWtek87+Ubi1BDKsUL6wx+OQy6C57QXNaTMOzfxn73ezKbaHlViotwy SeG6FztKexsI0fXTPnG7NWX5zWxt4Ri1fdvJM5NrwXifNGKqZScimHt5f4oPDi7gIE FRjas/wHzX/ttqdV69Hne0givAtcA3CIJ/z0xQ6rGqBJJQSykyXWuEn27dakdh5JyF A+Gq6V6PtR5IQ== From: Vincent Mailhol Date: Wed, 17 Sep 2025 13:48:24 +0900 Subject: [PATCH v2 1/3] can: raw: reorder struct uniqframe's members to optimise packing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-can-raw-repack-v2-1-395e8b3a4437@kernel.org> References: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> In-Reply-To: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> To: Oliver Hartkopp , Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Christophe Jaillet , Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1532; i=mailhol@kernel.org; h=from:subject:message-id; bh=uYbj8hTFtyXtNzgUkUNpzdgT2RSzDLC9LUc8bQgRZBs=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnbNf/idtj2Kj25o6S5/T/gXrrHwgeisrfUPPZP8fQy Sf0TYRbRykLgxgXg6yYIsuyck5uhY5C77BDfy1h5rAygQxh4OIUgIkY3WJk2PJzlZ+g2dRCJsNJ pxWftr1kN+HgeNO9+9Uu9cgs6xgvdUaGR/vtskr1i9++NTAJ3/cs5OodC3mb7H9H0yzqlx298qO cCQA= X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 struct uniqframe has one hole. Reorder the fields to save 8 bytes. Statistics before: $ pahole --class_name=3Duniqframe 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=3Duniqframe 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 */ }; Acked-by: Oliver Hartkopp Signed-off-by: Vincent Mailhol --- 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..db21d8a8c54d1b6a25a72c7a9d1= 1d5c94f3187b5 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -75,8 +75,8 @@ MODULE_ALIAS("can-proto-1"); */ =20 struct uniqframe { - int skbcnt; const struct sk_buff *skb; + int skbcnt; unsigned int join_rx_count; }; =20 --=20 2.49.1 From nobody Thu Oct 2 11:49:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF1E27A462; Wed, 17 Sep 2025 04:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084537; cv=none; b=IEDYmpgyRUcyKI+6JoJCTPIM9UhQLz9h5cg8Onx9oqH8UF/2+/irZt8DJSUQyuDnPkfQX1DVhxS4mye3Xqbuprll7T8iz0BYa4yWN89Q7WTRM5VCucoBOIipfrkIAfZ5EcMoakMwDxP4mDoUqrTw0AzVxphQpI9AB1ZzfKjYwkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084537; c=relaxed/simple; bh=9ZBz1hou7lESaLLepNjDGCXjO60B3Vu0/SzVAJ/MWZw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=knz4eE4QdRdiAU+dCK9390QT/5SURb1iXTyz5PMB5Z/WZVn2n8+uIwHGRjmYqriYX6SbxTmAl/FQemvpcvmQnHsLBfoRulR57aVWYR/2CwtdMBbGFSf7J1sT79NSOcKh2/pj3j4NJvIj9VZ8RW8kltY4QPDQlzuGCOi5oStaT38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cY2MPQ6Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cY2MPQ6Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6939DC4CEF9; Wed, 17 Sep 2025 04:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758084537; bh=9ZBz1hou7lESaLLepNjDGCXjO60B3Vu0/SzVAJ/MWZw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cY2MPQ6YTBV92fY3l5C5Vtuhn9uopfENvDbXfsgMaWCP/YcReOA+bp9y9wijhHafY c1JwJ905J1Svx432pznw4PHg1ozOIDDVOE2NGYqb4NO8fEpnP3FacnQLs0bs4vIx5Z an8qKbx9cogEhDDGB5HIiDbo/R52Kbk9jB0c7Phm78mNpMw9h7nBiTgiPSbkcYuFZF k6pEI0Jx8P/CZru2OIQF94DQPBaMwvOr6Z7wWlsdqRMffjiOiyK+N3qYJuoDSU4LjR iwJI0lJgsUMPgnTdJIN+6S4qhzD8ouyF+YwIFJcTBCH+22Ideekkn2cOr/9VzPf9sD fQlQnhxD1FIgw== From: Vincent Mailhol Date: Wed, 17 Sep 2025 13:48:25 +0900 Subject: [PATCH v2 2/3] can: raw: use bitfields to store flags in struct raw_sock Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-can-raw-repack-v2-2-395e8b3a4437@kernel.org> References: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> In-Reply-To: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> To: Oliver Hartkopp , Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Christophe Jaillet , Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9578; i=mailhol@kernel.org; h=from:subject:message-id; bh=9ZBz1hou7lESaLLepNjDGCXjO60B3Vu0/SzVAJ/MWZw=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnbDd2hDeI9t81KDoQPTnaaonlzEjHzYnzdbZ+r/ut+ 79gJWdBRykLgxgXg6yYIsuyck5uhY5C77BDfy1h5rAygQxh4OIUgImIpzH8D2XJ3llXyPH07pJN xkUzlK7smFSgu+r3w71fpiStdjnoupzhf5mf9rSPd5dc2DyBc9Jvy5rcli6TH/+6I9cq/uOeXWA UxQ0A X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 The bound, loopback, recv_own_msgs, fd_frames, xl_frames and join_filters fields of struct raw_sock just need to store one bit of information. Declare all those members as a bitfields of type unsigned int and width one bit. Add a temporary variable to raw_setsockopt() and raw_getsockopt() to make the conversion between the stored bits and the socket interface. This reduces the size of struct raw_sock by sixteen bytes. Statistics before: $ pahole --class_name=3Draw_sock net/can/raw.o struct raw_sock { struct sock sk __attribute__((__aligned__(8))); /* 0 = 776 */ /* XXX last struct has 1 bit hole */ /* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */ int bound; /* 776 4 */ int ifindex; /* 780 4 */ struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ int loopback; /* 808 4 */ int recv_own_msgs; /* 812 4 */ int fd_frames; /* 816 4 */ int xl_frames; /* 820 4 */ struct can_raw_vcid_options raw_vcid_opts; /* 824 4 */ canid_t tx_vcid_shifted; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ canid_t rx_vcid_shifted; /* 832 4 */ canid_t rx_vcid_mask_shifted; /* 836 4 */ int join_filters; /* 840 4 */ int count; /* 844 4 */ struct can_filter dfilter; /* 848 8 */ struct can_filter * filter; /* 856 8 */ can_err_mask_t err_mask; /* 864 4 */ /* XXX 4 bytes hole, try to pack */ struct uniqframe * uniq; /* 872 8 */ /* size: 880, cachelines: 14, members: 20 */ /* sum members: 876, holes: 1, sum holes: 4 */ /* member types with bit holes: 1, total: 1 */ /* forced alignments: 1 */ /* last cacheline: 48 bytes */ } __attribute__((__aligned__(8))); ...and after: $ pahole --class_name=3Draw_sock net/can/raw.o struct raw_sock { struct sock sk __attribute__((__aligned__(8))); /* 0 = 776 */ /* XXX last struct has 1 bit hole */ /* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */ int ifindex; /* 776 4 */ /* XXX 4 bytes hole, try to pack */ struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ unsigned int bound:1; /* 808: 0 4 */ unsigned int loopback:1; /* 808: 1 4 */ unsigned int recv_own_msgs:1; /* 808: 2 4 */ unsigned int fd_frames:1; /* 808: 3 4 */ unsigned int xl_frames:1; /* 808: 4 4 */ unsigned int join_filters:1; /* 808: 5 4 */ /* XXX 2 bits hole, try to pack */ /* Bitfield combined with next fields */ struct can_raw_vcid_options raw_vcid_opts; /* 809 4 */ /* XXX 3 bytes hole, try to pack */ canid_t tx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_shifted; /* 820 4 */ canid_t rx_vcid_mask_shifted; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ can_err_mask_t err_mask; /* 848 4 */ /* XXX 4 bytes hole, try to pack */ struct uniqframe * uniq; /* 856 8 */ /* size: 864, cachelines: 14, members: 20 */ /* sum members: 852, holes: 3, sum holes: 11 */ /* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */ /* forced alignments: 1 */ /* last cacheline: 32 bytes */ } __attribute__((__aligned__(8))); Acked-by: Oliver Hartkopp Signed-off-by: Vincent Mailhol --- Changelog: v1 -> v2: - also add raw_sock->bound and raw_sock->join_filters to the bitfield --- net/can/raw.c | 59 +++++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/net/can/raw.c b/net/can/raw.c index db21d8a8c54d1b6a25a72c7a9d11d5c94f3187b5..5a5ded519cd1768456c234c42dc= 4e865f7350dab 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -82,20 +82,20 @@ struct uniqframe { =20 struct raw_sock { struct sock sk; - int bound; int ifindex; struct net_device *dev; netdevice_tracker dev_tracker; struct list_head notifier; - int loopback; - int recv_own_msgs; - int fd_frames; - int xl_frames; + unsigned int bound:1; + unsigned int loopback:1; + unsigned int recv_own_msgs:1; + unsigned int fd_frames:1; + unsigned int xl_frames:1; + unsigned int join_filters:1; struct can_raw_vcid_options raw_vcid_opts; canid_t tx_vcid_shifted; canid_t rx_vcid_shifted; canid_t rx_vcid_mask_shifted; - int join_filters; int count; /* number of active filters */ struct can_filter dfilter; /* default/single filter */ struct can_filter *filter; /* pointer to filter(s) */ @@ -560,8 +560,8 @@ static int raw_setsockopt(struct socket *sock, int leve= l, int optname, struct can_filter sfilter; /* single filter */ struct net_device *dev =3D NULL; can_err_mask_t err_mask =3D 0; - int fd_frames; int count =3D 0; + int flag; int err =3D 0; =20 if (level !=3D SOL_CAN_RAW) @@ -682,44 +682,48 @@ static int raw_setsockopt(struct socket *sock, int le= vel, int optname, break; =20 case CAN_RAW_LOOPBACK: - if (optlen !=3D sizeof(ro->loopback)) + if (optlen !=3D sizeof(flag)) return -EINVAL; =20 - if (copy_from_sockptr(&ro->loopback, optval, optlen)) + if (copy_from_sockptr(&flag, optval, optlen)) return -EFAULT; =20 + ro->loopback =3D !!flag; break; =20 case CAN_RAW_RECV_OWN_MSGS: - if (optlen !=3D sizeof(ro->recv_own_msgs)) + if (optlen !=3D sizeof(flag)) return -EINVAL; =20 - if (copy_from_sockptr(&ro->recv_own_msgs, optval, optlen)) + if (copy_from_sockptr(&flag, optval, optlen)) return -EFAULT; =20 + ro->recv_own_msgs =3D !!flag; break; =20 case CAN_RAW_FD_FRAMES: - if (optlen !=3D sizeof(fd_frames)) + if (optlen !=3D sizeof(flag)) return -EINVAL; =20 - if (copy_from_sockptr(&fd_frames, optval, optlen)) + if (copy_from_sockptr(&flag, optval, optlen)) return -EFAULT; =20 /* Enabling CAN XL includes CAN FD */ - if (ro->xl_frames && !fd_frames) + if (ro->xl_frames && !flag) return -EINVAL; =20 - ro->fd_frames =3D fd_frames; + ro->fd_frames =3D !!flag; break; =20 case CAN_RAW_XL_FRAMES: - if (optlen !=3D sizeof(ro->xl_frames)) + if (optlen !=3D sizeof(flag)) return -EINVAL; =20 - if (copy_from_sockptr(&ro->xl_frames, optval, optlen)) + if (copy_from_sockptr(&flag, optval, optlen)) return -EFAULT; =20 + ro->xl_frames =3D !!flag; + /* Enabling CAN XL includes CAN FD */ if (ro->xl_frames) ro->fd_frames =3D ro->xl_frames; @@ -739,12 +743,13 @@ static int raw_setsockopt(struct socket *sock, int le= vel, int optname, break; =20 case CAN_RAW_JOIN_FILTERS: - if (optlen !=3D sizeof(ro->join_filters)) + if (optlen !=3D sizeof(flag)) return -EINVAL; =20 - if (copy_from_sockptr(&ro->join_filters, optval, optlen)) + if (copy_from_sockptr(&flag, optval, optlen)) return -EFAULT; =20 + ro->join_filters =3D !!flag; break; =20 default: @@ -758,6 +763,7 @@ static int raw_getsockopt(struct socket *sock, int leve= l, int optname, { struct sock *sk =3D sock->sk; struct raw_sock *ro =3D raw_sk(sk); + int flag; int len; void *val; =20 @@ -806,25 +812,29 @@ static int raw_getsockopt(struct socket *sock, int le= vel, int optname, case CAN_RAW_LOOPBACK: if (len > sizeof(int)) len =3D sizeof(int); - val =3D &ro->loopback; + flag =3D ro->loopback; + val =3D &flag; break; =20 case CAN_RAW_RECV_OWN_MSGS: if (len > sizeof(int)) len =3D sizeof(int); - val =3D &ro->recv_own_msgs; + flag =3D ro->recv_own_msgs; + val =3D &flag; break; =20 case CAN_RAW_FD_FRAMES: if (len > sizeof(int)) len =3D sizeof(int); - val =3D &ro->fd_frames; + flag =3D ro->fd_frames; + val =3D &flag; break; =20 case CAN_RAW_XL_FRAMES: if (len > sizeof(int)) len =3D sizeof(int); - val =3D &ro->xl_frames; + flag =3D ro->xl_frames; + val =3D &flag; break; =20 case CAN_RAW_XL_VCID_OPTS: { @@ -849,7 +859,8 @@ static int raw_getsockopt(struct socket *sock, int leve= l, int optname, case CAN_RAW_JOIN_FILTERS: if (len > sizeof(int)) len =3D sizeof(int); - val =3D &ro->join_filters; + flag =3D ro->join_filters; + val =3D &flag; break; =20 default: --=20 2.49.1 From nobody Thu Oct 2 11:49:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C83FB2853ED; Wed, 17 Sep 2025 04:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084538; cv=none; b=Hi6yV2Ef1xxBAnVQVzQc0Ny3Yg9UoJq0VV0c6S1ZFYzbfiVNyem8niJp4s6ZCjAIWyJ2bV6gHnUjyp17uYIkL+gbHnlh3RGk2oW+tGep6p7omt5953wk7XxWhZer+irE2apnEUNSUUFq5L3yF4NxuuT7NBp/+o8BaolqgEkvpEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758084538; c=relaxed/simple; bh=PqBU4lww/+186uiwZ0u17g3aZEZ98fu4Q3fznlo6ETw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uuHm5L/Eyq22ZSnkPh+Ge2DOPOwX1sQQvIId1+naj0/PhopSmZEOCbaSsyoKjIt3NcgQ3Rj7ht2olc7rmsPJ+aeY7hp40FMbNhbiycSKphiFRBPaYqPL7+jSZLwqf8NChFaeFgEwEXjUw43jrtO+PheWmuIebBf0sw5XmYXZVuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AWCmQsFn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AWCmQsFn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91ECEC4CEF0; Wed, 17 Sep 2025 04:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758084538; bh=PqBU4lww/+186uiwZ0u17g3aZEZ98fu4Q3fznlo6ETw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AWCmQsFnk7zrtgRqzbuzPE4wBTI33NUziSghiv/um0+Qw6n2BhUQkxwuAOBAoTYoq gABl7a3TSSyVcPnDpMeHcdRUnMoP+Sgro8Xo0aVj9Udvi3J1wmdxZZW3LJeCvlZKbe /uKGlfNH/w+qJQ5violzgo6MknrnlkW+EdRA67a2hEDCAJTxQZn0nxG+BRLH1ta/7u JvcvXbwrb70kcBOy3rGBMqL098eD4YKsPh0hvCNrCzZ8GN9g9iF56fwSfZIoOlrQrQ RDYCjQK3DKLdnmFGSpe/eT0lacFdl5ruNqfQoY7I1TVtJsQpDSW8X0JBTCMKKb3c5q 2hBf+HIByXlNw== From: Vincent Mailhol Date: Wed, 17 Sep 2025 13:48:26 +0900 Subject: [PATCH v2 3/3] can: raw: reorder struct raw_sock's members to optimise packing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-can-raw-repack-v2-3-395e8b3a4437@kernel.org> References: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> In-Reply-To: <20250917-can-raw-repack-v2-0-395e8b3a4437@kernel.org> To: Oliver Hartkopp , Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Christophe Jaillet , Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5552; i=mailhol@kernel.org; h=from:subject:message-id; bh=PqBU4lww/+186uiwZ0u17g3aZEZ98fu4Q3fznlo6ETw=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnbDf7NBwOz9n869FB5jIpW2HlbU8PNQnfkdh8zbaqK 1NqW+KUjlIWBjEuBlkxRZZl5ZzcCh2F3mGH/lrCzGFlAhnCwMUpABM58ZaR4VGx5GsZE4ubXB7y e5U7mfaYXPYP0VN6sXP1zD2ddqFCGowMDQu+tV+v0r0WJMipqvX7P/ej7H2CPb+sqz04IxhZRJw YAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 struct raw_sock has several holes. Reorder the fields to save 8 bytes. Statistics before: $ pahole --class_name=3Draw_sock net/can/raw.o struct raw_sock { struct sock sk __attribute__((__aligned__(8))); /* 0 = 776 */ /* XXX last struct has 1 bit hole */ /* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */ int ifindex; /* 776 4 */ /* XXX 4 bytes hole, try to pack */ struct net_device * dev; /* 784 8 */ netdevice_tracker dev_tracker; /* 792 0 */ struct list_head notifier; /* 792 16 */ unsigned int bound:1; /* 808: 0 4 */ unsigned int loopback:1; /* 808: 1 4 */ unsigned int recv_own_msgs:1; /* 808: 2 4 */ unsigned int fd_frames:1; /* 808: 3 4 */ unsigned int xl_frames:1; /* 808: 4 4 */ unsigned int join_filters:1; /* 808: 5 4 */ /* XXX 2 bits hole, try to pack */ /* Bitfield combined with next fields */ struct can_raw_vcid_options raw_vcid_opts; /* 809 4 */ /* XXX 3 bytes hole, try to pack */ canid_t tx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_shifted; /* 820 4 */ canid_t rx_vcid_mask_shifted; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ can_err_mask_t err_mask; /* 848 4 */ /* XXX 4 bytes hole, try to pack */ struct uniqframe * uniq; /* 856 8 */ /* size: 864, cachelines: 14, members: 20 */ /* sum members: 852, holes: 3, sum holes: 11 */ /* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */ /* forced alignments: 1 */ /* last cacheline: 32 bytes */ } __attribute__((__aligned__(8))); ...and after: $ pahole --class_name=3Draw_sock net/can/raw.o struct raw_sock { struct sock sk __attribute__((__aligned__(8))); /* 0 = 776 */ /* XXX last struct has 1 bit hole */ /* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */ struct net_device * dev; /* 776 8 */ netdevice_tracker dev_tracker; /* 784 0 */ struct list_head notifier; /* 784 16 */ int ifindex; /* 800 4 */ unsigned int bound:1; /* 804: 0 4 */ unsigned int loopback:1; /* 804: 1 4 */ unsigned int recv_own_msgs:1; /* 804: 2 4 */ unsigned int fd_frames:1; /* 804: 3 4 */ unsigned int xl_frames:1; /* 804: 4 4 */ unsigned int join_filters:1; /* 804: 5 4 */ /* XXX 2 bits hole, try to pack */ /* Bitfield combined with next fields */ struct can_raw_vcid_options raw_vcid_opts; /* 805 4 */ /* XXX 3 bytes hole, try to pack */ canid_t tx_vcid_shifted; /* 812 4 */ canid_t rx_vcid_shifted; /* 816 4 */ canid_t rx_vcid_mask_shifted; /* 820 4 */ can_err_mask_t err_mask; /* 824 4 */ int count; /* 828 4 */ /* --- cacheline 13 boundary (832 bytes) --- */ struct can_filter dfilter; /* 832 8 */ struct can_filter * filter; /* 840 8 */ struct uniqframe * uniq; /* 848 8 */ /* size: 856, cachelines: 14, members: 20 */ /* sum members: 852, holes: 1, sum holes: 3 */ /* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */ /* member types with bit holes: 1, total: 1 */ /* forced alignments: 1 */ /* last cacheline: 24 bytes */ } __attribute__((__aligned__(8))); Acked-by: Oliver Hartkopp Signed-off-by: Vincent Mailhol --- net/can/raw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/can/raw.c b/net/can/raw.c index 5a5ded519cd1768456c234c42dc4e865f7350dab..bf65d67b5df0135bf02d90c5e10= 70898a4f5592e 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -82,10 +82,10 @@ struct uniqframe { =20 struct raw_sock { struct sock sk; - int ifindex; struct net_device *dev; netdevice_tracker dev_tracker; struct list_head notifier; + int ifindex; unsigned int bound:1; unsigned int loopback:1; unsigned int recv_own_msgs:1; @@ -96,10 +96,10 @@ struct raw_sock { canid_t tx_vcid_shifted; canid_t rx_vcid_shifted; canid_t rx_vcid_mask_shifted; + can_err_mask_t err_mask; int count; /* number of active filters */ struct can_filter dfilter; /* default/single filter */ struct can_filter *filter; /* pointer to filter(s) */ - can_err_mask_t err_mask; struct uniqframe __percpu *uniq; }; =20 --=20 2.49.1