diff options
author | Christoph Hellwig <hch@lst.de> | 2018-07-17 19:51:52 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2018-07-31 16:18:09 -0400 |
commit | e666aa37f4330cb93a5004a89b7a938312e74e36 (patch) | |
tree | 321bb7db899b5c9f76b6164f8aeaa0ae4f0dad55 | |
parent | 745b3f76d1c889d738a1c4537a3c491bc1ecac4d (diff) |
xfs: avoid COW fork extent lookups in writeback if the fork didn't change
Used the per-fork sequence counter to avoid lookups in the writeback code
unless the COW fork actually changed.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/xfs/xfs_aops.c | 38 | ||||
-rw-r--r-- | fs/xfs/xfs_iomap.c | 5 | ||||
-rw-r--r-- | fs/xfs/xfs_iomap.h | 2 |
3 files changed, 38 insertions, 7 deletions
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 814100d27343..235b4ddcd324 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c | |||
@@ -29,6 +29,7 @@ | |||
29 | struct xfs_writepage_ctx { | 29 | struct xfs_writepage_ctx { |
30 | struct xfs_bmbt_irec imap; | 30 | struct xfs_bmbt_irec imap; |
31 | unsigned int io_type; | 31 | unsigned int io_type; |
32 | unsigned int cow_seq; | ||
32 | struct xfs_ioend *ioend; | 33 | struct xfs_ioend *ioend; |
33 | }; | 34 | }; |
34 | 35 | ||
@@ -310,6 +311,7 @@ xfs_map_blocks( | |||
310 | struct xfs_mount *mp = ip->i_mount; | 311 | struct xfs_mount *mp = ip->i_mount; |
311 | ssize_t count = i_blocksize(inode); | 312 | ssize_t count = i_blocksize(inode); |
312 | xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset), end_fsb; | 313 | xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset), end_fsb; |
314 | xfs_fileoff_t cow_fsb = NULLFILEOFF; | ||
313 | struct xfs_bmbt_irec imap; | 315 | struct xfs_bmbt_irec imap; |
314 | int whichfork = XFS_DATA_FORK; | 316 | int whichfork = XFS_DATA_FORK; |
315 | struct xfs_iext_cursor icur; | 317 | struct xfs_iext_cursor icur; |
@@ -333,12 +335,23 @@ xfs_map_blocks( | |||
333 | * COW fork blocks can overlap data fork blocks even if the blocks | 335 | * COW fork blocks can overlap data fork blocks even if the blocks |
334 | * aren't shared. COW I/O always takes precedent, so we must always | 336 | * aren't shared. COW I/O always takes precedent, so we must always |
335 | * check for overlap on reflink inodes unless the mapping is already a | 337 | * check for overlap on reflink inodes unless the mapping is already a |
336 | * COW one. | 338 | * COW one, or the COW fork hasn't changed from the last time we looked |
339 | * at it. | ||
340 | * | ||
341 | * It's safe to check the COW fork if_seq here without the ILOCK because | ||
342 | * we've indirectly protected against concurrent updates: writeback has | ||
343 | * the page locked, which prevents concurrent invalidations by reflink | ||
344 | * and directio and prevents concurrent buffered writes to the same | ||
345 | * page. Changes to if_seq always happen under i_lock, which protects | ||
346 | * against concurrent updates and provides a memory barrier on the way | ||
347 | * out that ensures that we always see the current value. | ||
337 | */ | 348 | */ |
338 | imap_valid = offset_fsb >= wpc->imap.br_startoff && | 349 | imap_valid = offset_fsb >= wpc->imap.br_startoff && |
339 | offset_fsb < wpc->imap.br_startoff + wpc->imap.br_blockcount; | 350 | offset_fsb < wpc->imap.br_startoff + wpc->imap.br_blockcount; |
340 | if (imap_valid && | 351 | if (imap_valid && |
341 | (!xfs_inode_has_cow_data(ip) || wpc->io_type == XFS_IO_COW)) | 352 | (!xfs_inode_has_cow_data(ip) || |
353 | wpc->io_type == XFS_IO_COW || | ||
354 | wpc->cow_seq == ip->i_cowfp->if_seq)) | ||
342 | return 0; | 355 | return 0; |
343 | 356 | ||
344 | if (XFS_FORCED_SHUTDOWN(mp)) | 357 | if (XFS_FORCED_SHUTDOWN(mp)) |
@@ -364,8 +377,10 @@ xfs_map_blocks( | |||
364 | * it directly instead of looking up anything in the data fork. | 377 | * it directly instead of looking up anything in the data fork. |
365 | */ | 378 | */ |
366 | if (xfs_inode_has_cow_data(ip) && | 379 | if (xfs_inode_has_cow_data(ip) && |
367 | xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &imap) && | 380 | xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &imap)) |
368 | imap.br_startoff <= offset_fsb) { | 381 | cow_fsb = imap.br_startoff; |
382 | if (cow_fsb != NULLFILEOFF && cow_fsb <= offset_fsb) { | ||
383 | wpc->cow_seq = ip->i_cowfp->if_seq; | ||
369 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | 384 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
370 | /* | 385 | /* |
371 | * Truncate can race with writeback since writeback doesn't | 386 | * Truncate can race with writeback since writeback doesn't |
@@ -411,6 +426,16 @@ xfs_map_blocks( | |||
411 | imap.br_startblock = HOLESTARTBLOCK; | 426 | imap.br_startblock = HOLESTARTBLOCK; |
412 | wpc->io_type = XFS_IO_HOLE; | 427 | wpc->io_type = XFS_IO_HOLE; |
413 | } else { | 428 | } else { |
429 | /* | ||
430 | * Truncate to the next COW extent if there is one. This is the | ||
431 | * only opportunity to do this because we can skip COW fork | ||
432 | * lookups for the subsequent blocks in the mapping; however, | ||
433 | * the requirement to treat the COW range separately remains. | ||
434 | */ | ||
435 | if (cow_fsb != NULLFILEOFF && | ||
436 | cow_fsb < imap.br_startoff + imap.br_blockcount) | ||
437 | imap.br_blockcount = cow_fsb - imap.br_startoff; | ||
438 | |||
414 | if (isnullstartblock(imap.br_startblock)) { | 439 | if (isnullstartblock(imap.br_startblock)) { |
415 | /* got a delalloc extent */ | 440 | /* got a delalloc extent */ |
416 | wpc->io_type = XFS_IO_DELALLOC; | 441 | wpc->io_type = XFS_IO_DELALLOC; |
@@ -427,9 +452,12 @@ xfs_map_blocks( | |||
427 | trace_xfs_map_blocks_found(ip, offset, count, wpc->io_type, &imap); | 452 | trace_xfs_map_blocks_found(ip, offset, count, wpc->io_type, &imap); |
428 | return 0; | 453 | return 0; |
429 | allocate_blocks: | 454 | allocate_blocks: |
430 | error = xfs_iomap_write_allocate(ip, whichfork, offset, &imap); | 455 | error = xfs_iomap_write_allocate(ip, whichfork, offset, &imap, |
456 | &wpc->cow_seq); | ||
431 | if (error) | 457 | if (error) |
432 | return error; | 458 | return error; |
459 | ASSERT(whichfork == XFS_COW_FORK || cow_fsb == NULLFILEOFF || | ||
460 | imap.br_startoff + imap.br_blockcount <= cow_fsb); | ||
433 | wpc->imap = imap; | 461 | wpc->imap = imap; |
434 | trace_xfs_map_blocks_alloc(ip, offset, count, wpc->io_type, &imap); | 462 | trace_xfs_map_blocks_alloc(ip, offset, count, wpc->io_type, &imap); |
435 | return 0; | 463 | return 0; |
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 8e8ca9f03f0e..3282575e2df4 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c | |||
@@ -651,7 +651,8 @@ xfs_iomap_write_allocate( | |||
651 | xfs_inode_t *ip, | 651 | xfs_inode_t *ip, |
652 | int whichfork, | 652 | int whichfork, |
653 | xfs_off_t offset, | 653 | xfs_off_t offset, |
654 | xfs_bmbt_irec_t *imap) | 654 | xfs_bmbt_irec_t *imap, |
655 | unsigned int *cow_seq) | ||
655 | { | 656 | { |
656 | xfs_mount_t *mp = ip->i_mount; | 657 | xfs_mount_t *mp = ip->i_mount; |
657 | xfs_fileoff_t offset_fsb, last_block; | 658 | xfs_fileoff_t offset_fsb, last_block; |
@@ -766,6 +767,8 @@ xfs_iomap_write_allocate( | |||
766 | if (error) | 767 | if (error) |
767 | goto error0; | 768 | goto error0; |
768 | 769 | ||
770 | if (whichfork == XFS_COW_FORK) | ||
771 | *cow_seq = XFS_IFORK_PTR(ip, whichfork)->if_seq; | ||
769 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 772 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
770 | } | 773 | } |
771 | 774 | ||
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h index 83474c9cede9..c6170548831b 100644 --- a/fs/xfs/xfs_iomap.h +++ b/fs/xfs/xfs_iomap.h | |||
@@ -14,7 +14,7 @@ struct xfs_bmbt_irec; | |||
14 | int xfs_iomap_write_direct(struct xfs_inode *, xfs_off_t, size_t, | 14 | int xfs_iomap_write_direct(struct xfs_inode *, xfs_off_t, size_t, |
15 | struct xfs_bmbt_irec *, int); | 15 | struct xfs_bmbt_irec *, int); |
16 | int xfs_iomap_write_allocate(struct xfs_inode *, int, xfs_off_t, | 16 | int xfs_iomap_write_allocate(struct xfs_inode *, int, xfs_off_t, |
17 | struct xfs_bmbt_irec *); | 17 | struct xfs_bmbt_irec *, unsigned int *); |
18 | int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool); | 18 | int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool); |
19 | 19 | ||
20 | void xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *, | 20 | void xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *, |