Skip to contentSkip to conversation

ext4: move `ext4_count_free` to ext4.h so it can be easily inlined

PATCH Superseded Noah Goldstein 2 participants 4 messages Apr 21, 2023 – Apr 24, 2023 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: move `ext4_count_free` to ext4.h so it can be easily inlined

ext4_count_free is a one-line helper that is clearly better off being inlined. This saves a handful instructions in vmlinux on x86.

Instruction estimates use wc -l on objdump
Before: 8539271
After : 8539248

So saves roughly 20 instructions

---
 fs/ext4/bitmap.c | 5 -----
 fs/ext4/ext4.h   | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)
fs/ext4/bitmap.c +0 -5
index f63e028c638c..c3cd2b878bbd 100644
@@ -11,11 +11,6 @@
 #include <linux/buffer_head.h>
 #include "ext4.h"
 
-unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
-{
-	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
-}
-
 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
 				  struct ext4_group_desc *gdp,
 				  struct buffer_head *bh, int sz)
fs/ext4/ext4.h +5 -1
index 08b29c289da4..6e1d3c175a70 100644
@@ -2675,7 +2675,11 @@ struct mmpd_data {
 # define NORET_AND	noreturn,
 
 /* bitmap.c */
-extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
+static inline unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
+{
+	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
+}
+
 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
 				struct ext4_group_desc *gdp,
 				struct buffer_head *bh, int sz);
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Noah Goldstein

ext4_count_free is a one-line helper that is clearly better off being inlined. This saves a handful instructions in vmlinux on x86.

Instruction estimates use wc -l on objdump
Before: 8539271
After : 8539248

So saves roughly 20 instructions

Looks fine. Feel free to add:

Honza

Quoted 41 lines
---
 fs/ext4/bitmap.c | 5 -----
 fs/ext4/ext4.h   | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)
fs/ext4/bitmap.c +0 -5
index f63e028c638c..c3cd2b878bbd 100644
@@ -11,11 +11,6 @@
 #include <linux/buffer_head.h>
 #include "ext4.h"
 
-unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
-{
-	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
-}
-
 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
 				  struct ext4_group_desc *gdp,
 				  struct buffer_head *bh, int sz)
fs/ext4/ext4.h +5 -1
index 08b29c289da4..6e1d3c175a70 100644
@@ -2675,7 +2675,11 @@ struct mmpd_data {
 # define NORET_AND	noreturn,
 
 /* bitmap.c */
-extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
+static inline unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
+{
+	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
+}
+
 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
 				struct ext4_group_desc *gdp,
 				struct buffer_head *bh, int sz);
Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 9 lines · Jan Kara
Quoted 7 lines · Noah Goldstein

ext4_count_free is a one-line helper that is clearly better off being inlined. This saves a handful instructions in vmlinux on x86.

Instruction estimates use wc -l on objdump
Before: 8539271
After : 8539248

Quoted 8 lines
Quoted 3 lines

So saves roughly 20 instructions

Looks fine. Feel free to add:

Done, thank you.

Quoted 46 lines

Honza

Quoted 39 lines
---
 fs/ext4/bitmap.c | 5 -----
 fs/ext4/ext4.h   | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)
fs/ext4/bitmap.c +0 -5
index f63e028c638c..c3cd2b878bbd 100644
@@ -11,11 +11,6 @@
 #include <linux/buffer_head.h>
 #include "ext4.h"
 
-unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
-{
-     return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
-}
-
 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
                                struct ext4_group_desc *gdp,
                                struct buffer_head *bh, int sz)
fs/ext4/ext4.h +5 -2
index 08b29c289da4..6e1d3c175a70 100644
@@ -2675,7 +2675,11 @@ struct mmpd_data {
 # define NORET_AND   noreturn,
 
 /* bitmap.c */
-extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
+static inline unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
+{
+     return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
+}
+
 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
                              struct ext4_group_desc *gdp,
                              struct buffer_head *bh, int sz);
--
Quoted 2 lines

2.34.1

--
Jan Kara <[email protected]>
SUSE Labs, CR

#3 lore raw

PATCH v2 1/1 ext4: move `ext4_count_free` to ext4.h so it can be easily inlined

In reply to Noah Goldstein

ext4_count_free is a one-line helper that is clearly better off being inlined. This saves a handful instructions in vmlinux on x86.

Instruction estimates use wc -l on objdump
Before: 8539271
After : 8539248

So saves roughly 20 instructions

---
 fs/ext4/bitmap.c | 5 -----
 fs/ext4/ext4.h   | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)
fs/ext4/bitmap.c +0 -5
index f63e028c638c..c3cd2b878bbd 100644
@@ -11,11 +11,6 @@
 #include <linux/buffer_head.h>
 #include "ext4.h"
 
-unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
-{
-	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
-}
-
 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
 				  struct ext4_group_desc *gdp,
 				  struct buffer_head *bh, int sz)
fs/ext4/ext4.h +5 -1
index 08b29c289da4..6e1d3c175a70 100644
@@ -2675,7 +2675,11 @@ struct mmpd_data {
 # define NORET_AND	noreturn,
 
 /* bitmap.c */
-extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
+static inline unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
+{
+	return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
+}
+
 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
 				struct ext4_group_desc *gdp,
 				struct buffer_head *bh, int sz);
Signature · 1 line
2.34.1