From: David Laight <David.Laight@ACULAB.COM>
To: "'oficerovas@altlinux.org'" <oficerovas@altlinux.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Michael Ellerman <mpe@ellerman.id.au>,
"kovalev@altlinux.org" <kovalev@altlinux.org>,
"nickel@altlinux.org" <nickel@altlinux.org>,
"dutyrok@altlinux.org" <dutyrok@altlinux.org>,
Michal Hocko <mhocko@suse.com>
Subject: RE: [PATCH 1/2] mm: vmalloc: introduce array allocation functions
Date: Fri, 26 Jan 2024 13:59:59 +0000 [thread overview]
Message-ID: <f8efd03ca56c4a52b524beb937a25b57@AcuMS.aculab.com> (raw)
In-Reply-To: <20240126095514.2681649-2-oficerovas@altlinux.org>
From: oficerovas@altlinux.org
> Sent: 26 January 2024 09:55
>
> commit a8749a35c399 ("mm: vmalloc: introduce array allocation functions")
>
> Linux has dozens of occurrences of vmalloc(array_size()) and
> vzalloc(array_size()). Allow to simplify the code by providing
> vmalloc_array and vcalloc, as well as the underscored variants that let
> the caller specify the GFP flags.
>
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Alexander Ofitserov <oficerovas@altlinux.org>
> ---
> include/linux/vmalloc.h | 5 +++++
> mm/util.c | 50 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 55 insertions(+)
>
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 76dad53a410ac..0fd47f2f39eb0 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -112,6 +112,11 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
> void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
> int node, const void *caller);
>
> +extern void *__vmalloc_array(size_t n, size_t size, gfp_t flags);
> +extern void *vmalloc_array(size_t n, size_t size);
> +extern void *__vcalloc(size_t n, size_t size, gfp_t flags);
> +extern void *vcalloc(size_t n, size_t size);
Symbols starting __ should really be ones that are part of the implementation
and not publicly visible.
...
> +/**
> + * __vmalloc_array - allocate memory for a virtually contiguous array.
> + * @n: number of elements.
> + * @size: element size.
> + * @flags: the type of memory to allocate (see kmalloc).
> + */
> +void *__vmalloc_array(size_t n, size_t size, gfp_t flags)
> +{
> + size_t bytes;
> +
> + if (unlikely(check_mul_overflow(n, size, &bytes)))
> + return NULL;
> + return __vmalloc(bytes, flags);
> +}
> +EXPORT_SYMBOL(__vmalloc_array);
> +
> +/**
> + * vmalloc_array - allocate memory for a virtually contiguous array.
> + * @n: number of elements.
> + * @size: element size.
> + */
> +void *vmalloc_array(size_t n, size_t size)
> +{
> + return __vmalloc_array(n, size, GFP_KERNEL);
> +}
> +EXPORT_SYMBOL(vmalloc_array);
and that should just be an inline wrapper on the function above.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-01-26 14:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-26 9:55 [PATCH 0/2] kvm: fix kmalloc bug in kvm_arch_prepare_memory_region on 5.10 stable kernel oficerovas
2024-01-26 9:55 ` [PATCH 1/2] mm: vmalloc: introduce array allocation functions oficerovas
2024-01-26 13:59 ` David Laight [this message]
2024-01-26 18:42 ` Paolo Bonzini
2024-01-27 0:50 ` Greg Kroah-Hartman
2024-01-26 9:55 ` [PATCH 2/2] KVM: use __vcalloc for very large allocations oficerovas
2024-01-26 18:04 ` [PATCH 0/2] kvm: fix kmalloc bug in kvm_arch_prepare_memory_region on 5.10 stable kernel Paolo Bonzini
2024-01-27 0:51 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8efd03ca56c4a52b524beb937a25b57@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=dutyrok@altlinux.org \
--cc=gregkh@linuxfoundation.org \
--cc=kovalev@altlinux.org \
--cc=mhocko@suse.com \
--cc=mpe@ellerman.id.au \
--cc=nickel@altlinux.org \
--cc=oficerovas@altlinux.org \
--cc=pbonzini@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox