From: Mikulas Patocka <mpatocka@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>,
Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Hannes Reinecke <hare@suse.de>,
Mark Wunderlich <mark.wunderlich@intel.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Helge Deller <deller@gmx.de>,
John David Anglin <dave.anglin@bell.net>,
linux-block@vger.kernel.org, linux-parisc@vger.kernel.org
Subject: [PATCH] block: use the __packed attribute only on architectures where it is efficient
Date: Tue, 6 Feb 2024 12:14:14 +0100 (CET) [thread overview]
Message-ID: <78172b8-74bc-1177-6ac7-7a7e7a44d18@redhat.com> (raw)
The __packed macro (expanding to __attribute__((__packed__))) specifies
that the structure has an alignment of 1. Therefore, it may be arbitrarily
misaligned. On architectures that don't have hardware support for
unaligned accesses, gcc generates very inefficient code that accesses the
structure fields byte-by-byte and assembles the result using shifts and
ors.
For example, on PA-RISC, this function is compiled to 23 instructions with
the __packed attribute and only 2 instructions without the __packed
attribute.
This commit changes the definition of 'struct bvec_iter', so that it only
uses the __packed attribute on architectures where unaligned access is
efficient.
sector_t get_sector(struct bvec_iter *iter)
{
return iter->bi_sector;
}
with __packed:
0000000000000000 <get_sector>:
0: 0f 40 10 1f ldb 0(r26),r31
4: 0f 42 10 1c ldb 1(r26),ret0
8: f3 ff 0b 18 depd,z,* r31,7,8,r31
c: f3 9c 0a 10 depd,z,* ret0,15,16,ret0
10: 0b fc 02 5c or ret0,r31,ret0
14: 0f 44 10 15 ldb 2(r26),r21
18: 0f 46 10 14 ldb 3(r26),r20
1c: f2 b5 09 08 depd,z,* r21,23,24,r21
20: 0f 48 10 13 ldb 4(r26),r19
24: 0b 95 02 55 or r21,ret0,r21
28: 0f 4a 10 1f ldb 5(r26),r31
2c: f2 94 08 00 depd,z,* r20,31,32,r20
30: 0f 4c 10 1c ldb 6(r26),ret0
34: 0f 4e 10 16 ldb 7(r26),r22
38: 0a b4 02 54 or r20,r21,r20
3c: f2 73 13 18 depd,z,* r19,39,40,r19
40: f3 ff 12 10 depd,z,* r31,47,48,r31
44: 0a 93 02 53 or r19,r20,r19
48: f3 9c 11 08 depd,z,* ret0,55,56,ret0
4c: 0a 7f 02 5f or r31,r19,r31
50: 0b fc 02 5c or ret0,r31,ret0
54: e8 40 d0 00 bve (rp)
58: 0b 96 02 5c or r22,ret0,ret0
5c: 00 00 00 00 break 0,0
without __packed:
0000000000000000 <get_sector>:
0: e8 40 d0 00 bve (rp)
4: 0f 40 10 dc ldd 0(r26),ret0
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 19416123ab3e ("block: define 'struct bvec_iter' as packed")
Cc: stable@vger.kernel.org # v5.16+
---
include/linux/bvec.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Index: linux-2.6/include/linux/bvec.h
===================================================================
--- linux-2.6.orig/include/linux/bvec.h 2023-09-05 14:46:02.000000000 +0200
+++ linux-2.6/include/linux/bvec.h 2024-02-06 11:49:56.000000000 +0100
@@ -83,7 +83,11 @@ struct bvec_iter {
unsigned int bi_bvec_done; /* number of bytes completed in
current bvec */
-} __packed;
+}
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+__packed
+#endif
+;
struct bvec_iter_all {
struct bio_vec bv;
next reply other threads:[~2024-02-06 11:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 11:14 Mikulas Patocka [this message]
2024-02-06 14:18 ` [PATCH] block: use the __packed attribute only on architectures where it is efficient Ming Lei
2024-02-06 18:31 ` Mikulas Patocka
2024-02-07 2:43 ` Ming Lei
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=78172b8-74bc-1177-6ac7-7a7e7a44d18@redhat.com \
--to=mpatocka@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=dave.anglin@bell.net \
--cc=deller@gmx.de \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=mark.wunderlich@intel.com \
--cc=ming.lei@redhat.com \
--cc=sagi@grimberg.me \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).