提交 aebf0243 编写于 作者: W Wang Shilong 提交者: Theodore Ts'o

ext4: use unlikely to improve the efficiency of the kernel

Because the function 'sb_getblk' seldomly fails to return NULL
value,it will be better to use 'unlikely' to optimize it.
Signed-off-by: NWang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 860d21e2
...@@ -956,7 +956,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, ...@@ -956,7 +956,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
goto cleanup; goto cleanup;
} }
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) { if (unlikely(!bh)) {
err = -ENOMEM; err = -ENOMEM;
goto cleanup; goto cleanup;
} }
...@@ -1029,7 +1029,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, ...@@ -1029,7 +1029,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
oldblock = newblock; oldblock = newblock;
newblock = ablocks[--a]; newblock = ablocks[--a];
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) { if (unlikely(!bh)) {
err = -ENOMEM; err = -ENOMEM;
goto cleanup; goto cleanup;
} }
...@@ -1142,7 +1142,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode, ...@@ -1142,7 +1142,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
return err; return err;
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) if (unlikely(!bh))
return -ENOMEM; return -ENOMEM;
lock_buffer(bh); lock_buffer(bh);
......
...@@ -713,7 +713,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -713,7 +713,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
return NULL; return NULL;
bh = sb_getblk(inode->i_sb, map.m_pblk); bh = sb_getblk(inode->i_sb, map.m_pblk);
if (!bh) { if (unlikely(!bh)) {
*errp = -ENOMEM; *errp = -ENOMEM;
return NULL; return NULL;
} }
...@@ -3660,7 +3660,7 @@ static int __ext4_get_inode_loc(struct inode *inode, ...@@ -3660,7 +3660,7 @@ static int __ext4_get_inode_loc(struct inode *inode,
iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb); iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb);
bh = sb_getblk(sb, block); bh = sb_getblk(sb, block);
if (!bh) if (unlikely(!bh))
return -ENOMEM; return -ENOMEM;
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
lock_buffer(bh); lock_buffer(bh);
...@@ -3693,7 +3693,7 @@ static int __ext4_get_inode_loc(struct inode *inode, ...@@ -3693,7 +3693,7 @@ static int __ext4_get_inode_loc(struct inode *inode,
/* Is the inode bitmap in cache? */ /* Is the inode bitmap in cache? */
bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp)); bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp));
if (!bitmap_bh) if (unlikely(!bitmap_bh))
goto make_io; goto make_io;
/* /*
......
...@@ -93,7 +93,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, ...@@ -93,7 +93,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
*bh = NULL; *bh = NULL;
} }
} }
if (!*bh) { if (unlikely(!*bh)) {
ext4_warning(sb, "Error while reading MMP block %llu", ext4_warning(sb, "Error while reading MMP block %llu",
mmp_block); mmp_block);
return -EIO; return -EIO;
......
...@@ -333,7 +333,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, ...@@ -333,7 +333,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
int err; int err;
bh = sb_getblk(sb, blk); bh = sb_getblk(sb, blk);
if (!bh) if (unlikely(!bh))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if ((err = ext4_journal_get_write_access(handle, bh))) { if ((err = ext4_journal_get_write_access(handle, bh))) {
brelse(bh); brelse(bh);
...@@ -410,7 +410,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle, ...@@ -410,7 +410,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
return err; return err;
bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap); bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap);
if (!bh) if (unlikely(!bh))
return -ENOMEM; return -ENOMEM;
err = ext4_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
...@@ -500,7 +500,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb, ...@@ -500,7 +500,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
goto out; goto out;
gdb = sb_getblk(sb, block); gdb = sb_getblk(sb, block);
if (!gdb) { if (unlikely(!gdb)) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
...@@ -1064,7 +1064,7 @@ static void update_backups(struct super_block *sb, int blk_off, char *data, ...@@ -1064,7 +1064,7 @@ static void update_backups(struct super_block *sb, int blk_off, char *data,
ext4_bg_has_super(sb, group)); ext4_bg_has_super(sb, group));
bh = sb_getblk(sb, backup_block); bh = sb_getblk(sb, backup_block);
if (!bh) { if (unlikely(!bh)) {
err = -ENOMEM; err = -ENOMEM;
break; break;
} }
...@@ -1168,7 +1168,7 @@ static int ext4_add_new_descs(handle_t *handle, struct super_block *sb, ...@@ -1168,7 +1168,7 @@ static int ext4_add_new_descs(handle_t *handle, struct super_block *sb,
static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block) static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block)
{ {
struct buffer_head *bh = sb_getblk(sb, block); struct buffer_head *bh = sb_getblk(sb, block);
if (!bh) if (unlikely(!bh))
return NULL; return NULL;
if (!bh_uptodate_or_lock(bh)) { if (!bh_uptodate_or_lock(bh)) {
if (bh_submit_read(bh) < 0) { if (bh_submit_read(bh) < 0) {
......
...@@ -886,7 +886,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -886,7 +886,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
(unsigned long long)block); (unsigned long long)block);
new_bh = sb_getblk(sb, block); new_bh = sb_getblk(sb, block);
if (!new_bh) { if (unlikely(!new_bh)) {
error = -ENOMEM; error = -ENOMEM;
getblk_failed: getblk_failed:
ext4_free_blocks(handle, inode, NULL, block, 1, ext4_free_blocks(handle, inode, NULL, block, 1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册