Skip to content

Commit

Permalink
xfs: reduce i_rwsem contention on buffered randrw workload
Browse files Browse the repository at this point in the history
Warm up page cache before buffered read to minimize time spent under
shared ilock.

Truncate and hole punch page cache invalidation is protected by MMAPLOCK,
but pNFS leases require IOLOCK protection of buffered reads, so skip
page cache warm up when pNFS block export is enabled.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
  • Loading branch information
amir73il committed Jun 21, 2022
1 parent a111daf commit 70e94f3
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions fs/xfs/xfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,29 @@ xfs_file_buffered_read(

trace_xfs_file_buffered_read(iocb, to);

ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
if (ret)
return ret;
if (iocb->ki_flags & IOCB_NOWAIT) {
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED))
return -EAGAIN;
} else {
#ifndef CONFIG_EXPORTFS_BLOCK_OPS
/*
* Warm up page cache to minimize time spent under
* shared ilock. truncate and hole punch page invalidation
* is protected by MMAPLOCK, but pNFS leases require IOLOCK
* protection of buffered reads.
*/
struct iov_iter iter;
loff_t pos = iocb->ki_pos;

iov_iter_discard(&iter, READ, iov_iter_count(to));
ret = generic_file_read_iter(iocb, &iter);
if (ret <= 0)
return ret;

iocb->ki_pos = pos;
#endif
xfs_ilock(ip, XFS_IOLOCK_SHARED);
}
ret = generic_file_read_iter(iocb, to);
xfs_iunlock(ip, XFS_IOLOCK_SHARED);

Expand Down

0 comments on commit 70e94f3

Please sign in to comment.