Skip to content

Commit 79b134a

Browse files
committed
btrfs: tweak free space tree bitmap allocation
The requested bitmap size varies, observed numbers were < 4K up to 16K. Using vmalloc unconditionally would be too heavy, we'll try contiguous allocations first and fall back to vmalloc if there's no contig memory. Signed-off-by: David Sterba <[email protected]>
1 parent 8cce83b commit 79b134a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

fs/btrfs/free-space-tree.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ static inline u32 free_space_bitmap_size(u64 size, u32 sectorsize)
153153

154154
static unsigned long *alloc_bitmap(u32 bitmap_size)
155155
{
156+
void *mem;
157+
158+
/*
159+
* The allocation size varies, observed numbers were < 4K up to 16K.
160+
* Using vmalloc unconditionally would be too heavy, we'll try
161+
* contiguous allocations first.
162+
*/
163+
if (bitmap_size <= PAGE_SIZE)
164+
return kzalloc(bitmap_size, GFP_NOFS);
165+
166+
mem = kzalloc(bitmap_size, GFP_NOFS | __GFP_HIGHMEM | __GFP_NOWARN);
167+
if (mem)
168+
return mem;
169+
156170
return __vmalloc(bitmap_size, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,
157171
PAGE_KERNEL);
158172
}
@@ -289,7 +303,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
289303

290304
ret = 0;
291305
out:
292-
vfree(bitmap);
306+
kvfree(bitmap);
293307
if (ret)
294308
btrfs_abort_transaction(trans, root, ret);
295309
return ret;
@@ -438,7 +452,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
438452

439453
ret = 0;
440454
out:
441-
vfree(bitmap);
455+
kvfree(bitmap);
442456
if (ret)
443457
btrfs_abort_transaction(trans, root, ret);
444458
return ret;

0 commit comments

Comments
 (0)