Skip to contentSkip to conversation

btrfs: add lockdep_assert_held to need_preemptive_reclaim

PATCH Superseded Niels Dossche 2 participants 3 messages Feb 28, 2022 – Mar 3, 2022 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: add lockdep_assert_held to need_preemptive_reclaim

In a previous patch I extended the locking for member accesses of space_info. It was then suggested to also add a lockdep assertion for space_info->lock to need_preemptive_reclaim.

---
 fs/btrfs/space-info.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +5 -1
index 294242c194d8..5464bd168d5b 100644
@@ -734,9 +734,13 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
 {
 	u64 global_rsv_size = fs_info->global_block_rsv.reserved;
 	u64 ordered, delalloc;
-	u64 thresh = div_factor_fine(space_info->total_bytes, 90);
+	u64 thresh;
 	u64 used;
 
+	lockdep_assert_held(&space_info->lock);
+
+	thresh = div_factor_fine(space_info->total_bytes, 90);
+
 	/* If we're just plain full then async reclaim just slows us down. */
 	if ((space_info->bytes_used + space_info->bytes_reserved +
 	     global_rsv_size) >= thresh)
Signature · 1 line
2.35.1
#1 lore raw
Quoted 2 lines · Niels Dossche

In a previous patch I extended the locking for member accesses of space_info.

A reference to another patch would be by a subject or a specific commit id (not applicable in this case) or you can write it without any reference if the change is standalone. The changelog should describe the reason for the change, user visible effects, what can go wrong etc.

Quoted 14 lines

It was then suggested to also add a lockdep assertion for space_info->lock to need_preemptive_reclaim.

---
 fs/btrfs/space-info.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +0 -0
index 294242c194d8..5464bd168d5b 100644

fs/btrfs/space-info.c static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info, · line 742

Quoted 10 lines
fs/btrfs/space-info.c +4 -1
@@ -734,9 +734,13 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
 {
 	u64 global_rsv_size = fs_info->global_block_rsv.reserved;
 	u64 ordered, delalloc;
-	u64 thresh = div_factor_fine(space_info->total_bytes, 90);
+	u64 thresh;
 	u64 used;
 
+	lockdep_assert_held(&space_info->lock);
+
+	thresh = div_factor_fine(space_info->total_bytes, 90);

I'm not sure this is necessary, as this is not locking where the initialization would have to be inside. The lockdep assertion is just a warning, so it does not matter where the intialization is done, I'd prefer to keep it as is.

#2 lore raw
Quoted 9 lines · David Sterba
Quoted 2 lines · Niels Dossche

In a previous patch I extended the locking for member accesses of space_info.

A reference to another patch would be by a subject or a specific commit id (not applicable in this case) or you can write it without any reference if the change is standalone. The changelog should describe the reason for the change, user visible effects, what can go wrong etc.

I will make sure to do that in the future. Thanks.

Quoted 21 lines
Quoted 21 lines

It was then suggested to also add a lockdep assertion for space_info->lock to need_preemptive_reclaim.

---
 fs/btrfs/space-info.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/space-info.c +1 -1
index 294242c194d8..5464bd168d5b 100644
@@ -734,9 +734,13 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
 {
 	u64 global_rsv_size = fs_info->global_block_rsv.reserved;
 	u64 ordered, delalloc;
-	u64 thresh = div_factor_fine(space_info->total_bytes, 90);
+	u64 thresh;
 	u64 used;
 
Quoted 8 lines

fs/btrfs/space-info.c static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info, · line 742

Quoted 3 lines
fs/btrfs/space-info.c +3 -0
+	lockdep_assert_held(&space_info->lock);
+
+	thresh = div_factor_fine(space_info->total_bytes, 90);

I'm not sure this is necessary, as this is not locking where the initialization would have to be inside. The lockdep assertion is just a warning, so it does not matter where the intialization is done, I'd prefer to keep it as is.

I understand. Thank you for your feedback. I will send a v2 shortly.