From: Bart Van Assche <bvanassche@acm.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Bart Van Assche <bvanassche@acm.org>,
linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 13/31] Remove unnecessary __attribute__((packed)) annotations
Date: Thu, 21 Apr 2022 15:18:18 -0700 [thread overview]
Message-ID: <20220421221836.3935616-14-bvanassche@acm.org> (raw)
In-Reply-To: <20220421221836.3935616-1-bvanassche@acm.org>
Applying the __attribute__((packed)) annotation to members that do not
need it impacts performance negatively on architectures that do not
support efficient unaligned accesses (e.g. ARMv7). Hence minimize the
__attribute__((packed)) annotations.
See also CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS in the Linux kernel.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
fsck/quotaio.c | 2 +-
fsck/quotaio_tree.h | 2 +-
fsck/quotaio_v2.h | 6 +++---
fsck/xattr.h | 2 +-
include/f2fs_fs.h | 52 ++++++++++++++++++++++-----------------------
include/quota.h | 9 +++-----
tools/f2fscrypt.c | 4 ++--
7 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/fsck/quotaio.c b/fsck/quotaio.c
index 52e962432c72..a3815b0c8835 100644
--- a/fsck/quotaio.c
+++ b/fsck/quotaio.c
@@ -31,7 +31,7 @@ static const char * const extensions[MAXQUOTAS] = {
struct disk_dqheader {
__le32 dqh_magic;
__le32 dqh_version;
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct disk_dqheader) == 8, "");
diff --git a/fsck/quotaio_tree.h b/fsck/quotaio_tree.h
index b88c55c01d5c..8072c6e188fd 100644
--- a/fsck/quotaio_tree.h
+++ b/fsck/quotaio_tree.h
@@ -33,7 +33,7 @@ struct qt_disk_dqdbheader {
__le16 dqdh_entries; /* Number of valid entries in block */
__le16 dqdh_pad1;
__le32 dqdh_pad2;
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct qt_disk_dqdbheader) == 16, "");
diff --git a/fsck/quotaio_v2.h b/fsck/quotaio_v2.h
index a37300d78bd0..b054422f5a6e 100644
--- a/fsck/quotaio_v2.h
+++ b/fsck/quotaio_v2.h
@@ -18,7 +18,7 @@
struct v2_disk_dqheader {
__le32 dqh_magic; /* Magic number identifying file */
__le32 dqh_version; /* File version */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
@@ -36,7 +36,7 @@ struct v2_disk_dqinfo {
__le32 dqi_free_blk; /* Number of first free block in the list */
__le32 dqi_free_entry; /* Number of block with at least one
* free entry */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
@@ -53,7 +53,7 @@ struct v2r1_disk_dqblk {
__le64 dqb_curspace; /* current space occupied (in bytes) */
__le64 dqb_btime; /* time limit for excessive disk use */
__le64 dqb_itime; /* time limit for excessive inode use */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
diff --git a/fsck/xattr.h b/fsck/xattr.h
index 5709a7df7adb..4e4b50d47bd7 100644
--- a/fsck/xattr.h
+++ b/fsck/xattr.h
@@ -45,7 +45,7 @@ struct fscrypt_context {
u8 flags;
u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
-} __attribute__((packed));
+};
static_assert(sizeof(struct fscrypt_context) == 28, "");
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index cfd3b711f288..49438eb2e6f2 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -735,11 +735,10 @@ enum {
/*
* For superblock
*/
-#pragma pack(push, 1)
struct f2fs_device {
__u8 path[MAX_PATH_LEN];
__le32 total_segments;
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_device) == 68, "");
@@ -754,7 +753,8 @@ struct f2fs_super_block {
__le32 segs_per_sec; /* # of segments per section */
__le32 secs_per_zone; /* # of sections per zone */
__le32 checksum_offset; /* checksum offset inside super block */
- __le64 block_count; /* total # of user blocks */
+ __le64 block_count __attribute__((packed));
+ /* total # of user blocks */
__le32 section_count; /* total # of sections */
__le32 segment_count; /* total # of segments */
__le32 segment_count_ckpt; /* # of segments for checkpoint */
@@ -781,14 +781,14 @@ struct f2fs_super_block {
__le32 feature; /* defined features */
__u8 encryption_level; /* versioning level for encryption */
__u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
- struct f2fs_device devs[MAX_DEVICES]; /* device list */
- __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
+ struct f2fs_device devs[MAX_DEVICES] __attribute__((packed)); /* device list */
+ __le32 qf_ino[F2FS_MAX_QUOTAS] __attribute__((packed)); /* quota inode numbers */
__u8 hot_ext_count; /* # of hot file extension */
__le16 s_encoding; /* Filename charset encoding */
__le16 s_encoding_flags; /* Filename charset encoding flags */
__u8 reserved[306]; /* valid reserved region */
__le32 crc; /* checksum of superblock */
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_super_block) == 3072, "");
@@ -841,7 +841,7 @@ struct f2fs_checkpoint {
/* SIT and NAT version bitmap */
unsigned char sit_nat_version_bitmap[];
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_checkpoint) == 192, "");
@@ -867,7 +867,7 @@ struct f2fs_orphan_block {
__le16 blk_count; /* Number of orphan inode blocks in CP */
__le32 entry_count; /* Total number of orphan nodes in current CP */
__le32 check_sum; /* CRC32 for orphan inode block */
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_orphan_block) == 4096, "");
@@ -878,7 +878,7 @@ struct f2fs_extent {
__le32 fofs; /* start file offset of the extent */
__le32 blk_addr; /* start block address of the extent */
__le32 len; /* lengh of the extent */
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_extent) == 12, "");
@@ -1005,7 +1005,7 @@ struct f2fs_inode {
__u8 i_name[F2FS_NAME_LEN]; /* file name for SPOR */
__u8 i_dir_level; /* dentry_level for large dir */
- struct f2fs_extent i_ext; /* caching a largest extent */
+ struct f2fs_extent i_ext __attribute__((packed)); /* caching a largest extent */
union {
struct {
@@ -1025,19 +1025,21 @@ struct f2fs_inode {
};
__le32 i_nid[5]; /* direct(2), indirect(2),
double_indirect(1) node id */
-} __attribute__((packed));
+};
+static_assert(offsetof(struct f2fs_inode, i_extra_end) -
+ offsetof(struct f2fs_inode, i_extra_isize) == 36, "");
static_assert(sizeof(struct f2fs_inode) == 4072, "");
struct direct_node {
__le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */
-} __attribute__((packed));
+};
static_assert(sizeof(struct direct_node) == 4072, "");
struct indirect_node {
__le32 nid[NIDS_PER_BLOCK]; /* array of data block address */
-} __attribute__((packed));
+};
static_assert(sizeof(struct indirect_node) == 4072, "");
@@ -1054,9 +1056,9 @@ struct node_footer {
__le32 nid; /* node id */
__le32 ino; /* inode nunmber */
__le32 flag; /* include cold/fsync/dentry marks and offset */
- __le64 cp_ver; /* checkpoint version */
+ __le64 cp_ver __attribute__((packed)); /* checkpoint version */
__le32 next_blkaddr; /* next node page block address */
-} __attribute__((packed));
+};
static_assert(sizeof(struct node_footer) == 24, "");
@@ -1068,7 +1070,7 @@ struct f2fs_node {
struct indirect_node in;
};
struct node_footer footer;
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_node) == 4096, "");
@@ -1090,7 +1092,7 @@ static_assert(sizeof(struct f2fs_nat_entry) == 9, "");
struct f2fs_nat_block {
struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_nat_block) == 4095, "");
@@ -1137,7 +1139,7 @@ static_assert(sizeof(struct f2fs_sit_entry) == 74, "");
struct f2fs_sit_block {
struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_sit_block) == 4070, "");
@@ -1181,8 +1183,8 @@ static_assert(sizeof(struct f2fs_summary) == 7, "");
struct summary_footer {
unsigned char entry_type; /* SUM_TYPE_XXX */
- __le32 check_sum; /* summary checksum */
-} __attribute__((packed));
+ __le32 check_sum __attribute__((packed)); /* summary checksum */
+};
static_assert(sizeof(struct summary_footer) == 5, "");
@@ -1222,7 +1224,7 @@ static_assert(sizeof(struct nat_journal_entry) == 13, "");
struct nat_journal {
struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES];
__u8 reserved[NAT_JOURNAL_RESERVED];
-} __attribute__((packed));
+};
static_assert(sizeof(struct nat_journal) == 505, "");
@@ -1236,7 +1238,7 @@ static_assert(sizeof(struct sit_journal_entry) == 78, "");
struct sit_journal {
struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES];
__u8 reserved[SIT_JOURNAL_RESERVED];
-} __attribute__((packed));
+};
static_assert(sizeof(struct sit_journal) == 505, "");
@@ -1267,7 +1269,7 @@ struct f2fs_summary_block {
struct f2fs_summary entries[ENTRIES_IN_SUM];
struct f2fs_journal journal;
struct summary_footer footer;
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_summary_block) == 4096, "");
@@ -1321,12 +1323,10 @@ struct f2fs_dentry_block {
__u8 reserved[SIZE_OF_RESERVED];
struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_dentry_block) == 4096, "");
-#pragma pack(pop)
-
/* for inline stuff */
#define DEF_INLINE_RESERVED_SIZE 1
diff --git a/include/quota.h b/include/quota.h
index 5b7aaa891d28..f0eff71a9a26 100644
--- a/include/quota.h
+++ b/include/quota.h
@@ -44,11 +44,10 @@ enum quota_type {
#define QT_TREEOFF 1 /* Offset of tree in file in blocks */
-#pragma pack(push, 1)
struct v2_disk_dqheader {
uint32_t dqh_magic; /* Magic number identifying file */
uint32_t dqh_version; /* File version */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
@@ -60,7 +59,7 @@ struct v2_disk_dqinfo {
uint32_t dqi_blocks; /* Number of blocks in file */
uint32_t dqi_free_blk; /* Number of first free block in the list */
uint32_t dqi_free_entry; /* Number of block with at least one free entry */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
@@ -77,10 +76,8 @@ struct v2r1_disk_dqblk {
__le64 dqb_curspace; /* current space occupied (in bytes) */
__le64 dqb_btime; /* time limit for excessive disk use */
__le64 dqb_itime; /* time limit for excessive inode use */
-} __attribute__ ((packed));
+};
static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
-#pragma pack(pop)
-
#endif
diff --git a/tools/f2fscrypt.c b/tools/f2fscrypt.c
index 97624ba5e185..72bfb6467300 100644
--- a/tools/f2fscrypt.c
+++ b/tools/f2fscrypt.c
@@ -102,7 +102,7 @@ struct f2fs_fscrypt_policy {
__u8 filenames_encryption_mode;
__u8 flags;
__u8 master_key_descriptor[F2FS_KEY_DESCRIPTOR_SIZE];
-} __attribute__((packed));
+};
static_assert(sizeof(struct f2fs_fscrypt_policy) == 12, "");
@@ -121,7 +121,7 @@ struct f2fs_encryption_key {
__u32 mode;
char raw[F2FS_MAX_KEY_SIZE];
__u32 size;
-} __attribute__((__packed__));
+};
static_assert(sizeof(struct f2fs_encryption_key) == 72, "");
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2022-04-21 22:19 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 22:18 [f2fs-dev] [PATCH 00/31] Make f2fs-tools easier to maintain Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 01/31] configure.ac: Stop using obsolete macros Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 02/31] configure.ac: Remove two prototype tests Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 03/31] configure.ac: Enable the automake -Wall option Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 04/31] configure.ac: Sort header file names alphabetically Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 05/31] configure.ac: Enable cross-compilation Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 06/31] Switch from the u_int to the uint types Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 07/31] Change the ANDROID_WINDOWS_HOST macro into _WIN32 Bart Van Assche
2022-04-22 17:53 ` Jaegeuk Kim
2022-04-21 22:18 ` [f2fs-dev] [PATCH 08/31] ci: Build f2fstools upon push and pull requests Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 09/31] Change one array member into a flexible array member Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 10/31] Verify structure sizes at compile time Bart Van Assche
2022-06-10 2:05 ` Peter Collingbourne via Linux-f2fs-devel
2022-06-10 17:12 ` Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 11/31] Suppress a compiler warning Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 12/31] f2fs_fs.h: Use standard fixed width integer types Bart Van Assche
2022-04-21 22:18 ` Bart Van Assche [this message]
2022-04-21 22:18 ` [f2fs-dev] [PATCH 14/31] Move the be32_to_cpu() definition Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 15/31] Include <stddef.h> instead of defining offsetof() Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 16/31] Use %zu to format size_t Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 17/31] Fix the MinGW build Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 18/31] configure.ac: Detect the sparse/sparse.h header Bart Van Assche
2022-04-22 19:01 ` Jaegeuk Kim
2022-04-21 22:18 ` [f2fs-dev] [PATCH 19/31] configure.ac: Detect selinux/android.h Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 20/31] mkfs/f2fs_format.c: Suppress a compiler warning Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 21/31] fsck: Remove a superfluous include directive Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 22/31] tools/f2fscrypt.c: Fix build without uuid/uuid.h header file Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 23/31] fsck/main.c: Suppress a compiler warning Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 24/31] Change #ifdef _WIN32 checks into #ifdef HAVE_.* Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 25/31] fsck/segment.c: Remove dead code Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 26/31] tools/f2fs_io: Fix the type of 'ret' Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 27/31] Annotate switch/case fallthrough Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 28/31] Suppress a compiler warning about integer truncation Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 29/31] Support cross-compiliation for PowerPC Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 30/31] Fix PowerPC format string warnings Bart Van Assche
2022-04-21 22:18 ` [f2fs-dev] [PATCH 31/31] ci: Enable -Wall, -Wextra and -Werror Bart Van Assche
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=20220421221836.3935616-14-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/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 NNTP newsgroup(s).