* [PATCH] btrfs: extend locking to all space_info members accesses
@ 2022-02-25 21:20 Niels Dossche
2022-02-28 15:51 ` Johannes Thumshirn
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Niels Dossche @ 2022-02-25 21:20 UTC (permalink / raw)
To: linux-btrfs, linux-kernel
Cc: clm, josef, dsterba, Niels Dossche, Niels Dossche
bytes_pinned is always accessed under space_info->lock, except in
btrfs_preempt_reclaim_metadata_space, however the other members are
accessed under that lock. The reserved member of the rsv's are also
partially accessed under a lock and partially not. Move all these
accesses into the same lock to ensure consistency.
Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---
fs/btrfs/space-info.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 294242c194d8..62382ae1eb02 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -1061,7 +1061,6 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
trans_rsv->reserved;
if (block_rsv_size < space_info->bytes_may_use)
delalloc_size = space_info->bytes_may_use - block_rsv_size;
- spin_unlock(&space_info->lock);
/*
* We don't want to include the global_rsv in our calculation,
@@ -1092,6 +1091,8 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
flush = FLUSH_DELAYED_REFS_NR;
}
+ spin_unlock(&space_info->lock);
+
/*
* We don't want to reclaim everything, just a portion, so scale
* down the to_reclaim by 1/4. If it takes us down to 0,
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] btrfs: extend locking to all space_info members accesses
2022-02-25 21:20 [PATCH] btrfs: extend locking to all space_info members accesses Niels Dossche
@ 2022-02-28 15:51 ` Johannes Thumshirn
2022-02-28 20:41 ` Josef Bacik
2022-02-28 20:54 ` David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2022-02-28 15:51 UTC (permalink / raw)
To: Niels Dossche, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, Niels Dossche
On 25/02/2022 22:21, Niels Dossche wrote:
> bytes_pinned is always accessed under space_info->lock, except in
> btrfs_preempt_reclaim_metadata_space, however the other members are
> accessed under that lock. The reserved member of the rsv's are also
> partially accessed under a lock and partially not. Move all these
> accesses into the same lock to ensure consistency.
Maybe also add a lockdep_assert_held() call to need_preemptive_reclaim().
As of now, it has only two callsites which both hold the lock before
accessing bytes_pinned et al, but better safe then sorry.
Anyways,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: extend locking to all space_info members accesses
2022-02-25 21:20 [PATCH] btrfs: extend locking to all space_info members accesses Niels Dossche
2022-02-28 15:51 ` Johannes Thumshirn
@ 2022-02-28 20:41 ` Josef Bacik
2022-02-28 20:54 ` David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2022-02-28 20:41 UTC (permalink / raw)
To: Niels Dossche; +Cc: linux-btrfs, linux-kernel, clm, dsterba, Niels Dossche
On Fri, Feb 25, 2022 at 10:20:28PM +0100, Niels Dossche wrote:
> bytes_pinned is always accessed under space_info->lock, except in
> btrfs_preempt_reclaim_metadata_space, however the other members are
> accessed under that lock. The reserved member of the rsv's are also
> partially accessed under a lock and partially not. Move all these
> accesses into the same lock to ensure consistency.
>
> Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: extend locking to all space_info members accesses
2022-02-25 21:20 [PATCH] btrfs: extend locking to all space_info members accesses Niels Dossche
2022-02-28 15:51 ` Johannes Thumshirn
2022-02-28 20:41 ` Josef Bacik
@ 2022-02-28 20:54 ` David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2022-02-28 20:54 UTC (permalink / raw)
To: Niels Dossche
Cc: linux-btrfs, linux-kernel, clm, josef, dsterba, Niels Dossche
On Fri, Feb 25, 2022 at 10:20:28PM +0100, Niels Dossche wrote:
> bytes_pinned is always accessed under space_info->lock, except in
> btrfs_preempt_reclaim_metadata_space, however the other members are
> accessed under that lock. The reserved member of the rsv's are also
> partially accessed under a lock and partially not. Move all these
> accesses into the same lock to ensure consistency.
>
> Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-28 20:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-25 21:20 [PATCH] btrfs: extend locking to all space_info members accesses Niels Dossche
2022-02-28 15:51 ` Johannes Thumshirn
2022-02-28 20:41 ` Josef Bacik
2022-02-28 20:54 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox