linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs: Correctly invert xfs_buftarg LRU isolation logic
@ 2018-02-28 15:49 Vratislav Bendel
  2018-02-28 19:08 ` Luis R. Rodriguez
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Vratislav Bendel @ 2018-02-28 15:49 UTC (permalink / raw)
  To: linux-xfs, Darrick J . Wong; +Cc: Brian Foster, linux-kernel

The function xfs_buftarg_isolate() used by xfs buffer schrinkers 
to determine whether a buffer should be isolated and disposed 
from LRU list, has inverted logic.

Excerpt from xfs_buftarg_isolate():
        /*
         * Decrement the b_lru_ref count unless the value is already
         * zero. If the value is already zero, we need to reclaim the
         * buffer, otherwise it gets another trip through the LRU.
         */
        if (!atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
                spin_unlock(&bp->b_lock);
                return LRU_ROTATE;
        }

However, as per documentation, atomic_add_unless() returns _zero_
if the atomic value was originally equal to the specified *unsless* value.

Ultimately causing a xfs_buffer with ->b_lru_ref == 0, to take another 
trip around LRU, while isolating buffers with non-zero b_lru_ref.

Signed-off-by: Vratislav Bendel <vbendel@redhat.com>
CC: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index d1da2ee9e6db..ac669a10c62f 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1708,7 +1708,7 @@ xfs_buftarg_isolate(
 	 * zero. If the value is already zero, we need to reclaim the
 	 * buffer, otherwise it gets another trip through the LRU.
 	 */
-	if (!atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
+	if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
 		spin_unlock(&bp->b_lock);
 		return LRU_ROTATE;
 	}
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH] xfs: Correctly invert xfs_buftarg LRU isolation logic
@ 2018-03-06 10:26 Vratislav Bendel
  2018-03-07  0:34 ` Darrick J. Wong
  2018-03-08  8:08 ` Christoph Hellwig
  0 siblings, 2 replies; 10+ messages in thread
From: Vratislav Bendel @ 2018-03-06 10:26 UTC (permalink / raw)
  To: linux-xfs, Darrick J . Wong; +Cc: Brian Foster, linux-kernel

Due to an inverted logic mistake in xfs_buftarg_isolate()
the xfs_buffers with zero b_lru_ref will take another trip
around LRU, while isolating buffers with non-zero b_lru_ref.

Additionally those isolated buffers end up right back on the LRU
once they are released, because b_lru_ref remains elevated.

Fix that circuitous route by leaving them on the LRU
as originally intended.

Signed-off-by: Vratislav Bendel <vbendel@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index d1da2ee9e6db..ac669a10c62f 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1708,7 +1708,7 @@ xfs_buftarg_isolate(
 	 * zero. If the value is already zero, we need to reclaim the
 	 * buffer, otherwise it gets another trip through the LRU.
 	 */
-	if (!atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
+	if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
 		spin_unlock(&bp->b_lock);
 		return LRU_ROTATE;
 	}
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-03-08  8:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-28 15:49 [PATCH] xfs: Correctly invert xfs_buftarg LRU isolation logic Vratislav Bendel
2018-02-28 19:08 ` Luis R. Rodriguez
2018-03-01 17:39 ` Brian Foster
2018-03-01 22:48 ` Darrick J. Wong
2018-03-02 16:36   ` Darrick J. Wong
2018-03-05 10:19     ` Vratislav Bendel
2018-03-05 18:52       ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2018-03-06 10:26 Vratislav Bendel
2018-03-07  0:34 ` Darrick J. Wong
2018-03-08  8:08 ` Christoph Hellwig

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).