Skip to contentSkip to conversation

ext4: Reduce object size of ext4_msg uses

PATCH In review Joe Perches 4 participants 4 messages Jul 25 – Jul 31 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Reduce object size of ext4_msg uses

Reduce the object size of ext4 ~2KB (~.5%) by combining the KERN_<LEVEL> and format uses of ext4_msg.

Separate them in __ext4_msg using printk_get_level and printk_skip_level and emitting the appropriate level.

x86 object sizes before and after:

defconfig size before:

$ size -t fs/ext4/built-in.a | tail -1
 579013	 121634	    316	 700963	  ab223	(TOTALS)

defconfig size after:

$ size -t fs/ext4/built-in.a | tail -1
 577196	 121650	    316	 699162	  aab1a	(TOTALS)

defconfig size before with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

$ size -t fs/ext4/built-in.a | tail -1
 537999	 121432	    316	 659747	  a1123	(TOTALS)

defconfig size after with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

$ size -t fs/ext4/built-in.a | tail -1
 536837	 121424	    316	 658577	  a0c91	(TOTALS)
---
 fs/ext4/ext4.h  | 12 ++++++------
 fs/ext4/super.c | 14 +++++++++-----
 2 files changed, 15 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +6 -6
index b37c136ea3ab..981918f32067 100644
@@ -3309,8 +3309,8 @@ void __ext4_warning(struct super_block *, const char *, unsigned int,
 extern __printf(4, 5)
 void __ext4_warning_inode(const struct inode *inode, const char *function,
 			  unsigned int line, const char *fmt, ...);
-extern __printf(3, 4)
-void __ext4_msg(struct super_block *, const char *, const char *, ...);
+extern __printf(2, 3)
+void __ext4_msg(struct super_block *, const char *fmt, ...);
 extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
 			   const char *, unsigned int, const char *);
 extern __printf(7, 8)
@@ -3354,8 +3354,8 @@ void __ext4_grp_locked_error(const char *, unsigned int,
 	__ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
 #define ext4_warning_inode(inode, fmt, ...)				\
 	__ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__)
