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: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index d42a8c4..391e53a 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -956,7 +956,7 @@
goto cleanup;
}
bh = sb_getblk(inode->i_sb, newblock);
- if (!bh) {
+ if (unlikely(!bh)) {
err = -ENOMEM;
goto cleanup;
}
@@ -1029,7 +1029,7 @@
oldblock = newblock;
newblock = ablocks[--a];
bh = sb_getblk(inode->i_sb, newblock);
- if (!bh) {
+ if (unlikely(!bh)) {
err = -ENOMEM;
goto cleanup;
}
@@ -1142,7 +1142,7 @@
return err;
bh = sb_getblk(inode->i_sb, newblock);
- if (!bh)
+ if (unlikely(!bh))
return -ENOMEM;
lock_buffer(bh);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9ccc140..93a7e845 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -713,7 +713,7 @@
return NULL;
bh = sb_getblk(inode->i_sb, map.m_pblk);
- if (!bh) {
+ if (unlikely(!bh)) {
*errp = -ENOMEM;
return NULL;
}
@@ -3660,7 +3660,7 @@
iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb);
bh = sb_getblk(sb, block);
- if (!bh)
+ if (unlikely(!bh))
return -ENOMEM;
if (!buffer_uptodate(bh)) {
lock_buffer(bh);
@@ -3693,7 +3693,7 @@
/* Is the inode bitmap in cache? */
bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp));
- if (!bitmap_bh)
+ if (unlikely(!bitmap_bh))
goto make_io;
/*
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index 44734f1..f9b5515 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -93,7 +93,7 @@
*bh = NULL;
}
}
- if (!*bh) {
+ if (unlikely(!*bh)) {
ext4_warning(sb, "Error while reading MMP block %llu",
mmp_block);
return -EIO;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 02824dc..05f8d45 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -333,7 +333,7 @@
int err;
bh = sb_getblk(sb, blk);
- if (!bh)
+ if (unlikely(!bh))
return ERR_PTR(-ENOMEM);
if ((err = ext4_journal_get_write_access(handle, bh))) {
brelse(bh);
@@ -410,7 +410,7 @@
return err;
bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap);
- if (!bh)
+ if (unlikely(!bh))
return -ENOMEM;
err = ext4_journal_get_write_access(handle, bh);
@@ -500,7 +500,7 @@
goto out;
gdb = sb_getblk(sb, block);
- if (!gdb) {
+ if (unlikely(!gdb)) {
err = -ENOMEM;
goto out;
}
@@ -1064,7 +1064,7 @@
ext4_bg_has_super(sb, group));
bh = sb_getblk(sb, backup_block);
- if (!bh) {
+ if (unlikely(!bh)) {
err = -ENOMEM;
break;
}
@@ -1168,7 +1168,7 @@
static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block)
{
struct buffer_head *bh = sb_getblk(sb, block);
- if (!bh)
+ if (unlikely(!bh))
return NULL;
if (!bh_uptodate_or_lock(bh)) {
if (bh_submit_read(bh) < 0) {
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 07d684a..c68990c 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -886,7 +886,7 @@
(unsigned long long)block);
new_bh = sb_getblk(sb, block);
- if (!new_bh) {
+ if (unlikely(!new_bh)) {
error = -ENOMEM;
getblk_failed:
ext4_free_blocks(handle, inode, NULL, block, 1,