Re: Performance of ext4

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mingming
Date: Monday, June 23, 2008 - 5:31 pm

On Mon, 2008-06-23 at 23:15 +0530, Aneesh Kumar K.V wrote:


In this case(when extend the file without need block allocation),
wouldn't make sense to update the i_disksize at write_end() time? So
that the window of i_size different from i_disksize could be much
smaller in this case.


Something like below? (untested)

Signed-off-by: Mingming Cao <cmm@us.ibm.com>
---
 fs/ext4/inode.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 60 insertions(+), 6 deletions(-)

Index: linux-2.6.26-rc6/fs/ext4/inode.c
===================================================================
--- linux-2.6.26-rc6.orig/fs/ext4/inode.c	2008-06-23 17:28:01.000000000 -0700
+++ linux-2.6.26-rc6/fs/ext4/inode.c	2008-06-23 17:28:10.000000000 -0700
@@ -1573,6 +1573,65 @@ static int ext4_da_write_begin(struct fi
 	return ret;
 }
 
+static int ext4_bh_unmapped_or_delay(handle_t *handle, struct buffer_head *bh)
+{
+	return !buffer_mapped(bh) || buffer_delay(bh);
+}
+
+static int ext4_da_write_end(struct file *file,
+				struct address_space *mapping,
+				loff_t pos, unsigned len, unsigned copied,
+				struct page *page, void *fsdata)
+{
+	handle_t *handle = NULL;
+	struct inode *inode = mapping->host;
+	int needed_blocks = ext4_writepage_trans_blocks(inode);
+	unsigned from, to;
+	int ret = 0, ret2;
+
+	from = pos & (PAGE_CACHE_SIZE - 1);
+	to = from + len;
+
+	if (ret == 0) {
+		/*
+		 * generic_write_end() will run mark_inode_dirty() if i_size
+		 * changes.  So let's piggyback the i_disksize mark_inode_dirty
+		 * into that.
+		 */
+		loff_t new_i_size;
+
+		new_i_size = pos + copied;
+		if (new_i_size > EXT4_I(inode)->i_disksize)
+			if (!walk_page_buffers(NULL, page_buffers(page),
+					       0, len, NULL, ext4_bh_unmapped_or_delay)){
+				/*
+				 * Updating i_disksize when extending file without
+				 * need block allocation
+				 */
+        			handle = ext4_journal_start(inode, needed_blocks);
+				if (IS_ERR(handle)) {
+			                ret = PTR_ERR(handle);
+			                return ret;
+				}
+				if (ext4_should_order_data(inode))
+					ret = ext4_jbd2_file_inode(handle, inode);
+
+				EXT4_I(inode)->i_disksize = new_i_size;
+			}
+		ret2 = generic_write_end(file, mapping, pos, len, copied,
+							page, fsdata);
+		copied = ret2;
+		if (ret2 < 0)
+			ret = ret2;
+	}
+	if (handle)
+		ret2 = ext4_journal_stop(handle);
+	if (!ret)
+		ret = ret2;
+
+	return ret ? ret : copied;
+}
+
 static void ext4_da_invalidatepage(struct page *page, unsigned long offset)
 {
 	struct buffer_head *head, *bh;
@@ -1682,11 +1741,6 @@ static int bput_one(handle_t *handle, st
 	return 0;
 }
 
-static int ext4_bh_unmapped_or_delay(handle_t *handle, struct buffer_head *bh)
-{
-	return !buffer_mapped(bh) || buffer_delay(bh);
-}
-
 /*
  * Note that we don't need to start a transaction unless we're journaling data
  * because we should have holes filled from ext4_page_mkwrite(). We even don't
@@ -2050,7 +2104,7 @@ static const struct address_space_operat
 	.writepages	= ext4_da_writepages,
 	.sync_page	= block_sync_page,
 	.write_begin	= ext4_da_write_begin,
-	.write_end	= generic_write_end,
+	.write_end	= ext4_da_write_end,
 	.bmap		= ext4_bmap,
 	.invalidatepage	= ext4_da_invalidatepage,
 	.releasepage	= ext4_releasepage,


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Performance of ext4, Holger Kiehl, (Wed Jun 11, 1:02 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Wed Jun 11, 3:59 am)
Re: Performance of ext4, Theodore Tso, (Wed Jun 11, 6:54 am)
Re: Performance of ext4, Holger Kiehl, (Wed Jun 11, 12:58 pm)
Re: Performance of ext4 , Nick Dokos, (Wed Jun 11, 1:17 pm)
Re: Performance of ext4, Holger Kiehl, (Wed Jun 11, 1:21 pm)
Re: Performance of ext4, Theodore Tso, (Wed Jun 11, 6:35 pm)
Re: Performance of ext4 , Holger Kiehl, (Thu Jun 12, 2:02 am)
Re: Performance of ext4 , Solofo.Ramangalahy, (Thu Jun 12, 3:58 am)
Re: Performance of ext4 , Holger Kiehl, (Thu Jun 12, 5:00 am)
Re: Performance of ext4, Theodore Tso, (Thu Jun 12, 6:19 am)
Re: Performance of ext4, Holger Kiehl, (Thu Jun 12, 7:07 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Thu Jun 12, 11:06 am)
Re: Performance of ext4, Holger Kiehl, (Thu Jun 12, 12:50 pm)
Re: Performance of ext4, Holger Kiehl, (Fri Jun 13, 1:05 am)
Re: Performance of ext4, Jan Kara, (Mon Jun 16, 10:54 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Mon Jun 16, 11:13 am)
Re: Performance of ext4, Holger Kiehl, (Tue Jun 17, 4:42 am)
Re: Performance of ext4, Holger Kiehl, (Tue Jun 17, 10:58 pm)
Re: Performance of ext4, Andreas Dilger, (Wed Jun 18, 11:58 pm)
Re: Performance of ext4, Theodore Tso, (Thu Jun 19, 4:09 am)
Re: Performance of ext4, Holger Kiehl, (Thu Jun 19, 8:04 am)
Re: Performance of ext4, Theodore Tso, (Thu Jun 19, 8:56 am)
Re: Performance of ext4, Eric Sandeen, (Thu Jun 19, 9:41 am)
Re: Performance of ext4, Theodore Tso, (Thu Jun 19, 10:42 am)
Re: Performance of ext4, Mingming, (Thu Jun 19, 12:51 pm)
Re: Performance of ext4, Holger Kiehl, (Fri Jun 20, 1:09 am)
Re: Performance of ext4, Holger Kiehl, (Fri Jun 20, 1:32 am)
Re: Performance of ext4, Theodore Tso, (Fri Jun 20, 1:59 am)
Re: Performance of ext4, Holger Kiehl, (Fri Jun 20, 2:21 am)
Re: Performance of ext4, Holger Kiehl, (Sat Jun 21, 8:02 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Mon Jun 23, 10:45 am)
Re: Performance of ext4, Andreas Dilger, (Mon Jun 23, 1:55 pm)
Re: Performance of ext4, Mingming, (Mon Jun 23, 5:31 pm)
Re: Performance of ext4, Aneesh Kumar K.V, (Mon Jun 23, 8:07 pm)
Re: Performance of ext4, Aneesh Kumar K.V, (Mon Jun 23, 8:28 pm)
Re: Performance of ext4, Aneesh Kumar K.V, (Mon Jun 23, 8:33 pm)
Re: Performance of ext4, Holger Kiehl, (Tue Jun 24, 5:57 am)
Re: Performance of ext4, Mingming, (Tue Jun 24, 10:58 am)
Re: Performance of ext4, Holger Kiehl, (Tue Jun 24, 2:12 pm)
Re: Performance of ext4, Mingming, (Tue Jun 24, 3:58 pm)
Re: Performance of ext4, Holger Kiehl, (Wed Jun 25, 2:09 am)
Re: Performance of ext4, Mingming, (Wed Jun 25, 5:46 pm)
Re: Performance of ext4, Aneesh Kumar K.V, (Fri Jun 27, 2:14 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Fri Jun 27, 2:49 am)
Re: Performance of ext4, Jan Kara, (Fri Jun 27, 3:00 am)
Re: Performance of ext4, Aneesh Kumar K.V, (Fri Jun 27, 10:35 am)
Re: Performance of ext4, Holger Kiehl, (Mon Jul 7, 6:13 am)
Re: Performance of ext4, Holger Kiehl, (Thu Jul 10, 1:11 am)