mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Holger Kiehl <Holger.Kiehl@dwd.de>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: Mingming <cmm@us.ibm.com>, Theodore Tso <tytso@mit.edu>,
	Eric Sandeen <sandeen@redhat.com>, Jan Kara <jack@suse.cz>,
	Solofo.Ramangalahy@bull.net, Nick Dokos <nicholas.dokos@hp.com>,
	linux-ext4@vger.kernel.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Performance of ext4
Date: Tue, 24 Jun 2008 21:12:09 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0806242103370.14795@diagnostix.dwd.de> (raw)
In-Reply-To: <20080624033349.GD10469@skywalker>

On Tue, 24 Jun 2008, Aneesh Kumar K.V wrote:

> On Tue, Jun 24, 2008 at 08:37:21AM +0530, Aneesh Kumar K.V wrote:
>> On Mon, Jun 23, 2008 at 05:31:32PM -0700, Mingming wrote:
>>>
>>> On Mon, 2008-06-23 at 23:15 +0530, Aneesh Kumar K.V wrote:
>>>
>>>> I found one place where we fail to update i_disksize. Can you try this
>>>> patch ?
>>>>
>>>> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
>>>> index 33f940b..9fa737f 100644
>>>> --- a/fs/ext4/inode.c
>>>> +++ b/fs/ext4/inode.c
>>>> @@ -1620,7 +1620,10 @@ static int ext4_da_writepage(struct page *page,
>>>>  	loff_t size;
>>>>  	unsigned long len;
>>>>  	handle_t *handle = NULL;
>>>> +	ext4_lblk_t block;
>>>> +	loff_t disksize;
>>>>  	struct buffer_head *page_bufs;
>>>> +	struct buffer_head *bh, *head;
>>>>  	struct inode *inode = page->mapping->host;
>>>>
>>>>  	handle = ext4_journal_current_handle();
>>>> @@ -1662,6 +1665,38 @@ static int ext4_da_writepage(struct page *page,
>>>>  	else
>>>>  		ret = block_write_full_page(page, ext4_da_get_block_write, wbc);
>>>>
>>>> +	 if (ret)
>>>> +		 return ret;
>>>> +	/*
>>>> +	 * When called via shrink_page_list and if we don't have any unmapped
>>>> +	 * buffer_head we still could have written some new content in an
>>>> +	 * already mapped buffer. That means we need to extent i_disksize here
>>>> +	 */
>>>
>>> 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)
>>
>> In this case you will have to start a transaction in write_begin . With
>> the below code transaction is started inside page_lock. Also I don't
>> think we need needed_blocks credit just 1 should be enough because we
>> are not doing any block allocation here. We just need to update the
>> inode block.
>>
>>
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 33f940b..bc925c5 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1770,6 +1770,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
> 	struct page *page;
> 	pgoff_t index;
> 	unsigned from, to;
> +	handle_t *handle;
> 	struct inode *inode = mapping->host;
>
> 	index = pos >> PAGE_CACHE_SHIFT;
> @@ -1777,6 +1778,17 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
> 	to = from + len;
>
> retry:
> +	/*
> +	 * If we are writing towards the end of an already mapped
> +	 * buffer_head, we don't do any block allocation. But we
> +	 * need to update i_disksize.
> +	 */
> +	handle = ext4_journal_start(inode, 1);
> +	if (IS_ERR(handle)) {
> +		ret = PTR_ERR(handle);
> +		goto out;
> +	}
> +
> 	page = __grab_cache_page(mapping, index);
> 	if (!page)
> 		return -ENOMEM;
> @@ -1786,15 +1798,63 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
> 							ext4_da_get_block_prep);
> 	if (ret < 0) {
> 		unlock_page(page);
> +		ext4_journal_stop(handle);
> 		page_cache_release(page);
> 	}
>
> 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
> 		goto retry;
>
> +out:
> 	return ret;
> }
>
> +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)
> +{
> +	loff_t new_i_size;
> +	unsigned from, to;
> +	int ret = 0, ret2;
> +	struct inode *inode = mapping->host;
> +	handle_t *handle = ext4_journal_current_handle();
> +
> +	from = pos & (PAGE_CACHE_SIZE - 1);
> +	to = from + len;
> +
> +	/*
> +	 * generic_write_end() will run mark_inode_dirty() if i_size
> +	 * changes.  So let's piggyback the i_disksize mark_inode_dirty
> +	 * into that.
> +	 */
> +
> +	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
> +			 */
> +			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;
> +	ret2 = ext4_journal_stop(handle);
> +	if (!ret)
> +		ret = ret2;
> +
> +	return ret ? ret : copied;
> +}
> +
> static void ext4_da_invalidatepage(struct page *page, unsigned long offset)
> {
> 	/*
> @@ -2250,7 +2310,7 @@ static int ext4_journalled_set_page_dirty(struct page *page)
> 	.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,
>
Yes, with this patch applied on top of latest patch queue I no longer
get truncated files, after running a short test. Tomorrow I will do some
more thorough testing and use the patch you have send to me in a separate
mail. The above patch did not apply but it was easy to apply by hand.

Thanks a lot for the patch!

Holger


  reply	other threads:[~2008-06-24 21:12 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-11  8:02 Holger Kiehl
2008-06-11 10:59 ` Aneesh Kumar K.V
2008-06-11 19:58   ` Holger Kiehl
2008-06-11 20:17     ` Nick Dokos
2008-06-12  9:02       ` Holger Kiehl
2008-06-12 10:58         ` Solofo.Ramangalahy
2008-06-12 12:00           ` Holger Kiehl
2008-06-12 13:19             ` Theodore Tso
2008-06-12 14:07               ` Holger Kiehl
2008-06-12 18:06                 ` Aneesh Kumar K.V
2008-06-12 19:50                   ` Holger Kiehl
2008-06-13  8:05                     ` Holger Kiehl
2008-06-16 17:54                       ` Jan Kara
2008-06-16 18:13                         ` Aneesh Kumar K.V
2008-06-17 11:42                           ` Holger Kiehl
2008-06-18  5:58                             ` Holger Kiehl
2008-06-19  6:58                               ` Andreas Dilger
2008-06-19 11:09                               ` Theodore Tso
2008-06-19 15:04                                 ` Holger Kiehl
2008-07-07 13:13                                 ` Holger Kiehl
2008-07-10  8:11                                   ` Holger Kiehl
2008-06-19 15:56                             ` Theodore Tso
2008-06-19 16:41                               ` Eric Sandeen
2008-06-19 17:42                                 ` Theodore Tso
2008-06-19 19:51                                   ` Mingming
2008-06-20  8:32                                   ` Holger Kiehl
2008-06-20  8:59                                     ` Theodore Tso
2008-06-20  9:21                                       ` Holger Kiehl
2008-06-23 17:45                                         ` Aneesh Kumar K.V
2008-06-24  0:31                                           ` Mingming
2008-06-24  3:07                                             ` Aneesh Kumar K.V
2008-06-24  3:28                                               ` Aneesh Kumar K.V
2008-06-24  3:33                                               ` Aneesh Kumar K.V
2008-06-24 21:12                                                 ` Holger Kiehl [this message]
2008-06-24 22:58                                                   ` Mingming
2008-06-25  9:09                                                     ` Holger Kiehl
2008-06-26  0:46                                                       ` Mingming
2008-06-27  9:14                                                         ` Aneesh Kumar K.V
2008-06-27  9:49                                                           ` Aneesh Kumar K.V
2008-06-27 10:00                                                             ` Jan Kara
2008-06-27 17:35                                                               ` Aneesh Kumar K.V
2008-06-24 17:58                                               ` Mingming
2008-06-24 12:57                                           ` Holger Kiehl
2008-06-23 20:55                                         ` Andreas Dilger
2008-06-20  8:09                               ` Holger Kiehl
2008-06-21 15:02                                 ` Holger Kiehl
2008-06-11 13:54 ` Theodore Tso
2008-06-11 20:21   ` Holger Kiehl
2008-06-12  1:35     ` Theodore Tso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0806242103370.14795@diagnostix.dwd.de \
    --to=holger.kiehl@dwd.de \
    --cc=Solofo.Ramangalahy@bull.net \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=cmm@us.ibm.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicholas.dokos@hp.com \
    --cc=sandeen@redhat.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®