From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26DC5C433FE for ; Wed, 2 Nov 2022 09:10:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93B668E0002; Wed, 2 Nov 2022 05:10:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EBD28E0001; Wed, 2 Nov 2022 05:10:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DB188E0002; Wed, 2 Nov 2022 05:10:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6A6558E0001 for ; Wed, 2 Nov 2022 05:10:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1C918C10DC for ; Wed, 2 Nov 2022 09:10:48 +0000 (UTC) X-FDA: 80087932176.30.5773307 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id B755140004 for ; Wed, 2 Nov 2022 09:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/89QMp6WjlwuYcBf8tvrD9DBEoepLSCyiJfq47hf0fU=; b=lRKhOcDHq1EWvuQCrx/g/CfZuM OwDe5lOPfYjNI6eSlcOq3zg8vGqkvn4ZIM/Dwi9yKWWqp/6frGkfiy1MGh1P3gF138eLifyKq11M9 fXPi0ejr+ZlHUeKaS9SNfYKP2A0y9olm6uhZvbIdNDUj4Fbp3robjU0D0HwJ8MsOQznO4Gpcvp20I Ut7DgigE2VAfJva9fWQa0HShwmbVr/heVOx7/ode0yEWGgSTyEZn98p9uag0ISldeNeeIin7BXizP j4mQgfOQ9mQFJg76j3C3GVfl1xe/VjxFhO4S9V0HJLp5gAYq7IvTxiWr87AyEuzHmrzXFowu+VAVd x9qzHunA==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oq9lj-009vF7-U3; Wed, 02 Nov 2022 09:10:43 +0000 Date: Wed, 2 Nov 2022 02:10:43 -0700 From: Christoph Hellwig To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, Uladzislau Rezki , David Howells , Dave Chinner , linux-fsdevel@vger.kernel.org, Thomas Gleixner , Ira Weiny , "Fabio M. De Francesco" , Luis Chamberlain Subject: Re: [PATCH v2 1/2] vmalloc: Factor vmap_alloc() out of vm_map_ram() Message-ID: References: <20221101201828.1170455-1-willy@infradead.org> <20221101201828.1170455-2-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221101201828.1170455-2-willy@infradead.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667380247; a=rsa-sha256; cv=none; b=emhsQoUeZqfNjdwSfCCxDh9uLWadnIivGh1QY/rcCa8wZU5dWdnkObkmcrWQCirZwTM3I+ A0ceE5w0n+tIi4K0lwvoy3qQoptHdOxZXOeyiLub3Bbsr1+fN3DUMpxFoncJxSvlzsmUnA Dk2rstInhK0kez+w9k40AtQaF88X/G4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lRKhOcDH; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+27d44d0ccf0240a6b878+7010+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+27d44d0ccf0240a6b878+7010+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667380247; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/89QMp6WjlwuYcBf8tvrD9DBEoepLSCyiJfq47hf0fU=; b=XQu/JuYoXp9g0oSKCSkqK/rrenie9igeFPpKACr9u6fYKLSFphQIT1S4n/lqT6OfncLWp7 ZK3IhbhUbKt+zCyOfa64HGVZqAXzUXfR+s0YXI6Vi9KzLb7u3Ya0N+AIHoFREKaqOVmpQg U+X1MuANKV9O5ICqMeTl3iWtox0sL8U= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lRKhOcDH; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+27d44d0ccf0240a6b878+7010+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+27d44d0ccf0240a6b878+7010+infradead.org+hch@bombadil.srs.infradead.org X-Stat-Signature: dh1fs8ti7z8t58no3mtbbrxgwafohyjc X-Rspamd-Queue-Id: B755140004 X-HE-Tag: 1667380246-773197 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > Signed-off-by: Matthew Wilcox (Oracle) > --- > 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.