From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: wqu@suse.com, David Sterba <dsterba@suse.com>
Subject: [PATCH] btrfs: reorder struct btrfs_key for better alignment
Date: Tue, 18 Jun 2019 16:15:14 +0200 [thread overview]
Message-ID: <20190618141514.17322-1-dsterba@suse.com> (raw)
We don't use the plain key for any on-disk operations so there's no
requirement for the member order. As the offset is a u64 that should be
on an 8byte aligned address, this can generate ineffective code on
strict alignment architectures and can potentially hurt even on others
(cross-cacheline access).
The resulting asm code on x86_64 only differes in the offset, no significant
change in size of the object size.
The alignment of the structure is unchanged.
Signed-off-by: David Sterba <dsterba@suse.com>
---
include/uapi/linux/btrfs_tree.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index aff1356c2bb8..9ca7adcf3b7f 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -342,10 +342,17 @@ struct btrfs_disk_key {
__le64 offset;
} __attribute__ ((__packed__));
+/*
+ * NOTE: this structure does not match the on-disk format of key and must be
+ * converted with the right helpers. The btrfs_key is for in-memory use and the
+ * members are reordered for better alignment. It's still packed as it's never
+ * used in arrays and the extra alignment would consume stack space in
+ * functions.
+ */
struct btrfs_key {
__u64 objectid;
- __u8 type;
__u64 offset;
+ __u8 type;
} __attribute__ ((__packed__));
struct btrfs_dev_item {
--
2.21.0
next reply other threads:[~2019-06-18 14:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 14:15 David Sterba [this message]
2019-06-18 14:20 ` [PATCH] btrfs: reorder struct btrfs_key for better alignment Nikolay Borisov
2019-06-19 1:37 ` Qu Wenruo
2019-06-19 13:39 ` David Sterba
2019-06-19 13:50 ` Qu Wenruo
2019-06-19 14:14 ` David Sterba
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=20190618141514.17322-1-dsterba@suse.com \
--to=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.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