Skip to content

Commit a4ae309

Browse files
Eric Sandeenjankara
authored andcommitted
ext3: speed up file creates by optimizing rec_len functions
The addition of 64k block capability in the rec_len_from_disk and rec_len_to_disk functions added a bit of math overhead which slows down file create workloads needlessly when the architecture cannot even support 64k blocks, thanks to page size limits. Similar changes already exist in the ext4 codebase. The directory entry checking can also be optimized a bit by sprinkling in some unlikely() conditions to move the error handling out of line. bonnie++ sequential file creates on a 512MB ramdisk speeds up from about 77,000/s to about 82,000/s, about a 6% improvement. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 40a063f commit a4ae309

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎fs/ext3/dir.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,26 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
6969
const char * error_msg = NULL;
7070
const int rlen = ext3_rec_len_from_disk(de->rec_len);
7171

72-
if (rlen < EXT3_DIR_REC_LEN(1))
72+
if (unlikely(rlen < EXT3_DIR_REC_LEN(1)))
7373
error_msg = "rec_len is smaller than minimal";
74-
else if (rlen % 4 != 0)
74+
else if (unlikely(rlen % 4 != 0))
7575
error_msg = "rec_len % 4 != 0";
76-
else if (rlen < EXT3_DIR_REC_LEN(de->name_len))
76+
else if (unlikely(rlen < EXT3_DIR_REC_LEN(de->name_len)))
7777
error_msg = "rec_len is too small for name_len";
78-
else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
78+
else if (unlikely((((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)))
7979
error_msg = "directory entry across blocks";
80-
else if (le32_to_cpu(de->inode) >
81-
le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
80+
else if (unlikely(le32_to_cpu(de->inode) >
81+
le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)))
8282
error_msg = "inode out of bounds";
8383

84-
if (error_msg != NULL)
84+
if (unlikely(error_msg != NULL))
8585
ext3_error (dir->i_sb, function,
8686
"bad entry in directory #%lu: %s - "
8787
"offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
8888
dir->i_ino, error_msg, offset,
8989
(unsigned long) le32_to_cpu(de->inode),
9090
rlen, de->name_len);
91+
9192
return error_msg == NULL ? 1 : 0;
9293
}
9394

‎include/linux/ext3_fs.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,21 +724,30 @@ struct ext3_dir_entry_2 {
724724
~EXT3_DIR_ROUND)
725725
#define EXT3_MAX_REC_LEN ((1<<16)-1)
726726

727+
/*
728+
* Tests against MAX_REC_LEN etc were put in place for 64k block
729+
* sizes; if that is not possible on this arch, we can skip
730+
* those tests and speed things up.
731+
*/
727732
static inline unsigned ext3_rec_len_from_disk(__le16 dlen)
728733
{
729734
unsigned len = le16_to_cpu(dlen);
730735

736+
#if (PAGE_CACHE_SIZE >= 65536)
731737
if (len == EXT3_MAX_REC_LEN)
732738
return 1 << 16;
739+
#endif
733740
return len;
734741
}
735742

736743
static inline __le16 ext3_rec_len_to_disk(unsigned len)
737744
{
745+
#if (PAGE_CACHE_SIZE >= 65536)
738746
if (len == (1 << 16))
739747
return cpu_to_le16(EXT3_MAX_REC_LEN);
740748
else if (len > (1 << 16))
741749
BUG();
750+
#endif
742751
return cpu_to_le16(len);
743752
}
744753

0 commit comments

Comments
 (0)