Skip to contentSkip to conversation

Btrfs: allocate ulists in btrfs_check_shared() using GFP_KERNEL

PATCH In review [email protected] 2 participants 4 messages Apr 15, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: allocate ulists in btrfs_check_shared() using GFP_KERNEL

From: Filipe Manana <[email protected]>

As of commit bb739cf08e8f32 ("btrfs: btrfs_check_shared should manage its own transaction") btrfs_check_shared() manages its own transaction, it no longer receives a transaction handle as parameter. Since it is used only in the fiemap path, the ulists it needs to use are allocated before it grabs a transaction handle and we are not holding any locks that could cause a deadlock in case reclaim happens during a memory allocation, we can use the GFP_KERNEL flag to allocate the ulists instead of GFP_NOFS. So do that switch.

---
 fs/btrfs/backref.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/backref.c +2 -2
index 876e6bb93797..377978bb8845 100644
@@ -1481,8 +1481,8 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
 		.share_count = 0,
 	};
 
-	tmp = ulist_alloc(GFP_NOFS);
-	roots = ulist_alloc(GFP_NOFS);
+	tmp = ulist_alloc(GFP_KERNEL);
+	roots = ulist_alloc(GFP_KERNEL);
 	if (!tmp || !roots) {
 		ulist_free(tmp);
 		ulist_free(roots);
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Mon, Apr 15, 2019 at 09:29:10AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

As of commit bb739cf08e8f32 ("btrfs: btrfs_check_shared should manage its own transaction") btrfs_check_shared() manages its own transaction, it no longer receives a transaction handle as parameter. Since it is used only in the fiemap path, the ulists it needs to use are allocated before it grabs a transaction handle and we are not holding any locks that could cause a deadlock in case reclaim happens during a memory allocation, we can use the GFP_KERNEL flag to allocate the ulists instead of GFP_NOFS. So do that switch.

Quoted 1 line
#2 lore raw
Quoted 13 lines · David Sterba
Quoted 11 lines · On Mon, Apr 15, 2019 at 09:29:10AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

As of commit bb739cf08e8f32 ("btrfs: btrfs_check_shared should manage its own transaction") btrfs_check_shared() manages its own transaction, it no longer receives a transaction handle as parameter. Since it is used only in the fiemap path, the ulists it needs to use are allocated before it grabs a transaction handle and we are not holding any locks that could cause a deadlock in case reclaim happens during a memory allocation, we can use the GFP_KERNEL flag to allocate the ulists instead of GFP_NOFS. So do that switch.

Quoted 3 lines
Quoted 1 line

Actually no, this isn't safe, drop it please.
An inode's range is locked, the allocations can trigger writeback for that inode, and writepages() needs to lock the range as well.

Thanks.

#3 lore raw
Quoted 14 lines · Filipe Manana
Quoted 13 lines · David Sterba
Quoted 11 lines · On Mon, Apr 15, 2019 at 09:29:10AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

As of commit bb739cf08e8f32 ("btrfs: btrfs_check_shared should manage its own transaction") btrfs_check_shared() manages its own transaction, it no longer receives a transaction handle as parameter. Since it is used only in the fiemap path, the ulists it needs to use are allocated before it grabs a transaction handle and we are not holding any locks that could cause a deadlock in case reclaim happens during a memory allocation, we can use the GFP_KERNEL flag to allocate the ulists instead of GFP_NOFS. So do that switch.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Actually no, this isn't safe, drop it please.
An inode's range is locked, the allocations can trigger writeback for that inode, and writepages() needs to lock the range as well.

Ah, right, lock_extent_bits. I think the ulist allocations can be moved outside of the section to extent_fiemap, each call of btrfs_check_shared allocates and frees.