mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
Reimplement k[v]realloc_node() to be able to set node and alignment should a user need to do so. In order to do that while retaining the maximal backward compatibility, add k[v]realloc_node_align() functions and redefine the rest of API using these new ones. While doing that, we also keep the number of _noprof variants to a minimum, which implies some changes to the existing users of older _noprof functions, that basically being bcachefs. With that change we also provide the ability for the Rust part of the kernel to set node and alignment in its K[v]xxx [re]allocations. Link: https://lkml.kernel.org/r/20250806124147.1724658-1-vitaly.wool@konsulko.se Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Jann Horn <jannh@google.com> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
39 lines
962 B
C
39 lines
962 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/log2.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/vmalloc.h>
|
|
#include "darray.h"
|
|
|
|
int __bch2_darray_resize_noprof(darray_char *d, size_t element_size, size_t new_size, gfp_t gfp)
|
|
{
|
|
if (new_size > d->size) {
|
|
new_size = roundup_pow_of_two(new_size);
|
|
|
|
/*
|
|
* This is a workaround: kvmalloc() doesn't support > INT_MAX
|
|
* allocations, but vmalloc() does.
|
|
* The limit needs to be lifted from kvmalloc, and when it does
|
|
* we'll go back to just using that.
|
|
*/
|
|
size_t bytes;
|
|
if (unlikely(check_mul_overflow(new_size, element_size, &bytes)))
|
|
return -ENOMEM;
|
|
|
|
void *data = likely(bytes < INT_MAX)
|
|
? kvmalloc_node_align_noprof(bytes, 1, gfp, NUMA_NO_NODE)
|
|
: vmalloc_noprof(bytes);
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
if (d->size)
|
|
memcpy(data, d->data, d->size * element_size);
|
|
if (d->data != d->preallocated)
|
|
kvfree(d->data);
|
|
d->data = data;
|
|
d->size = new_size;
|
|
}
|
|
|
|
return 0;
|
|
}
|