Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "yukuai (C)" <yukuai3@huawei.com>
Cc: hch@infradead.org, darrick.wong@oracle.com, david@fromorbit.com,
	linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, yi.zhang@huawei.com
Subject: Re: [RFC PATCH V4] iomap: add support to track dirty state of sub pages
Date: Fri, 11 Sep 2020 13:05:29 +0100	[thread overview]
Message-ID: <20200911120529.GZ6583@casper.infradead.org> (raw)
In-Reply-To: <7fb4bb5a-adc7-5914-3aae-179dd8f3adb1@huawei.com>

On Fri, Sep 11, 2020 at 04:27:08PM +0800, yukuai (C) wrote:
> Since your THP iomap patches were reviewed, I made some modifications
> based on these patches.

Thanks!  This looks good to me!

> +static void
> +iomap_set_range_dirty(struct page *page, unsigned int off,
> +		unsigned int len)
> +{
> +	struct inode *inode = page->mapping->host;
> +	unsigned int blocks_per_page = i_blocks_per_page(inode, page);

I might call this nr_blocks.

> +	unsigned int first = (off >> inode->i_blkbits) + blocks_per_page;
> +	unsigned int last = ((off + len - 1) >> inode->i_blkbits) +
> blocks_per_page;
> +	unsigned long flags;
> +	struct iomap_page *iop;
> +
> +	if (PageError(page))
> +		return;

I think this is wrong.  If PageError is set then we've seen an I/O error
on this page (today either a read or a write, although I intend to make
that for writes only soon).  But I don't see a reason for declining to
make a page dirty if we've seen an eror -- indeed, that seems likely to
lead to further data loss as we then won't even try to write parts of
the page back to storage.

> +	if (len)
> +		iomap_set_page_dirty(page);
> +
> +	if (!page_has_private(page))
> +		return;
> +
> +	iop = to_iomap_page(page);

We usually do the last three lines as:

	iop = to_iomap_page(page);
	if (!iop)
		return;

(actually, we usually call to_iomap_page() at the start of the function
and then check it here)

> +static void
> +iomap_clear_range_dirty(struct page *page, unsigned int off,
> +		unsigned int len)
> +{
> +	struct inode *inode = page->mapping->host;
> +	unsigned int blocks_per_page = i_blocks_per_page(inode, page);
> +	unsigned int first = (off >> inode->i_blkbits) + blocks_per_page;
> +	unsigned int last = ((off + len - 1) >> inode->i_blkbits) +
> blocks_per_page;
> +	unsigned long flags;
> +	struct iomap_page *iop;
> +
> +	if (PageError(page))
> +		return;

It does make sense to avoid clearing the dirty state of the page here;
if the write failed, then the page is still dirty, and it'd be nice to
retry writes until they succeed.  So if you take out the PageError in
set_range_dirty, don't take it out here!

> +	if (!page_has_private(page))
> +		return;
> +
> +	iop = to_iomap_page(page);
> +	spin_lock_irqsave(&iop->state_lock, flags);
> +	bitmap_clear(iop->state, first, last - first + 1);
> +	spin_unlock_irqrestore(&iop->state_lock, flags);
> +}
> +
>  static void
>  iomap_iop_set_range_uptodate(struct page *page, unsigned off, unsigned len)
>  {
> @@ -148,11 +201,11 @@ iomap_iop_set_range_uptodate(struct page *page,
> unsigned off, unsigned len)
>  	unsigned last = (off + len - 1) >> inode->i_blkbits;
>  	unsigned long flags;
> 
> -	spin_lock_irqsave(&iop->uptodate_lock, flags);
> -	bitmap_set(iop->uptodate, first, last - first + 1);
> -	if (bitmap_full(iop->uptodate, i_blocks_per_page(inode, page)))
> +	spin_lock_irqsave(&iop->state_lock, flags);
> +	bitmap_set(iop->state, first, last - first + 1);
> +	if (bitmap_full(iop->state, i_blocks_per_page(inode, page)))
>  		SetPageUptodate(page);
> -	spin_unlock_irqrestore(&iop->uptodate_lock, flags);
> +	spin_unlock_irqrestore(&iop->state_lock, flags);
>  }
> 
>  static void
> @@ -445,7 +498,7 @@ iomap_is_partially_uptodate(struct page *page, unsigned
> long from,
> 
>  	if (iop) {
>  		for (i = first; i <= last; i++)
> -			if (!test_bit(i, iop->uptodate))
> +			if (!test_bit(i, iop->state))
>  				return 0;
>  		return 1;
>  	}
> @@ -683,7 +736,7 @@ static size_t __iomap_write_end(struct inode *inode,
> loff_t pos, size_t len,
>  	if (unlikely(copied < len && !PageUptodate(page)))
>  		return 0;
>  	iomap_set_range_uptodate(page, offset_in_page(pos), len);
> -	iomap_set_page_dirty(page);
> +	iomap_set_range_dirty(page, offset_in_page(pos), len);

I _think_ the call to set_range_uptodate here is now unnecessary.  The
blocks should already have been set uptodate in write_begin.  But please
check!

> @@ -1007,7 +1059,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf,
> const struct iomap_ops *ops)
>  {
>  	struct page *page = vmf->page;
>  	struct inode *inode = file_inode(vmf->vma->vm_file);
> -	unsigned long length;
> +	unsigned int length, dirty_bits;

This is dirty_bytes, surely?


  parent reply	other threads:[~2020-09-11 12:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 12:33 Yu Kuai
2020-08-21 12:44 ` Matthew Wilcox
2020-08-21 12:46   ` [PATCH 1/3] iomap: Use kzalloc to allocate iomap_page Matthew Wilcox (Oracle)
2020-08-21 12:46     ` [PATCH 2/3] iomap: Use bitmap ops to set uptodate bits Matthew Wilcox (Oracle)
2020-08-22  5:59       ` Christoph Hellwig
2020-08-21 12:46     ` [PATCH 3/3] iomap: Support arbitrarily many blocks per page Matthew Wilcox (Oracle)
2020-08-21 12:48       ` Matthew Wilcox
2020-08-22  6:01       ` Christoph Hellwig
2020-08-22  5:57     ` [PATCH 1/3] iomap: Use kzalloc to allocate iomap_page Christoph Hellwig
2020-09-11  8:27   ` [RFC PATCH V4] iomap: add support to track dirty state of sub pages yukuai (C)
2020-09-11  8:35     ` yukuai (C)
2020-09-11 12:05     ` Matthew Wilcox [this message]
2020-09-25  2:30       ` yukuai (C)

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=20200911120529.GZ6583@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    --subject='Re: [RFC PATCH V4] iomap: add support to track dirty state of sub pages' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).