Commit 45414083 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent fa3e5135
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1258,7 +1258,7 @@ int bch2_buckets_nouse_alloc(struct bch_fs *c)
	for_each_member_device(c, ca) {
		BUG_ON(ca->buckets_nouse);

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

	bucket_gens = kvmalloc(struct_size(bucket_gens, b, nbuckets),
	bucket_gens = bch2_kvmalloc(struct_size(bucket_gens, b, nbuckets),
				    GFP_KERNEL|__GFP_ZERO);
	if (!bucket_gens) {
		ret = -BCH_ERR_ENOMEM_bucket_gens;
+10 −0
Original line number Diff line number Diff line
@@ -55,6 +55,16 @@ static inline size_t buf_pages(void *p, size_t len)
			    PAGE_SIZE);
}

static inline void *bch2_kvmalloc(size_t n, gfp_t flags)
{
	void *p = unlikely(n >= INT_MAX)
		? vmalloc(n)
		: kvmalloc(n, flags & ~__GFP_ZERO);
	if (p && (flags & __GFP_ZERO))
		memset(p, 0, n);
	return p;
}

#define init_heap(heap, _size, gfp)					\
({									\
	(heap)->nr = 0;						\