Skip to contentSkip to conversation

btrfs: fix comment in alloc_bitmap() and drop stale TODO

PATCH In review [email protected] 2 participants 2 messages Oct 3, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: fix comment in alloc_bitmap() and drop stale TODO

From: Rajeev Tapadia <[email protected]>

All callers of alloc_bitmap() hold a transaction handle, so GFP_NOFS is needed to avoid deadlocks on recursion. Update the comment and drop the stale TODO.

---
Change log:
As per previous review the change is not required. So just removing the stale TODO.

 fs/btrfs/free-space-tree.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/btrfs/free-space-tree.c +3 -5
index dad0b492a663..bb8ca7b679be 100644
@@ -165,11 +165,9 @@ static unsigned long *alloc_bitmap(u32 bitmap_size)
 
 	/*
 	 * GFP_NOFS doesn't work with kvmalloc(), but we really can't recurse
-	 * into the filesystem as the free space bitmap can be modified in the
-	 * critical section of a transaction commit.
-	 *
-	 * TODO: push the memalloc_nofs_{save,restore}() to the caller where we
-	 * know that recursion is unsafe.
+	 * into the filesystem here. All callers hold a transaction handle
+	 * open, so if a GFP_KERNEL allocation recurses into the filesystem
+	 * and triggers a transaction commit, we would deadlock.
 	 */
 	nofs_flag = memalloc_nofs_save();
 	ret = kvzalloc(bitmap_rounded_size, GFP_KERNEL);
Signature · 1 line
2.51.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · On Fri, Oct 3, 2025 at 2:31 PM <[email protected]> wrote:

From: Rajeev Tapadia <[email protected]>

All callers of alloc_bitmap() hold a transaction handle, so GFP_NOFS is needed to avoid deadlocks on recursion. Update the comment and drop the stale TODO.

Thanks.
I pushed it to the for-next branch:

https://github.com/btrfs/linux/commits/for-next/

Quoted 30 lines

---
Change log:
As per previous review the change is not required. So just removing the stale TODO.

 fs/btrfs/free-space-tree.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/btrfs/free-space-tree.c +3 -6
index dad0b492a663..bb8ca7b679be 100644
@@ -165,11 +165,9 @@ static unsigned long *alloc_bitmap(u32 bitmap_size)
 
        /*
         * GFP_NOFS doesn't work with kvmalloc(), but we really can't recurse
-        * into the filesystem as the free space bitmap can be modified in the
-        * critical section of a transaction commit.
-        *
-        * TODO: push the memalloc_nofs_{save,restore}() to the caller where we
-        * know that recursion is unsafe.
+        * into the filesystem here. All callers hold a transaction handle
+        * open, so if a GFP_KERNEL allocation recurses into the filesystem
+        * and triggers a transaction commit, we would deadlock.
         */
        nofs_flag = memalloc_nofs_save();
        ret = kvzalloc(bitmap_rounded_size, GFP_KERNEL);
--

2.51.0