Skip to content

Commit f0d3302

Browse files
author
Kent Overstreet
committed
bcachefs: Workaround for kvmalloc() not supporting > INT_MAX allocations
kvmalloc() doesn't support allocations > INT_MAX, but vmalloc() does - the limit should be lifted, but we can work around this for now. A user with a 75 TB filesystem reported the following journal replay error: koverstreet/bcachefs#769 In journal replay we have to sort and dedup all the keys from the journal, which means we need a large contiguous allocation. Given that the user has 128GB of ram, the 2GB limit on allocation size has become far too small. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 3956ff8 commit f0d3302

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

fs/bcachefs/darray.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22

33
#include <linux/log2.h>
44
#include <linux/slab.h>
5+
#include <linux/vmalloc.h>
56
#include "darray.h"
67

78
int __bch2_darray_resize_noprof(darray_char *d, size_t element_size, size_t new_size, gfp_t gfp)
89
{
910
if (new_size > d->size) {
1011
new_size = roundup_pow_of_two(new_size);
1112

12-
void *data = kvmalloc_array_noprof(new_size, element_size, gfp);
13+
/*
14+
* This is a workaround: kvmalloc() doesn't support > INT_MAX
15+
* allocations, but vmalloc() does.
16+
* The limit needs to be lifted from kvmalloc, and when it does
17+
* we'll go back to just using that.
18+
*/
19+
size_t bytes;
20+
if (unlikely(check_mul_overflow(new_size, element_size, &bytes)))
21+
return -ENOMEM;
22+
23+
void *data = likely(bytes < INT_MAX)
24+
? kvmalloc_noprof(bytes, gfp)
25+
: vmalloc_noprof(bytes);
1326
if (!data)
1427
return -ENOMEM;
1528

0 commit comments

Comments
 (0)