xfs: fix AIM7 regression
PATCH 1/1 xfs: fix AIM7 regression
Apparently our current rwsem code doesn't like doing the trylock, then lock for real scheme. So change our read/write methods to just do the trylock for the RWF_NOWAIT case. This fixes a ~25% regression in AIM7.
--- fs/xfs/xfs_file.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
fs/xfs/xfs_file.c +13 -8
@@ -237,11 +237,13 @@ xfs_file_dax_read(if (!count)return 0 ;/* skip atime */ -if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED )) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED ))return -EAGAIN ; + }else {xfs_ilock (ip,XFS_IOLOCK_SHARED ); } + ret =dax_iomap_rw (iocb, to, &xfs_iomap_ops);xfs_iunlock (ip,XFS_IOLOCK_SHARED );
@@ -259,9 +261,10 @@ xfs_file_buffered_aio_read(trace_xfs_file_buffered_read (ip,iov_iter_count (to), iocb->ki_pos); -if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED )) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED ))return -EAGAIN ; + }else {xfs_ilock (ip,XFS_IOLOCK_SHARED ); } ret =generic_file_read_iter (iocb, to);
@@ -552,9 +555,10 @@ xfs_file_dio_aio_write( iolock =XFS_IOLOCK_SHARED ; } -if (!xfs_ilock_nowait (ip, iolock)) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip, iolock))return -EAGAIN ; + }else {xfs_ilock (ip, iolock); }
@@ -606,9 +610,10 @@ xfs_file_dax_write(size_t count;loff_t pos; -if (!xfs_ilock_nowait (ip, iolock)) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip, iolock))return -EAGAIN ; + }else {xfs_ilock (ip, iolock); }
Signature · 1 line
2.14.2
Quoted 5 lines · Christoph Hellwig
Apparently our current rwsem code doesn't like doing the trylock, then lock for real scheme. So change our read/write methods to just do the trylock for the
RWF_NOWAITcase. This fixes a ~25% regression in AIM7.
The code looks fine, but this seems really strange. If the trylock fails, then wouldn't the blocking lock have slept anyways if done initially? Is there any more background info available on this, or perhaps a theory on why there is such a significant regression..?
Brian
Quoted 73 lines
Fixes 91f9943e ("fs: support RWF_NOWAIT for buffered reads")Reported-by kernel test robot <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_file.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)fs/xfs/xfs_file.c +13
-8@@ -237,11 +237,13 @@ xfs_file_dax_read(if (!count)return 0 ;/* skip atime */ -if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED )) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED ))return -EAGAIN ; + }else {xfs_ilock (ip,XFS_IOLOCK_SHARED ); } + ret =dax_iomap_rw (iocb, to, &xfs_iomap_ops);xfs_iunlock (ip,XFS_IOLOCK_SHARED );@@ -259,9 +261,10 @@ xfs_file_buffered_aio_read(trace_xfs_file_buffered_read (ip,iov_iter_count (to), iocb->ki_pos); -if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED )) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip,XFS_IOLOCK_SHARED ))return -EAGAIN ; + }else {xfs_ilock (ip,XFS_IOLOCK_SHARED ); } ret =generic_file_read_iter (iocb, to);@@ -552,9 +555,10 @@ xfs_file_dio_aio_write( iolock =XFS_IOLOCK_SHARED ; } -if (!xfs_ilock_nowait (ip, iolock)) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip, iolock))return -EAGAIN ; + }else {xfs_ilock (ip, iolock); }@@ -606,9 +610,10 @@ xfs_file_dax_write(size_t count;loff_t pos; -if (!xfs_ilock_nowait (ip, iolock)) { -if (iocb->ki_flags &IOCB_NOWAIT ) +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!xfs_ilock_nowait (ip, iolock))return -EAGAIN ; + }else {xfs_ilock (ip, iolock); }Signature · 6 lines
2.14.2 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Brian Foster
Quoted 5 lines · Christoph Hellwig
Apparently our current rwsem code doesn't like doing the trylock, then lock for real scheme. So change our read/write methods to just do the trylock for the
RWF_NOWAITcase. This fixes a ~25% regression in AIM7.The code looks fine, but this seems really strange. If the trylock fails, then wouldn't the blocking lock have slept anyways if done initially? Is there any more background info available on this, or perhaps a theory on why there is such a significant regression..?
No, unfortunately I don't have a theory, but I agree it is odd behavior in the rwsem code.
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Brian Foster
Quoted 5 lines · Christoph Hellwig
Apparently our current rwsem code doesn't like doing the trylock, then lock for real scheme. So change our read/write methods to just do the trylock for the
RWF_NOWAITcase. This fixes a ~25% regression in AIM7.
Quoted 7 lines
Quoted 4 lines
The code looks fine, but this seems really strange. If the trylock fails, then wouldn't the blocking lock have slept anyways if done initially? Is there any more background info available on this, or perhaps a theory on why there is such a significant regression..?
No, unfortunately I don't have a theory, but I agree it is odd behavior in the rwsem code.
<shrug> I want to know a little more about why there's a performance hit in the down_read_trylock -> down_read case. Are we getting penalized for that? Is it some weird interaction with lockdep?
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Darrick J. Wong
Quoted 7 lines
Quoted 4 lines
The code looks fine, but this seems really strange. If the trylock fails, then wouldn't the blocking lock have slept anyways if done initially? Is there any more background info available on this, or perhaps a theory on why there is such a significant regression..?
No, unfortunately I don't have a theory, but I agree it is odd behavior in the rwsem code.
<shrug> I want to know a little more about why there's a performance hit in the
down_read_trylock->down_readcase. Are we getting penalized for that? Is it some weird interaction with lockdep?
I don't think the test bot did run with lockdep. But feel free to take a look at the mail thread titled
[lkp-robot] [fs] 91f9943e1c: aim7.jobs-per-min -26.6% regression
on lkml. Note that synthetic benchmarks on XFS always saw weird effects from rwsem details. I remember that a few years ago I had to back to the mainline patch to move the rwsem fastpath out of line because thay caused a major performance regressions on CIFS file serving benchmarks on a very low end ARM NAS box.
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Brian Foster
Quoted 5 lines · Christoph Hellwig
Apparently our current rwsem code doesn't like doing the trylock, then lock for real scheme. So change our read/write methods to just do the trylock for the
RWF_NOWAITcase. This fixes a ~25% regression in AIM7.The code looks fine, but this seems really strange. If the trylock fails, then wouldn't the blocking lock have slept anyways if done initially? Is there any more background info available on this, or perhaps a theory on why there is such a significant regression..?
Quoted 6 lines
Quoted 2 lines
No, unfortunately I don't have a theory, but I agree it is odd behavior in the rwsem code.
<shrug> I want to know a little more about why there's a performance hit in the
down_read_trylock->down_readcase. Are we getting penalized for that? Is it some weird interaction with lockdep?
At least on x86, __down_read_trylock() is implemented very much differently from __down_read(). In particular if there's heavy contention on the semaphore from readers, __down_read_trylock() implementation seems to be prone to going through cmpxchg loop several times which could explain observed performance data. But I'm just guessing... Adding some x86 people to CC just in case they have more to say.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR