diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 5b0e26a..3eeb68b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1249,6 +1249,9 @@ struct ext4_sb_info {
 
 	/* record the last minlen when FITRIM is called. */
 	atomic_t s_last_trim_minblks;
+
+	/* to sync the delayed allocation's buffers */
+	atomic_t s_need_da_sync;
 };
 
 static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 848f436..8d317a3 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2368,6 +2368,14 @@ static int ext4_nonda_switch(struct super_block *sb)
 		 */
 		return 1;
 	}
+
+	/*
+	 * Second case to switch to non dealloc mode, if we want to write all the ext4
+	 * data out.
+	 */
+	if (atomic_read(&sbi->s_need_da_sync) > 0)
+		return 1;
+
 	/*
 	 * Even if we don't switch but are nearing capacity,
 	 * start pushing delalloc when 1/2 of free blocks are dirty.
@@ -4665,6 +4673,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
 	journal_t *journal;
 	handle_t *handle;
 	int err;
+	struct super_block *sb = inode->i_sb;
+	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
 
 	/*
 	 * We have to be very careful here: changing a data block's
@@ -4682,6 +4692,13 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
 	if (is_journal_aborted(journal))
 		return -EROFS;
 
+	/*
+	 * To write all delayed allocation's buffers out before calling
+	 * jbd2_journal_flush(). Because it cannot flush the buffers.
+	 */
+	atomic_inc(&sbi->s_need_da_sync);
+	sync_filesystem(sb);
+
 	jbd2_journal_lock_updates(journal);
 	jbd2_journal_flush(journal);
 
@@ -4700,6 +4717,7 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
 	ext4_set_aops(inode);
 
 	jbd2_journal_unlock_updates(journal);
+	atomic_dec(&sbi->s_need_da_sync);
 
 	/* Finally we can mark the inode as dirty. */
 
