From patchwork Wed Dec 19 17:37:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10737827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5314514DE for ; Wed, 19 Dec 2018 17:38:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 399F62AD7F for ; Wed, 19 Dec 2018 17:38:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 293582B6E4; Wed, 19 Dec 2018 17:38:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99AB32AD7F for ; Wed, 19 Dec 2018 17:38:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA8928E000F; Wed, 19 Dec 2018 12:38:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C559F8E0001; Wed, 19 Dec 2018 12:38:03 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA8828E000F; Wed, 19 Dec 2018 12:38:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) by kanga.kvack.org (Postfix) with ESMTP id 7E9178E0001 for ; Wed, 19 Dec 2018 12:38:03 -0500 (EST) Received: by mail-it1-f200.google.com with SMTP id t143so7280327itc.9 for ; Wed, 19 Dec 2018 09:38:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kgDREch0uno6TnGn8VSgP/fbnyM+Daf0DWv6CA+Hm7o=; b=F1ErAFRYfci2bt7fUZbA5lu2msbwH7z46QIx3sXN7GlxQLK2motXr3+7ycyZxKAgdo +owzUiKl37I+9Y74Dc4kUOGLXD9nABRz3N3Gp4HiPDaSiTBmHsSDy/yXTK/+6Py/hZOO k6tRvS09e/TRyaB0VKoVsHaCwVG+UfWCDQhFdGJw15aWhMPU37F965PTC+d0L50K3jqg tD2gumnp4XaxMm6i9/F9P06lVXmM3L6wWD8cai/NQ4Pht8sslE21TAAg/6xF6dey5fHs F9QJ1ZWDxMu4nXDAgHYnn7eyV+Fzhx+Q2n1hGaTqjGdWa2PgbQxKy3M3ZOI7Ai3xPmeV o7Rw== X-Gm-Message-State: AA+aEWZ7o+1X5FHFwH5CVX1nOCY6kjaEL5YN8wHqeGxoe+eSp5YGHSAi i3G9TljP2IDxC8K2uCEQRuM9tTrfecG6ixJjbGz9u6W0DgoFOxHSZbsF2JJTsmZsZAG6AZOr4+K 5fpS1mJWAnYbVhVsFdiiUwDjGWrboVA/EVIvzMqXik7ZRp15WDh0/PN3CvQbksLdZYxcAwMpJKM q/doame7nq61iCIINQoQ5B6ciPLlHzf3raAlezE5FFqSZkg+WxfjCYziO0u1M2kg8XTUeBE7qzf vAn3bHBe460ZdMzQGdL4e5VzrQAXtFyfjdS8GrN85oFrX6ee4XnIaBVHeCeEQfXxnVpnR0SkPh4 K12ry9WbhCUu148TFirDlga2Uhgphuo/zsnkqU9WXyxz25VspTSrFGkZCyUP0RD4QvOnfobayMQ I X-Received: by 2002:a05:660c:8c7:: with SMTP id g7mr7848379itl.44.1545241083242; Wed, 19 Dec 2018 09:38:03 -0800 (PST) X-Received: by 2002:a05:660c:8c7:: with SMTP id g7mr7848332itl.44.1545241082408; Wed, 19 Dec 2018 09:38:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545241082; cv=none; d=google.com; s=arc-20160816; b=u7Lryd1Uo9lcaCoikrEXRuMrCOy1D7kQhOCVuWpVQc0jbwQ9Y18ZAIZgLLWqXDXoUE 2yUxyj8QfPfVuruVgI0TSdUyibHaqNBCLJXiFSlb6sBd8Q5wOA6fl+KHoB4Q1dBQBVJa L2afigMQ3e5yiWRrCuqL7PDDvHltkuYMdzq8njLkOW+pO0iuwd6BYglgdhh2MY/637ZW INynl7rjbPDhaEY2pI75piVZX21sRsBvwIrEg+e/H0wP04AHkAgP46g4SppR8+lQ7Qq6 ic0aKvPGw55PLKfXk0J8ocBrehzh/95Ur0SaV+x5ljiQMjx97gm7i0sygdNIBnSN5ery pK7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=kgDREch0uno6TnGn8VSgP/fbnyM+Daf0DWv6CA+Hm7o=; b=cN9oMhv15n4w984D4IuZRQbGCRhNjk0rNVJYelW2dbA/Q1wI7OEi5RvAsdv0gxVwq0 U3NAANAnJIlEEcM+QV5Bh9q4T3M/YX+U/PVMgH3CbRB6okp6yG2n5eGiGKIdaglpmJhM mRj++xYIyOmtnZT8Rvprq4XfPqSKF8cazVwtxpEkQjJK/t7a5jO4bFB9x/7cfHNSDZYP YDs2vzYY/uSRYjRIyovg+wfzbsZxNdZZ3o7HOUmixIvasalk0BjqnI/HbkzhcA0Bve8k BmUK1kO/xBKvnT1HuaL7llUjW/DN/VhFShygJbPOoDKehuCnB5nbGpIKRvVcvMVQL5lv WSkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EDmYQL9h; spf=pass (google.com: domain of guroan@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=guroan@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m25sor2590900iti.26.2018.12.19.09.38.02 for (Google Transport Security); Wed, 19 Dec 2018 09:38:02 -0800 (PST) Received-SPF: pass (google.com: domain of guroan@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EDmYQL9h; spf=pass (google.com: domain of guroan@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=guroan@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kgDREch0uno6TnGn8VSgP/fbnyM+Daf0DWv6CA+Hm7o=; b=EDmYQL9hb4bDPQdcE93OZn3ioCoP52SxxzGFhz0zf5rH+Ox1gnqs8MluVRoJmSEdTh LqA2yOsLrmTl5fh4qGqZsGrmtNB6n7hKKXE6FOrjJTsDMZd6u5mHEz5L5lrpbI5Vbw3C LxSEWdQHUFV/QQLNWUYZoWCC9IbSy4pvLaSUl2fjHyEyWX+G9IntgwPmxsKXB+KO7KRD DK0BMk48t5EUbKJG+SkHp2mvjZqvR3/wETNBeh8AxjtrpXL+rPbHymphuU3XEggXK/vp Uta1GFKR2u5cwG6+tZ5DFmtiiH3WjrrJPqeoUTYad2daPOkmBZpSwVjspQBBk/Oy4FW7 KmkA== X-Google-Smtp-Source: AFSGD/UQryS0JBeZSHy5Ve6NEwHMkAFotihqqp++wX/z/7Cpw+1p8Vn/QuZCOnyDhw7iwMUh4DCcGQ== X-Received: by 2002:a24:8203:: with SMTP id t3mr7216765itd.151.1545241081846; Wed, 19 Dec 2018 09:38:01 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::7:bd3e]) by smtp.gmail.com with ESMTPSA id a10sm3637728itc.3.2018.12.19.09.38.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Dec 2018 09:38:01 -0800 (PST) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: linux-mm@kvack.org Cc: Matthew Wilcox , Johannes Weiner , Michal Hocko , linux-kernel@vger.kernel.org, kernel-team@fb.com, Roman Gushchin Subject: [PATCH 2/3] mm: separate memory allocation and actual work in alloc_vmap_area() Date: Wed, 19 Dec 2018 09:37:50 -0800 Message-Id: <20181219173751.28056-3-guro@fb.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219173751.28056-1-guro@fb.com> References: <20181219173751.28056-1-guro@fb.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP alloc_vmap_area() is allocating memory for the vmap_area, and performing the actual lookup of the vm area and vmap_area initialization. This prevents us from using a pre-allocated memory for the map_area structure, which can be used in some cases to minimize the number of required memory allocations. Let's keep the memory allocation part in alloc_vmap_area() and separate everything else into init_vmap_area(). Signed-off-by: Roman Gushchin Acked-by: Johannes Weiner Reviewed-by: Matthew Wilcox --- mm/vmalloc.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 7660e3ef4133..042175d7d95f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -395,16 +395,10 @@ static void purge_vmap_area_lazy(void); static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); -/* - * Allocate a region of KVA of the specified size and alignment, within the - * vstart and vend. - */ -static struct vmap_area *alloc_vmap_area(unsigned long size, - unsigned long align, - unsigned long vstart, unsigned long vend, - int node, gfp_t gfp_mask) +static int init_vmap_area(struct vmap_area *va, unsigned long size, + unsigned long align, unsigned long vstart, + unsigned long vend, int node, gfp_t gfp_mask) { - struct vmap_area *va; struct rb_node *n; unsigned long addr; int purged = 0; @@ -416,11 +410,6 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, might_sleep(); - va = kmalloc_node(sizeof(struct vmap_area), - gfp_mask & GFP_RECLAIM_MASK, node); - if (unlikely(!va)) - return ERR_PTR(-ENOMEM); - /* * Only scan the relevant parts containing pointers to other objects * to avoid false negatives. @@ -512,7 +501,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, BUG_ON(va->va_start < vstart); BUG_ON(va->va_end > vend); - return va; + return 0; overflow: spin_unlock(&vmap_area_lock); @@ -534,8 +523,35 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, if (!(gfp_mask & __GFP_NOWARN) && printk_ratelimit()) pr_warn("vmap allocation for size %lu failed: use vmalloc= to increase size\n", size); - kfree(va); - return ERR_PTR(-EBUSY); + + return -EBUSY; +} + +/* + * Allocate a region of KVA of the specified size and alignment, within the + * vstart and vend. + */ +static struct vmap_area *alloc_vmap_area(unsigned long size, + unsigned long align, + unsigned long vstart, + unsigned long vend, + int node, gfp_t gfp_mask) +{ + struct vmap_area *va; + int ret; + + va = kmalloc_node(sizeof(struct vmap_area), + gfp_mask & GFP_RECLAIM_MASK, node); + if (unlikely(!va)) + return ERR_PTR(-ENOMEM); + + ret = init_vmap_area(va, size, align, vstart, vend, node, gfp_mask); + if (ret) { + kfree(va); + return ERR_PTR(ret); + } + + return va; } int register_vmap_purge_notifier(struct notifier_block *nb)