From: Christoph Hellwig <hch@infradead.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-mm@kvack.org, Uladzislau Rezki <urezki@gmail.com>,
David Howells <dhowells@redhat.com>,
Dave Chinner <david@fromorbit.com>,
linux-fsdevel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ira Weiny <ira.weiny@intel.com>,
"Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
Luis Chamberlain <mcgrof@kernel.org>
Subject: Re: [PATCH v2 1/2] vmalloc: Factor vmap_alloc() out of vm_map_ram()
Date: Wed, 2 Nov 2022 02:10:43 -0700 [thread overview]
Message-ID: <Y2I0E/cpHQK9iuCS@infradead.org> (raw)
In-Reply-To: <20221101201828.1170455-2-willy@infradead.org>
On Tue, Nov 01, 2022 at 08:18:27PM +0000, Matthew Wilcox (Oracle) wrote:
> Introduce vmap_alloc() to simply get the address space. This allows
> for code sharing in the next patch.
>
> Suggested-by: Uladzislau Rezki <urezki@gmail.com>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> mm/vmalloc.c | 41 +++++++++++++++++++++++------------------
> 1 file changed, 23 insertions(+), 18 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index ccaa461998f3..dcab1d3cf185 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2230,6 +2230,27 @@ void vm_unmap_ram(const void *mem, unsigned int count)
> }
> EXPORT_SYMBOL(vm_unmap_ram);
>
> +static void *vmap_alloc(size_t size, int node)
> +{
> + void *mem;
> +
> + if (likely(size <= (VMAP_MAX_ALLOC * PAGE_SIZE))) {
> + mem = vb_alloc(size, GFP_KERNEL);
> + if (IS_ERR(mem))
> + mem = NULL;
> + } else {
> + struct vmap_area *va;
> + va = alloc_vmap_area(size, PAGE_SIZE,
> + VMALLOC_START, VMALLOC_END, node, GFP_KERNEL);
> + if (IS_ERR(va))
> + mem = NULL;
> + else
> + mem = (void *)va->va_start;
> + }
> +
> + return mem;
This reads really strange, why not return the ERR_PTR and do:
static void *vmap_alloc(size_t size, int node)
{
if (unlikely(size > VMAP_MAX_ALLOC * PAGE_SIZE)) {
struct vmap_area *va;
va = alloc_vmap_area(size, PAGE_SIZE, VMALLOC_START,
VMALLOC_END, node, GFP_KERNEL);
if (IS_ERR(va))
return ERR_CAST(va);
return (void *)va->va_start;
}
return vb_alloc(size, GFP_KERNEL);
}
> @@ -2247,24 +2268,8 @@ EXPORT_SYMBOL(vm_unmap_ram);
> void *vm_map_ram(struct page **pages, unsigned int count, int node)
> {
> unsigned long size = (unsigned long)count << PAGE_SHIFT;
> + void *mem = vmap_alloc(size, node);
> + unsigned long addr = (unsigned long)mem;
And here we still need the error check anyway, no matter if it is for
NULL or an ERR_PTR.
next prev parent reply other threads:[~2022-11-02 9:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 20:18 [PATCH v2 0/2] Mapping an entire folio Matthew Wilcox (Oracle)
2022-11-01 20:18 ` [PATCH v2 1/2] vmalloc: Factor vmap_alloc() out of vm_map_ram() Matthew Wilcox (Oracle)
2022-11-02 3:46 ` Hyeonggon Yoo
2022-11-02 3:59 ` Hyeonggon Yoo
2022-11-02 9:10 ` Christoph Hellwig [this message]
2022-11-01 20:18 ` [PATCH v2 2/2] mm: Add folio_map_local() Matthew Wilcox (Oracle)
2022-11-02 9:13 ` Christoph Hellwig
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=Y2I0E/cpHQK9iuCS@infradead.org \
--to=hch@infradead.org \
--cc=david@fromorbit.com \
--cc=dhowells@redhat.com \
--cc=fmdefrancesco@gmail.com \
--cc=ira.weiny@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mcgrof@kernel.org \
--cc=tglx@linutronix.de \
--cc=urezki@gmail.com \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).