Skip to content

Commit 4541408

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_kvmalloc()
Add a version of kvmalloc() that doesn't have the INT_MAX limit; large filesystems do hit this. We'll want to get rid of the in-memory bucket gens array, but we're not there quite yet. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent fa3e513 commit 4541408

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

fs/bcachefs/buckets.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ int bch2_buckets_nouse_alloc(struct bch_fs *c)
12581258
for_each_member_device(c, ca) {
12591259
BUG_ON(ca->buckets_nouse);
12601260

1261-
ca->buckets_nouse = kvmalloc(BITS_TO_LONGS(ca->mi.nbuckets) *
1261+
ca->buckets_nouse = bch2_kvmalloc(BITS_TO_LONGS(ca->mi.nbuckets) *
12621262
sizeof(unsigned long),
12631263
GFP_KERNEL|__GFP_ZERO);
12641264
if (!ca->buckets_nouse) {
@@ -1290,8 +1290,8 @@ int bch2_dev_buckets_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
12901290
if (resize && ca->buckets_nouse)
12911291
return -BCH_ERR_no_resize_with_buckets_nouse;
12921292

1293-
bucket_gens = kvmalloc(struct_size(bucket_gens, b, nbuckets),
1294-
GFP_KERNEL|__GFP_ZERO);
1293+
bucket_gens = bch2_kvmalloc(struct_size(bucket_gens, b, nbuckets),
1294+
GFP_KERNEL|__GFP_ZERO);
12951295
if (!bucket_gens) {
12961296
ret = -BCH_ERR_ENOMEM_bucket_gens;
12971297
goto err;

fs/bcachefs/util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ static inline size_t buf_pages(void *p, size_t len)
5555
PAGE_SIZE);
5656
}
5757

58+
static inline void *bch2_kvmalloc(size_t n, gfp_t flags)
59+
{
60+
void *p = unlikely(n >= INT_MAX)
61+
? vmalloc(n)
62+
: kvmalloc(n, flags & ~__GFP_ZERO);
63+
if (p && (flags & __GFP_ZERO))
64+
memset(p, 0, n);
65+
return p;
66+
}
67+
5868
#define init_heap(heap, _size, gfp) \
5969
({ \
6070
(heap)->nr = 0; \

0 commit comments

Comments
 (0)