From: Matthew Wilcox <willy@infradead.org>
To: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Dave Chinner <david@fromorbit.com>,
Brian Foster <bfoster@redhat.com>,
Christoph Hellwig <hch@infradead.org>,
Andreas Gruenbacher <agruenba@redhat.com>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
Disha Goel <disgoel@linux.ibm.com>,
Aravinda Herle <araherle@in.ibm.com>
Subject: Re: [PATCHv6 5/5] iomap: Add per-block dirty state tracking to improve performance
Date: Mon, 5 Jun 2023 05:03:35 +0100 [thread overview]
Message-ID: <ZH1elxw5ddP+bjEa@casper.infradead.org> (raw)
In-Reply-To: <c38a4081e762e38b8fc4c0a54d848741d28d7455.1685900733.git.ritesh.list@gmail.com>
On Mon, Jun 05, 2023 at 07:01:52AM +0530, Ritesh Harjani (IBM) wrote:
> +static void iop_set_range_dirty(struct inode *inode, struct folio *folio,
> + size_t off, size_t len)
> +{
> + struct iomap_page *iop = to_iomap_page(folio);
> + unsigned int blks_per_folio = i_blocks_per_folio(inode, folio);
> + unsigned int first_blk = off >> inode->i_blkbits;
> + unsigned int last_blk = (off + len - 1) >> inode->i_blkbits;
> + unsigned int nr_blks = last_blk - first_blk + 1;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&iop->state_lock, flags);
> + bitmap_set(iop->state, first_blk + blks_per_folio, nr_blks);
> + spin_unlock_irqrestore(&iop->state_lock, flags);
> +}
> +
> +static void iomap_iop_set_range_dirty(struct inode *inode, struct folio *folio,
> + size_t off, size_t len)
> +{
> + struct iomap_page *iop = to_iomap_page(folio);
> +
> + if (iop)
> + iop_set_range_dirty(inode, folio, off, len);
> +}
Why are these separate functions? It'd be much better written as:
static void iomap_iop_set_range_dirty(struct inode *inode, struct folio *folio,
size_t off, size_t len)
{
struct iomap_page *iop = to_iomap_page(folio);
unsigned int start, first, last;
unsigned long flags;
if (!iop)
return;
start = i_blocks_per_folio(inode, folio);
first = off >> inode->i_blkbits;
last = (off + len - 1) >> inode->i_blkbits;
spin_lock_irqsave(&iop->state_lock, flags);
bitmap_set(iop->state, start + first, last - first + 1);
spin_unlock_irqrestore(&iop->state_lock, flags);
}
> +static void iop_clear_range_dirty(struct inode *inode, struct folio *folio,
> + size_t off, size_t len)
> +{
> + struct iomap_page *iop = to_iomap_page(folio);
> + unsigned int blks_per_folio = i_blocks_per_folio(inode, folio);
> + unsigned int first_blk = off >> inode->i_blkbits;
> + unsigned int last_blk = (off + len - 1) >> inode->i_blkbits;
> + unsigned int nr_blks = last_blk - first_blk + 1;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&iop->state_lock, flags);
> + bitmap_clear(iop->state, first_blk + blks_per_folio, nr_blks);
> + spin_unlock_irqrestore(&iop->state_lock, flags);
> +}
> +
> +static void iomap_iop_clear_range_dirty(struct inode *inode,
> + struct folio *folio, size_t off, size_t len)
> +{
> + struct iomap_page *iop = to_iomap_page(folio);
> +
> + if (iop)
> + iop_clear_range_dirty(inode, folio, off, len);
> +}
Similarly
> +bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
> +{
> + struct iomap_page __maybe_unused *iop;
> + struct inode *inode = mapping->host;
> + size_t len = folio_size(folio);
> +
> + iop = iomap_iop_alloc(inode, folio, 0);
Why do you keep doing this? Just throw away the return value from
iomap_iop_alloc(). Don't clutter the source with the unnecessary
variable declaration and annotation that it's not used!
> +static int iomap_write_delalloc_punch(struct inode *inode, struct folio *folio,
> + loff_t *punch_start_byte, loff_t start_byte, loff_t end_byte,
> + int (*punch)(struct inode *inode, loff_t offset, loff_t length))
> +{
> + struct iomap_page *iop;
> + unsigned int first_blk, last_blk, i;
> + loff_t last_byte;
> + u8 blkbits = inode->i_blkbits;
> + int ret = 0;
> +
> + if (start_byte > *punch_start_byte) {
> + ret = punch(inode, *punch_start_byte,
> + start_byte - *punch_start_byte);
> + if (ret)
> + goto out_err;
> + }
> + /*
> + * When we have per-block dirty tracking, there can be
> + * blocks within a folio which are marked uptodate
> + * but not dirty. In that case it is necessary to punch
> + * out such blocks to avoid leaking any delalloc blocks.
> + */
> + iop = to_iomap_page(folio);
> + if (!iop)
> + goto skip_iop_punch;
> +
> + last_byte = min_t(loff_t, end_byte - 1,
> + (folio_next_index(folio) << PAGE_SHIFT) - 1);
> + first_blk = offset_in_folio(folio, start_byte) >> blkbits;
> + last_blk = offset_in_folio(folio, last_byte) >> blkbits;
> + for (i = first_blk; i <= last_blk; i++) {
> + if (!iop_test_block_dirty(folio, i)) {
> + ret = punch(inode, i << blkbits, 1 << blkbits);
> + if (ret)
> + goto out_err;
> + }
> + }
> +
> +skip_iop_punch:
> + /*
> + * Make sure the next punch start is correctly bound to
> + * the end of this data range, not the end of the folio.
> + */
> + *punch_start_byte = min_t(loff_t, end_byte,
> + folio_next_index(folio) << PAGE_SHIFT);
> +
> + return ret;
> +
> +out_err:
> + folio_unlock(folio);
> + folio_put(folio);
> + return ret;
> +
> +}
> +
> /*
> * Scan the data range passed to us for dirty page cache folios. If we find a
> * dirty folio, punch out the preceeding range and update the offset from which
> @@ -940,26 +1074,9 @@ static int iomap_write_delalloc_scan(struct inode *inode,
> }
>
> /* if dirty, punch up to offset */
> - if (folio_test_dirty(folio)) {
> - if (start_byte > *punch_start_byte) {
> - int error;
> -
> - error = punch(inode, *punch_start_byte,
> - start_byte - *punch_start_byte);
> - if (error) {
> - folio_unlock(folio);
> - folio_put(folio);
> - return error;
> - }
> - }
> -
> - /*
> - * Make sure the next punch start is correctly bound to
> - * the end of this data range, not the end of the folio.
> - */
> - *punch_start_byte = min_t(loff_t, end_byte,
> - folio_next_index(folio) << PAGE_SHIFT);
> - }
> + if (folio_test_dirty(folio))
> + iomap_write_delalloc_punch(inode, folio, punch_start_byte,
> + start_byte, end_byte, punch);
>
> /* move offset to start of next folio in range */
> start_byte = folio_next_index(folio) << PAGE_SHIFT;
I'm having trouble following this refactoring + modification. Perhaps
I'm just tired.
next prev parent reply other threads:[~2023-06-05 4:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 1:31 [PATCHv6 0/5] iomap: Add support for per-block dirty state to improve write performance Ritesh Harjani (IBM)
2023-06-05 1:31 ` [PATCHv6 1/5] iomap: Rename iomap_page_create/release() to iomap_iop_alloc/free() Ritesh Harjani (IBM)
2023-06-05 1:31 ` [PATCHv6 2/5] iomap: Move folio_detach_private() in iomap_iop_free() to the end Ritesh Harjani (IBM)
2023-06-05 1:31 ` [PATCHv6 3/5] iomap: Refactor some iop related accessor functions Ritesh Harjani (IBM)
2023-06-05 3:33 ` Matthew Wilcox
2023-06-05 5:16 ` Ritesh Harjani
2023-06-05 1:31 ` [PATCHv6 4/5] iomap: Allocate iop in ->write_begin() early Ritesh Harjani (IBM)
2023-06-05 1:31 ` [PATCHv6 5/5] iomap: Add per-block dirty state tracking to improve performance Ritesh Harjani (IBM)
2023-06-05 4:03 ` Matthew Wilcox [this message]
2023-06-05 5:20 ` Ritesh Harjani
2023-06-06 12:17 ` [PATCHv6 0/5] iomap: Add support for per-block dirty state to improve write performance Andreas Grünbacher
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=ZH1elxw5ddP+bjEa@casper.infradead.org \
--to=willy@infradead.org \
--cc=agruenba@redhat.com \
--cc=araherle@in.ibm.com \
--cc=bfoster@redhat.com \
--cc=david@fromorbit.com \
--cc=disgoel@linux.ibm.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).