-#define ext4_msg(sb, level, fmt, ...)				\
-	__ext4_msg(sb, level, fmt, ##__VA_ARGS__)
+#define ext4_msg(sb, level, fmt, ...)					\
+	__ext4_msg(sb, level fmt, ##__VA_ARGS__)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, __func__, __LINE__, msg)
 #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...)		\
@@ -3401,8 +3401,8 @@ do {									\
 } while (0)
 #define ext4_msg(sb, level, fmt, ...)					\
 do {									\
-	no_printk(fmt, ##__VA_ARGS__);					\
-	__ext4_msg(sb, "", " ");					\
+	no_printk(level fmt, ##__VA_ARGS__);				\
+	__ext4_msg(sb, "" " ");						\
 } while (0)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, "", 0, "")
fs/ext4/super.c +9 -5
index 245f67d10ded..72d6f6353a27 100644
@@ -981,11 +981,11 @@ void __ext4_std_error(struct super_block *sb, const char *function,
 	ext4_handle_error(sb, false, -errno, 0, 0, function, line);
 }
 
-void __ext4_msg(struct super_block *sb,
-		const char *prefix, const char *fmt, ...)
+void __ext4_msg(struct super_block *sb, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
+	int level;
 
 	if (sb) {
 		atomic_inc(&EXT4_SB(sb)->s_msg_count);
@@ -995,12 +995,16 @@ void __ext4_msg(struct super_block *sb,
 	}
 
 	va_start(args, fmt);
-	vaf.fmt = fmt;
+
+	level = printk_get_level(fmt);
+	vaf.fmt = printk_skip_level(fmt);
 	vaf.va = &args;
 	if (sb)
-		printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
+		printk("%c%cEXT4-fs (%s): %pV\n",
+		       KERN_SOH_ASCII, level, sb->s_id, &vaf);
 	else
-		printk("%sEXT4-fs: %pV\n", prefix, &vaf);
+		printk("%c%cEXT4-fs: %pV\n",
+		       KERN_SOH_ASCII, level, &vaf);
 	va_end(args);
 }
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Joe Perches

Reduce the object size of ext4 ~2KB (~.5%) by combining the KERN_<LEVEL> and format uses of ext4_msg.

Separate them in __ext4_msg using printk_get_level and printk_skip_level and emitting the appropriate level.

x86 object sizes before and after:

defconfig size before:

$ size -t fs/ext4/built-in.a | tail -1
579013 121634    316 700963  ab223 (TOTALS)

defconfig size after:

$ size -t fs/ext4/built-in.a | tail -1
577196 121650    316 699162  aab1a (TOTALS)

defconfig size before with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

Quoted 8 lines
$ size -t fs/ext4/built-in.a | tail -1
537999 121432    316 659747  a1123 (TOTALS)

defconfig size after with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

$ size -t fs/ext4/built-in.a | tail -1
536837 121424    316 658577  a0c91 (TOTALS)
Reviewed-by Andreas Dilger <[email protected] <mailto:[email protected]>>
Quoted 73 lines

---
fs/ext4/ext4.h | 12 ++++++------
fs/ext4/super.c | 14 +++++++++-----

2 files changed, 15 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +6 -6
index b37c136ea3ab..981918f32067 100644
@@ -3309,8 +3309,8 @@ void __ext4_warning(struct super_block *, const char *, unsigned int,
 extern __printf(4, 5)
 void __ext4_warning_inode(const struct inode *inode, const char *function,
 unsigned int line, const char *fmt, ...);
-extern __printf(3, 4)
-void __ext4_msg(struct super_block *, const char *, const char *, ...);
+extern __printf(2, 3)
+void __ext4_msg(struct super_block *, const char *fmt, ...);
 extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
  const char *, unsigned int, const char *);
 extern __printf(7, 8)
@@ -3354,8 +3354,8 @@ void __ext4_grp_locked_error(const char *, unsigned int,
 __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
 #define ext4_warning_inode(inode, fmt, ...) \
 __ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__)
-#define ext4_msg(sb, level, fmt, ...) \
- __ext4_msg(sb, level, fmt, ##__VA_ARGS__)
+#define ext4_msg(sb, level, fmt, ...) \
+ __ext4_msg(sb, level fmt, ##__VA_ARGS__)
 #define dump_mmp_msg(sb, mmp, msg) \
 __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg)
 #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \
@@ -3401,8 +3401,8 @@ do { \
 } while (0)
 #define ext4_msg(sb, level, fmt, ...) \
 do { \
- no_printk(fmt, ##__VA_ARGS__); \
- __ext4_msg(sb, "", " "); \
+ no_printk(level fmt, ##__VA_ARGS__); \
+ __ext4_msg(sb, "" " "); \
 } while (0)
 #define dump_mmp_msg(sb, mmp, msg) \
 __dump_mmp_msg(sb, mmp, "", 0, "")
fs/ext4/super.c +7 -4
index 245f67d10ded..72d6f6353a27 100644
@@ -981,11 +981,11 @@ void __ext4_std_error(struct super_block *sb, const char *function,
 ext4_handle_error(sb, false, -errno, 0, 0, function, line);
 }
 
-void __ext4_msg(struct super_block *sb,
- const char *prefix, const char *fmt, ...)
+void __ext4_msg(struct super_block *sb, const char *fmt, ...)
 {
 struct va_format vaf;
 va_list args;
+ int level;
 
 if (sb) {
 atomic_inc(&EXT4_SB(sb)->s_msg_count);
@@ -995,12 +995,16 @@ void __ext4_msg(struct super_block *sb,
 }
 
 va_start(args, fmt);
- vaf.fmt = fmt;
+
+ level = printk_get_level(fmt);
+ vaf.fmt = printk_skip_level(fmt);
 vaf.va = &args;
 if (sb)
- printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
+ printk("%c%cEXT4-fs (%s): %pV\n",
+       KERN_SOH_ASCII, level, sb->s_id, &vaf);
Quoted 7 lines

else
- printk("%sEXT4-fs: %pV\n", prefix, &vaf);
+ printk("%c%cEXT4-fs: %pV\n",
+ KERN_SOH_ASCII, level, &vaf);
va_end(args);
}

Cheers, Andreas

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Joe Perches
Quoted 17 lines · Joe Perches

Reduce the object size of ext4 ~2KB (~.5%) by combining the KERN_<LEVEL> and format uses of ext4_msg.

Separate them in __ext4_msg using printk_get_level and printk_skip_level and emitting the appropriate level.

x86 object sizes before and after:

defconfig size before:

$ size -t fs/ext4/built-in.a | tail -1
 579013	 121634	    316	 700963	  ab223	(TOTALS)

defconfig size after:

$ size -t fs/ext4/built-in.a | tail -1
 577196	 121650	    316	 699162	  aab1a	(TOTALS)

defconfig size before with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

Quoted 8 lines
$ size -t fs/ext4/built-in.a | tail -1
 537999	 121432	    316	 659747	  a1123	(TOTALS)

defconfig size after with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

$ size -t fs/ext4/built-in.a | tail -1
 536837	 121424	    316	 658577	  a0c91	(TOTALS)

Looks good. Feel free to add:

Honza

Quoted 80 lines
---
 fs/ext4/ext4.h  | 12 ++++++------
 fs/ext4/super.c | 14 +++++++++-----
 2 files changed, 15 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +6 -6
index b37c136ea3ab..981918f32067 100644
@@ -3309,8 +3309,8 @@ void __ext4_warning(struct super_block *, const char *, unsigned int,
 extern __printf(4, 5)
 void __ext4_warning_inode(const struct inode *inode, const char *function,
 			  unsigned int line, const char *fmt, ...);
-extern __printf(3, 4)
-void __ext4_msg(struct super_block *, const char *, const char *, ...);
+extern __printf(2, 3)
+void __ext4_msg(struct super_block *, const char *fmt, ...);
 extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
 			   const char *, unsigned int, const char *);
 extern __printf(7, 8)
@@ -3354,8 +3354,8 @@ void __ext4_grp_locked_error(const char *, unsigned int,
 	__ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
 #define ext4_warning_inode(inode, fmt, ...)				\
 	__ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__)
-#define ext4_msg(sb, level, fmt, ...)				\
-	__ext4_msg(sb, level, fmt, ##__VA_ARGS__)
+#define ext4_msg(sb, level, fmt, ...)					\
+	__ext4_msg(sb, level fmt, ##__VA_ARGS__)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, __func__, __LINE__, msg)
 #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...)		\
@@ -3401,8 +3401,8 @@ do {									\
 } while (0)
 #define ext4_msg(sb, level, fmt, ...)					\
 do {									\
-	no_printk(fmt, ##__VA_ARGS__);					\
-	__ext4_msg(sb, "", " ");					\
+	no_printk(level fmt, ##__VA_ARGS__);				\
+	__ext4_msg(sb, "" " ");						\
 } while (0)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, "", 0, "")
fs/ext4/super.c +9 -5
index 245f67d10ded..72d6f6353a27 100644
@@ -981,11 +981,11 @@ void __ext4_std_error(struct super_block *sb, const char *function,
 	ext4_handle_error(sb, false, -errno, 0, 0, function, line);
 }
 
-void __ext4_msg(struct super_block *sb,
-		const char *prefix, const char *fmt, ...)
+void __ext4_msg(struct super_block *sb, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
+	int level;
 
 	if (sb) {
 		atomic_inc(&EXT4_SB(sb)->s_msg_count);
@@ -995,12 +995,16 @@ void __ext4_msg(struct super_block *sb,
 	}
 
 	va_start(args, fmt);
-	vaf.fmt = fmt;
+
+	level = printk_get_level(fmt);
+	vaf.fmt = printk_skip_level(fmt);
 	vaf.va = &args;
 	if (sb)
-		printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
+		printk("%c%cEXT4-fs (%s): %pV\n",
+		       KERN_SOH_ASCII, level, sb->s_id, &vaf);
 	else
-		printk("%sEXT4-fs: %pV\n", prefix, &vaf);
+		printk("%c%cEXT4-fs: %pV\n",
+		       KERN_SOH_ASCII, level, &vaf);
 	va_end(args);
 }
 
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Joe Perches
Quoted 17 lines · Joe Perches

Reduce the object size of ext4 ~2KB (~.5%) by combining the KERN_<LEVEL> and format uses of ext4_msg.

Separate them in __ext4_msg using printk_get_level and printk_skip_level and emitting the appropriate level.

x86 object sizes before and after:

defconfig size before:

$ size -t fs/ext4/built-in.a | tail -1
 579013	 121634	    316	 700963	  ab223	(TOTALS)

defconfig size after:

$ size -t fs/ext4/built-in.a | tail -1
 577196	 121650	    316	 699162	  aab1a	(TOTALS)

defconfig size before with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

Quoted 8 lines
$ size -t fs/ext4/built-in.a | tail -1
 537999	 121432	    316	 659747	  a1123	(TOTALS)

defconfig size after with CONFIG_EXPERT=y and CONFIG_PRINTK=n:

$ size -t fs/ext4/built-in.a | tail -1
 536837	 121424	    316	 658577	  a0c91	(TOTALS)

Interesting, on powerpc64, we save around 1 - 2K. Its not much but sure, maybe some embedded or chip bringup scenarios might find it useful.

Regards,
ojaswin

Quoted 80 lines
---
 fs/ext4/ext4.h  | 12 ++++++------
 fs/ext4/super.c | 14 +++++++++-----
 2 files changed, 15 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +6 -6
index b37c136ea3ab..981918f32067 100644
@@ -3309,8 +3309,8 @@ void __ext4_warning(struct super_block *, const char *, unsigned int,
 extern __printf(4, 5)
 void __ext4_warning_inode(const struct inode *inode, const char *function,
 			  unsigned int line, const char *fmt, ...);
-extern __printf(3, 4)
-void __ext4_msg(struct super_block *, const char *, const char *, ...);
+extern __printf(2, 3)
+void __ext4_msg(struct super_block *, const char *fmt, ...);
 extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
 			   const char *, unsigned int, const char *);
 extern __printf(7, 8)
@@ -3354,8 +3354,8 @@ void __ext4_grp_locked_error(const char *, unsigned int,
 	__ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
 #define ext4_warning_inode(inode, fmt, ...)				\
 	__ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__)
-#define ext4_msg(sb, level, fmt, ...)				\
-	__ext4_msg(sb, level, fmt, ##__VA_ARGS__)
+#define ext4_msg(sb, level, fmt, ...)					\
+	__ext4_msg(sb, level fmt, ##__VA_ARGS__)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, __func__, __LINE__, msg)
 #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...)		\
@@ -3401,8 +3401,8 @@ do {									\
 } while (0)
 #define ext4_msg(sb, level, fmt, ...)					\
 do {									\
-	no_printk(fmt, ##__VA_ARGS__);					\
-	__ext4_msg(sb, "", " ");					\
+	no_printk(level fmt, ##__VA_ARGS__);				\
+	__ext4_msg(sb, "" " ");						\
 } while (0)
 #define dump_mmp_msg(sb, mmp, msg)					\
 	__dump_mmp_msg(sb, mmp, "", 0, "")
fs/ext4/super.c +9 -5
index 245f67d10ded..72d6f6353a27 100644
@@ -981,11 +981,11 @@ void __ext4_std_error(struct super_block *sb, const char *function,
 	ext4_handle_error(sb, false, -errno, 0, 0, function, line);
 }
 
-void __ext4_msg(struct super_block *sb,
-		const char *prefix, const char *fmt, ...)
+void __ext4_msg(struct super_block *sb, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
+	int level;
 
 	if (sb) {
 		atomic_inc(&EXT4_SB(sb)->s_msg_count);
@@ -995,12 +995,16 @@ void __ext4_msg(struct super_block *sb,
 	}
 
 	va_start(args, fmt);
-	vaf.fmt = fmt;
+
+	level = printk_get_level(fmt);
+	vaf.fmt = printk_skip_level(fmt);
 	vaf.va = &args;
 	if (sb)
-		printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
+		printk("%c%cEXT4-fs (%s): %pV\n",
+		       KERN_SOH_ASCII, level, sb->s_id, &vaf);
 	else
-		printk("%sEXT4-fs: %pV\n", prefix, &vaf);
+		printk("%c%cEXT4-fs: %pV\n",
+		       KERN_SOH_ASCII, level, &vaf);
 	va_end(args);
 }