ext4: Speedup WB_SYNC_ALL pass called from sync(2)
[firefly-linux-kernel-4.4.55.git] / fs / ext4 / inode.c
index 6e39895a91b80aaae3914cc3a51756b3fa48a4c8..ab3e8357929d35fedb779e964d41f02ceb862297 100644 (file)
@@ -514,6 +514,12 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
                  "logical block %lu\n", inode->i_ino, flags, map->m_len,
                  (unsigned long) map->m_lblk);
 
+       /*
+        * ext4_map_blocks returns an int, and m_len is an unsigned int
+        */
+       if (unlikely(map->m_len > INT_MAX))
+               map->m_len = INT_MAX;
+
        /* Lookup extent status tree firstly */
        if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) {
                ext4_es_lru_add(inode);
@@ -3608,6 +3614,12 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
        up_write(&EXT4_I(inode)->i_data_sem);
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
+
+       /* Now release the pages again to reduce race window */
+       if (last_block_offset > first_block_offset)
+               truncate_pagecache_range(inode, first_block_offset,
+                                        last_block_offset);
+
        inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
        ext4_mark_inode_dirty(handle, inode);
 out_stop:
@@ -4443,7 +4455,12 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
                        return -EIO;
                }
 
-               if (wbc->sync_mode != WB_SYNC_ALL)
+               /*
+                * No need to force transaction in WB_SYNC_NONE mode. Also
+                * ext4_sync_fs() will force the commit after everything is
+                * written.
+                */
+               if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
                        return 0;
 
                err = ext4_force_commit(inode->i_sb);
@@ -4453,7 +4470,11 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
                err = __ext4_get_inode_loc(inode, &iloc, 0);
                if (err)
                        return err;
-               if (wbc->sync_mode == WB_SYNC_ALL)
+               /*
+                * sync(2) will flush the whole buffer cache. No need to do
+                * it here separately for each inode.
+                */
+               if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
                        sync_dirty_buffer(iloc.bh);
                if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
                        EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,