diff options
author | David Sterba <dsterba@suse.com> | 2018-05-11 17:57:54 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-05-28 18:24:09 +0200 |
commit | bf5091c8d69e95c34dab2224b98a9cb0ccff1aa8 (patch) | |
tree | ac3fff8b933faca399ed8edf10f1f3d3c4b9279d /fs/btrfs/ioctl.c | |
parent | Btrfs: reuse cmp workspace in EXTENT_SAME ioctl (diff) | |
download | linux-bf5091c8d69e95c34dab2224b98a9cb0ccff1aa8.tar.xz linux-bf5091c8d69e95c34dab2224b98a9cb0ccff1aa8.zip |
btrfs: use kvzalloc for EXTENT_SAME temporary data
The dedupe range is 16 MiB, with 4 KiB pages and 8 byte pointers, the
arrays can be 32KiB large. To avoid allocation failures due to
fragmented memory, use the allocation with fallback to vmalloc.
The arrays are allocated and freed only inside btrfs_extent_same and
reused for all the ranges.
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to '')
-rw-r--r-- | fs/btrfs/ioctl.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 99eab7b3e5e1..aeef6cd8aaeb 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3144,12 +3144,13 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, * locking. We use an array for the page pointers. Size of the array is * bounded by len, which is in turn bounded by BTRFS_MAX_DEDUPE_LEN. */ - cmp.src_pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); - cmp.dst_pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); + cmp.src_pages = kvmalloc_array(num_pages, sizeof(struct page *), + GFP_KERNEL | __GFP_ZERO); + cmp.dst_pages = kvmalloc_array(num_pages, sizeof(struct page *), + GFP_KERNEL | __GFP_ZERO); if (!cmp.src_pages || !cmp.dst_pages) { - kfree(cmp.src_pages); - kfree(cmp.dst_pages); - return -ENOMEM; + ret = -ENOMEM; + goto out_free; } for (i = 0; i < chunk_count; i++) { @@ -3172,8 +3173,9 @@ out_unlock: else btrfs_double_inode_unlock(src, dst); - kfree(cmp.src_pages); - kfree(cmp.dst_pages); +out_free: + kvfree(cmp.src_pages); + kvfree(cmp.dst_pages); return ret; } |