From patchwork Tue Feb 12 17:56:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10808441 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 4A804746 for ; Tue, 12 Feb 2019 17:57:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 396612C517 for ; Tue, 12 Feb 2019 17:57:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D2652C529; Tue, 12 Feb 2019 17:57:20 +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 678DE2C517 for ; Tue, 12 Feb 2019 17:57:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 754088E0002; Tue, 12 Feb 2019 12:57:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 703708E0001; Tue, 12 Feb 2019 12:57:18 -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 5F2DF8E0002; Tue, 12 Feb 2019 12:57:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 207FB8E0001 for ; Tue, 12 Feb 2019 12:57:18 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id w20so2717647ply.16 for ; Tue, 12 Feb 2019 09:57:18 -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=93OAZAKUmkpYvDgCLiiRT27o1RpTSM6guTV/d2KLbuo=; b=cJ+XABE4RoUX6aiSm2AFwLtasnfNMLSHiEXJlfDtSEN+eujS30AHN/+o3yypDscgU0 0YJ705ijeUw5iR3I0a7RYwFdTWs4g/2dpQ2KF36C5ECtfWt62tiRDfKlUgNIhLnjdpRX EtQE73ETdVtG1YdF9vxTAzSzFR44CbwtChNE58ChKFTIh3IjM5FzU0uO4IWMO+lADJY0 GZzNlHUdWV+F1/tP41lhblt+we6yfgIIiLseYPL+/+Lp1muqY/I38UBXaOzHq30P34h6 6euw907ICTyPsLAOTLNNXGsaoR6m/M4ChUCjg4afjfxOF3vK1QuZvpq0nf+/uThggnt4 lx/g== X-Gm-Message-State: AHQUAuba32EPftyd+W8LbbAP5Y2/+vM5AdAoMUAwYXu546hWwbD7sLnQ uHczibg/KCZCyLxOsitxZVU32MDnSKkM1FY0f8YjFmzYrWucVUE/UNTwHWxP3oeMf1gEvJWjpDj sVCU50ssBVrd4F4HF1IybigEQ+4hD26hsqethc/LsEp+O/u0ZEdi/bMBsTRwx8AQRY9G7xn0CJK 12IBb+ObqkuO7+Qj99StkRQx309gNUXSC+Hu07BzN/0G2BcnuB9VcJLyOCqKklVXQKuAws8/Ktd lF1VMEOHFg7Q7ePY2KpQIVGlhhofPljvTG5n6kqvrV2N0dQFj6FOu1DyGt7f444BiJTx9DE4FH6 xlo5KBZxuQzGfY+sC/vkA/RVLBrv9D55U1Vs8zoQ8I5jZAYbB3KQ4tIpzoQNKIwq7HrJN4Ful2o v X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr5292076plb.51.1549994237700; Tue, 12 Feb 2019 09:57:17 -0800 (PST) X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr5292038plb.51.1549994236943; Tue, 12 Feb 2019 09:57:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549994236; cv=none; d=google.com; s=arc-20160816; b=YnIPp8p0vbf0TV4/Lezt54bqEIOVcJKuV0Bs+1s/JHcRYVf4sKx9wLYm6oDl3EY6sh 8IHqGdDkmjAEIz9HWuevCvHkyquRPefh7x/NoaElk4OTWlvwfpcBr/Xo9t52EO+duKpt rmKGs5oYblb6aCVlYu+9FqgKeTNXhMkOP/e5EYbtp4Pfne6JbYR+jy35he2Ylpdu8+ec 6kTUhk7N+hQtnR/l4LOEQNuj+/Oaz7AyjZSB0Z7N/gwQo3D1jIIZWxGSHHK5eYWUHnZK SKOLagtw7SvYIqgPy/qtbRX3T75t1G9aHdSzitijGIBP0ZNH929ZE4bXDRleZV7uRuPJ OYvw== 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=93OAZAKUmkpYvDgCLiiRT27o1RpTSM6guTV/d2KLbuo=; b=qbWmo276u1FueEhh8H34btnMKk0npE1qDXoN6/JacuvfLWqt7Hkt/ebFbvQuzdT57J u4j6L2aaqyQvT1JJzluHhZ9aLw3iB1m33SnQYqa+44fbHjgtcP5huJ6W8Gvms4O/cir6 m5kRQOeGT/AavR1I1uWMJ/8jHI/7hz4odzEPGKaPMQ0fvY5eHfpsTBL7ONdJJSHfMLhS xuym60MaerUYiljz8KsBoMIMnEXPxhyv0sK0SDwFTnLHQvwotJG/Ln0sgKAefEz61ded 4txzOrCEaCIcOBjxWpT6r8681qDKMxV6yEFhMOIxVP3B5qOQ76SnMMQXSNUARHrbAQzj teug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QCGXaJM2; 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 t17sor13757828plo.73.2019.02.12.09.57.16 for (Google Transport Security); Tue, 12 Feb 2019 09:57:16 -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=QCGXaJM2; 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=93OAZAKUmkpYvDgCLiiRT27o1RpTSM6guTV/d2KLbuo=; b=QCGXaJM2hZZokK7yOMpTLoWcdJNyPFmRc21nwx+XYJj7UgFF+4IibYRea/KVv3ZX8c 8JX53r9R78lt/ndj5qADE9ryXZzv0gfWL9C0CDRozNeMTN3mo6D/V5Vk3KXHmiLYZJHS +kPGtC/3cmiCB718Tj0itOFo4U6RwAnZtulKgLIXt7eYnd17h2kjyeQ/fHvu2qSPqG9M +hRIsHipg4Cjpd1Wju20iuBLziYb4UH/o9hmAf/hxuy+llEbnOB1v4dwk8gm5FvWROL2 aUmqZWfujJ7MKlJpZbi2RA8r8VlJtiSfkJFER/AA0m/HBT/8iEyWkygcjFbRLGwFmGI4 IVhQ== X-Google-Smtp-Source: AHgI3IbR1QARiQM372qVa41Na+Ijx46rJgy765Pia3Oe3eVsWoU2m3AYeLeFpsuP9V7WXRuErsrY7Q== X-Received: by 2002:a17:902:243:: with SMTP id 61mr4968727plc.249.1549994236475; Tue, 12 Feb 2019 09:57:16 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::5:4d62]) by smtp.gmail.com with ESMTPSA id z186sm18608427pfz.119.2019.02.12.09.57.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Feb 2019 09:57:15 -0800 (PST) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: linux-mm@kvack.org Cc: Matthew Wilcox , Johannes Weiner , kernel-team@fb.com, Andrew Morton , linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH v2 1/3] mm: refactor __vunmap() to avoid duplicated call to find_vm_area() Date: Tue, 12 Feb 2019 09:56:46 -0800 Message-Id: <20190212175648.28738-2-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212175648.28738-1-guro@fb.com> References: <20190212175648.28738-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 __vunmap() calls find_vm_area() twice without an obvious reason: first directly to get the area pointer, second indirectly by calling remove_vm_area(), which is again searching for the area. To remove this redundancy, let's split remove_vm_area() into __remove_vm_area(struct vmap_area *), which performs the actual area removal, and remove_vm_area(const void *addr) wrapper, which can be used everywhere, where it has been used before. On my test setup, I've got 5-10% speed up on vfree()'ing 1000000 of 4-pages vmalloc blocks. Signed-off-by: Roman Gushchin Cc: Johannes Weiner Cc: Matthew Wilcox --- mm/vmalloc.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b7455d4c8c12..8f0179895fb5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1477,6 +1477,24 @@ struct vm_struct *find_vm_area(const void *addr) return NULL; } +static struct vm_struct *__remove_vm_area(struct vmap_area *va) +{ + struct vm_struct *vm = va->vm; + + might_sleep(); + + spin_lock(&vmap_area_lock); + va->vm = NULL; + va->flags &= ~VM_VM_AREA; + va->flags |= VM_LAZY_FREE; + spin_unlock(&vmap_area_lock); + + kasan_free_shadow(vm); + free_unmap_vmap_area(va); + + return vm; +} + /** * remove_vm_area - find and remove a continuous kernel virtual area * @addr: base address @@ -1489,31 +1507,20 @@ struct vm_struct *find_vm_area(const void *addr) */ struct vm_struct *remove_vm_area(const void *addr) { + struct vm_struct *vm = NULL; struct vmap_area *va; - might_sleep(); - va = find_vmap_area((unsigned long)addr); - if (va && va->flags & VM_VM_AREA) { - struct vm_struct *vm = va->vm; - - spin_lock(&vmap_area_lock); - va->vm = NULL; - va->flags &= ~VM_VM_AREA; - va->flags |= VM_LAZY_FREE; - spin_unlock(&vmap_area_lock); - - kasan_free_shadow(vm); - free_unmap_vmap_area(va); + if (va && va->flags & VM_VM_AREA) + vm = __remove_vm_area(va); - return vm; - } - return NULL; + return vm; } static void __vunmap(const void *addr, int deallocate_pages) { struct vm_struct *area; + struct vmap_area *va; if (!addr) return; @@ -1522,17 +1529,18 @@ static void __vunmap(const void *addr, int deallocate_pages) addr)) return; - area = find_vm_area(addr); - if (unlikely(!area)) { + va = find_vmap_area((unsigned long)addr); + if (unlikely(!va || !(va->flags & VM_VM_AREA))) { WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n", addr); return; } + area = va->vm; debug_check_no_locks_freed(area->addr, get_vm_area_size(area)); debug_check_no_obj_freed(area->addr, get_vm_area_size(area)); - remove_vm_area(addr); + __remove_vm_area(va); if (deallocate_pages) { int i; @@ -1547,7 +1555,6 @@ static void __vunmap(const void *addr, int deallocate_pages) } kfree(area); - return; } static inline void __vfree_deferred(const void *addr) From patchwork Tue Feb 12 17:56:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10808443 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 18EBA746 for ; Tue, 12 Feb 2019 17:57:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07DAD2C517 for ; Tue, 12 Feb 2019 17:57:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F03B92C528; Tue, 12 Feb 2019 17:57:22 +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 C2B722C517 for ; Tue, 12 Feb 2019 17:57:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD8EC8E0003; Tue, 12 Feb 2019 12:57:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9C3B08E0001; Tue, 12 Feb 2019 12:57:19 -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 7A0E38E0003; Tue, 12 Feb 2019 12:57:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 3C7EC8E0001 for ; Tue, 12 Feb 2019 12:57:19 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id f3so2602781pgq.13 for ; Tue, 12 Feb 2019 09:57:19 -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=JDU7hPspNg25hPl2OvBKS7YvtxIGkNRnjLg+s4xyhDM=; b=epedpf7OHFHKlEKV2FaqrJiIGdLLWgqpWrEL+6mBV+M9Sl9/saiHGx1WNkIcMkbal7 skESz9vYlIg+HaV4Na1wfOGPnDCsC0aRJg1wiSey3SiE2EwC4u1ufL/1K1vVkYx3BD0J +qQgg5EB6QGJiNtlX5vnEm8YgpX85KNPCnSRRZYHb5NGKDAtkTCnGP/8H1g0Fhb9FX5X T30blQ9rielDVjd7jDqTTBLuy4fh2ERXKsJdQ7latx8+2bvQK7AdiTWGsy4ciUuglJC4 9CwC1doegmjsPVxeAKe7VZ/d+jyguYdwfiXNUPkg9LIcSrFZNxp4rVRWXbXJkyrDW6oK Vlcw== X-Gm-Message-State: AHQUAuZp1PgEaH3RpfywbwYohWth1Q1lG75c80j5mUbdTmsjkkW2Sn0C Q3TY9uW9K24hkjgdKnx2taMwtE46Lw1E/Su5uXca6nsw/H95tUOjFVSPJ8AYgoovQpQqEFEVxM6 OdVX745cJmsivp20f+YeoHjyJnigCmvdbh1dMOgm5rtPY7JJknaHCNCo2g+wr775OmJXsPy+oTm iw03h31nGBsnz6TULwty/ntvK7QlAfVrozcMLuRwQFRoTOULmSB2XwKhXIL6WCL65qk58zmWDhd 6FGyvhCfe/+3bCI2FfukZ3Ev9K1HfVh3bEvcqG5z+PM9wD/zqmXWjgisaEnb0FUbr2LKoin3qFv V3/mlPDpM9Vi2XqL/GewzQjx6e4gqpmoi0awfGsULwoPdcWiuI2whfn0GM7QOuBmkVKvE2KMHxq 7 X-Received: by 2002:a63:4b25:: with SMTP id y37mr4779192pga.181.1549994238885; Tue, 12 Feb 2019 09:57:18 -0800 (PST) X-Received: by 2002:a63:4b25:: with SMTP id y37mr4779152pga.181.1549994238109; Tue, 12 Feb 2019 09:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549994238; cv=none; d=google.com; s=arc-20160816; b=WUn9HHfTpcXt8Z2rz00D6X9P/H6NmsV6gWf8JFu3p77aZ07jzQc+tu6gdFK1GskQQ5 I9dLsSxtwLtEjNZ1TRXBEapu+qCYOGSUsMraY0Q8K2fe64D2q8L4i8pMI0ZyeIBQ/pMW 49NVYrIZnPyfdH0qz4wQ4Z+kVEmUGU4SGCK4RAz6WuarkTllkqVBz3uruo7HwhK2M06Y kk4r8v9U0+f+nXovGxWB+LAD4NXj26auyFNkvC38vW44dkFdmnmnVvH4mjHNbRzh+5wh GaC9wNN3W3JKo010osRdVdZ5+GQEdKQ6YcvbeZOg7K8xQ33A++Ba17It4O60jh4sSGRw zM6g== 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=JDU7hPspNg25hPl2OvBKS7YvtxIGkNRnjLg+s4xyhDM=; b=ZNoCN1Nxe6GQq/ROQxqcj55h8Pmm+NqU6b6cDuT/gh44fvZOLsbSPi44w1FOdtDPzk q9X9dmmwE6iXgikUvS/PgGOOHNcgiuXoCtCjbvoVteh1fmGWE4dxqNW8xvePjVIUOAaU AZVvkMLiHrn5u/EWQi6YEDFzu5DWuljFKDRCapNcWkjo4AmVrV3zMMoLB+vLd3mvdNGO L6opHNn+Txq0IELKwDV5xabEKSC5hBvE095zHTlmNDx3x9k87+xDtcM5lykLX6frg8va t2XwuwkEJsK+WO4TBuz1VvHOBKhXkRlYjTHzNzhEt01VuEdFFB2UG5n+oHaet9zmdIE+ z03g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZsKPvlBS; 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 i37sor19658377plb.45.2019.02.12.09.57.18 for (Google Transport Security); Tue, 12 Feb 2019 09:57:18 -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=ZsKPvlBS; 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=JDU7hPspNg25hPl2OvBKS7YvtxIGkNRnjLg+s4xyhDM=; b=ZsKPvlBSND/BBli5ocsBaMaB7S8odXyIT8DmJfUMHKbU8LQFv8ZJBe6VkCGW6UXfxg 5qYud7MxGIilXgI8DJUK9T6Oe6cONgQuIS3uwg+cl8HAjPSL5Il/zuHcV0SIkC927B1F EYlJdurDGZjozSxpH5mR5GIJwSwAyxU4Kc3pQTRycew3NMPW/pfNEm3Va1/jzTICbNm+ ToWjMq8dtVE8BV84AjpIFM2XR9De2VX/FTdBKqO7NPLnb7313azhRYP9OFQWEgljFljU YIGeGSOY2Sqs+QsslDvU6Sdw+WQUw2wWFSaZKaVpfLTPlADbmPMQlFn4SnDiyoPCQpkP iCsg== X-Google-Smtp-Source: AHgI3IbIqG76F5iw/WVx3RtEmtdN8RqImuM6uM/rK60cWCtO/s3g+/3YiAcKucPyCDktEnwvUciCUw== X-Received: by 2002:a17:902:1d4a:: with SMTP id u10mr5002457plu.122.1549994237645; Tue, 12 Feb 2019 09:57:17 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::5:4d62]) by smtp.gmail.com with ESMTPSA id z186sm18608427pfz.119.2019.02.12.09.57.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Feb 2019 09:57:16 -0800 (PST) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: linux-mm@kvack.org Cc: Matthew Wilcox , Johannes Weiner , kernel-team@fb.com, Andrew Morton , linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH v2 2/3] mm: separate memory allocation and actual work in alloc_vmap_area() Date: Tue, 12 Feb 2019 09:56:47 -0800 Message-Id: <20190212175648.28738-3-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212175648.28738-1-guro@fb.com> References: <20190212175648.28738-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 8f0179895fb5..f1f19d1105c4 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. @@ -516,7 +505,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); @@ -538,8 +527,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) From patchwork Tue Feb 12 17:56:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10808445 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 3FDAA1390 for ; Tue, 12 Feb 2019 17:57:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E31E2C517 for ; Tue, 12 Feb 2019 17:57:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F6C42C528; Tue, 12 Feb 2019 17:57:25 +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 8D4172C517 for ; Tue, 12 Feb 2019 17:57:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B273B8E0004; Tue, 12 Feb 2019 12:57:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD4EC8E0001; Tue, 12 Feb 2019 12:57:20 -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 9EBF68E0004; Tue, 12 Feb 2019 12:57:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 625048E0001 for ; Tue, 12 Feb 2019 12:57:20 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id t65so2980938pfj.19 for ; Tue, 12 Feb 2019 09:57:20 -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=gKD32Yoy3OQX5/4gri4PxomY3lVn8k0uhfbQMdVmPC8=; b=r38TmtOCxMrFvutl9Y3O5kPoIrjWLtcuzw0F7Ii0jKwOUel8bUf4T9xIMAuYSko77/ f7JfXkT42zoEcs+I1FzqbacqinOBHfDOVOII96dEn4yvaywoESDk47jdfH2vMNnKdrH+ TVn4NnEhODe+mR2DHhxoJUpIMXyRnvi3hCuxwhVt5pp2AXqympv7bCAh3cHqMBT0pM7x Jq9jjdhVA2ymTyKhqq4KAudjjgS3LPPy8xK5XKEwJdlGTB4w025Zw8xZKSFdsUYKMtT9 s1OiH/3c3Uac4pO39CmsnFqEaCrRrF0qfMzh3CUjkEYD3jGvBdoh343NSi0iStijUpQQ HlIA== X-Gm-Message-State: AHQUAuY0WjnDW9JwE/u/a+uaiiy5Cml2I8JLebVSaqhrGQOznpQYi8UR oWbTioRMPjS0KPjJjCsnR17wK+2Bh7Pim+Khf5UiSW0yMEYMwyMWW4Jtko1ox48U3WLLXTayBIG aYWd1C4BmrX1QFKAifWBoXi3CgRjZMFplhEi8uOQS2UdCttUqJ37xFq17WqcB+N3GN4Ze/2VO8G k2TRYQyXTRRpyj6HLAzkeA+IBWoum1hE0DEKRtDbZTEybr+yLAoLqKTJMN7emSDlOFe/nnjhfgL dGqF7LFfT6eKNQ/TjzFYHE7AiMjtzv6Ohqx/UrHV1Abx6rfazZ5MZo91h/dm/pwpbMrKsVvIFGR 43OXMdVUxSj48LGt/ei9Sk+SNxNv6jL3hrUoezUcZfogkJ5MIv6k1ubq6GnxW4Erc5mqYA9Phg6 B X-Received: by 2002:a17:902:104:: with SMTP id 4mr5195869plb.62.1549994239938; Tue, 12 Feb 2019 09:57:19 -0800 (PST) X-Received: by 2002:a17:902:104:: with SMTP id 4mr5195824plb.62.1549994239227; Tue, 12 Feb 2019 09:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549994239; cv=none; d=google.com; s=arc-20160816; b=AQZsOtIGXlC4KjvEBqdE4PqU/WsBggvyoaqVIRJR77TOZiRHZ7hgAqq8hr56o46szi gFBymMS+qLHbe616EhrkV8DVD/a5cTEMiGxvK5ag8jY4LmSTLvDfPeL3rYuPPcFzJKLz pvmcDSE/htViQa0/mNH1u2fhWRzYEeQL9x2ibj1DTOnX4jb+kqHaB2m4efjeZR9gCtOz JLlEezgAhidCnHw6QDgYxBMIGy2CcBRbA+Fex2M9ZUu8fDhgSOi/e0Z32vwQHBluGbft on0byVp595dfl7/o+ynzkIDM3lV180XQhWxKVyKAtI+0y9pcWeMrP02Iv7CiePYofC3a udBA== 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=gKD32Yoy3OQX5/4gri4PxomY3lVn8k0uhfbQMdVmPC8=; b=N3NM2Rt6Khu63cvVqdRW2q9nNoHVKwvIGCOxeD3g32jCcrzU9bU3jffZTIEaTk/HmB 7lUHj7u4aeghl+zWQPJmipH5kTGpFNJYvGV2QbEQ0OYJYcTbVqDNBFWzxUba7rM19hpz cg+p/zj1F8bit6ddwPhIQ/PMH8a43cN5i7lLNXhCeUGwZem4S0kY6M2A4X1fXnqdkiyp A/hSgJIfRqgWHOebHnCHMIKhLKH0GGa0nz/wQNtJBTLLpu1mJDoYQVarpnHZJfdDO78i fNnZVJwoig/kaM/sCrAjo6Vyvx3q29sR9q6r0PV+D78/Cl4RCIYR+kCZNpDhngZLH0iI h1LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lrYOH5Dd; 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 g4sor19501782pgc.74.2019.02.12.09.57.19 for (Google Transport Security); Tue, 12 Feb 2019 09:57:19 -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=lrYOH5Dd; 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=gKD32Yoy3OQX5/4gri4PxomY3lVn8k0uhfbQMdVmPC8=; b=lrYOH5DduVB4SGWITtLwhHB5PkSnt7X1YF/ulNlufQPN10JdBC3JKMtQnvkf5vzP9A YLiuTZoCEu/56JlQngg6SGr+/UVhtpx0a7rvpj98atfRfeSC90uCghKgOA/jrV3byYfR DGprnMtdxx+R7cP3dAL5wPq20Lhz1S40qCx/xiOXW987jnfMQQi1jZIpUKswiA5qxLsN XcBHq4BkH3HQchxPa9HhnAnVtKHnrXLj2zs/a4wdF+cpd6CagMnzw5KWAmZrD5aKtUvE cw33AoTM4HaBgNIVtq6bsALkld1RsUlDXCu2Q1ePr2kSjJGox+I/lilx+murwmqMyiYX aSiQ== X-Google-Smtp-Source: AHgI3IaILzRq1X2DE5NdW31PIJY1d8o4nzOM96VGqUakZek+QPBqTvVl5YHHHJPpQ2A6etEQ4l7PmA== X-Received: by 2002:a65:614a:: with SMTP id o10mr4701974pgv.387.1549994238809; Tue, 12 Feb 2019 09:57:18 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::5:4d62]) by smtp.gmail.com with ESMTPSA id z186sm18608427pfz.119.2019.02.12.09.57.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Feb 2019 09:57:18 -0800 (PST) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: linux-mm@kvack.org Cc: Matthew Wilcox , Johannes Weiner , kernel-team@fb.com, Andrew Morton , linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH v2 3/3] mm: show number of vmalloc pages in /proc/meminfo Date: Tue, 12 Feb 2019 09:56:48 -0800 Message-Id: <20190212175648.28738-4-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212175648.28738-1-guro@fb.com> References: <20190212175648.28738-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 Vmalloc() is getting more and more used these days (kernel stacks, bpf and percpu allocator are new top users), and the total % of memory consumed by vmalloc() can be pretty significant and changes dynamically. /proc/meminfo is the best place to display this information: its top goal is to show top consumers of the memory. Since the VmallocUsed field in /proc/meminfo is not in use for quite a long time (it has been defined to 0 by the commit a5ad88ce8c7f ("mm: get rid of 'vmalloc_info' from /proc/meminfo")), let's reuse it for showing the actual physical memory consumption of vmalloc(). Signed-off-by: Roman Gushchin Cc: Johannes Weiner Cc: Matthew Wilcox --- fs/proc/meminfo.c | 2 +- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 568d90e17c17..465ea0153b2a 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -120,7 +120,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) show_val_kb(m, "Committed_AS: ", committed); seq_printf(m, "VmallocTotal: %8lu kB\n", (unsigned long)VMALLOC_TOTAL >> 10); - show_val_kb(m, "VmallocUsed: ", 0ul); + show_val_kb(m, "VmallocUsed: ", vmalloc_nr_pages()); show_val_kb(m, "VmallocChunk: ", 0ul); show_val_kb(m, "Percpu: ", pcpu_nr_pages()); diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 398e9c95cd61..0b497408272b 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -63,10 +63,12 @@ extern void vm_unmap_aliases(void); #ifdef CONFIG_MMU extern void __init vmalloc_init(void); +extern unsigned long vmalloc_nr_pages(void); #else static inline void vmalloc_init(void) { } +static inline unsigned long vmalloc_nr_pages(void) { return 0; } #endif extern void *vmalloc(unsigned long size); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f1f19d1105c4..8dd490d8d191 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -340,6 +340,19 @@ static unsigned long cached_align; static unsigned long vmap_area_pcpu_hole; +static DEFINE_PER_CPU(unsigned long, nr_vmalloc_pages); + +unsigned long vmalloc_nr_pages(void) +{ + unsigned long pages = 0; + int cpu; + + for_each_possible_cpu(cpu) + pages += per_cpu(nr_vmalloc_pages, cpu); + + return pages; +} + static struct vmap_area *__find_vmap_area(unsigned long addr) { struct rb_node *n = vmap_area_root.rb_node; @@ -1566,6 +1579,7 @@ static void __vunmap(const void *addr, int deallocate_pages) BUG_ON(!page); __free_pages(page, 0); } + this_cpu_sub(nr_vmalloc_pages, area->nr_pages); kvfree(area->pages); } @@ -1742,12 +1756,14 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, if (unlikely(!page)) { /* Successfully allocated i pages, free them in __vunmap() */ area->nr_pages = i; + this_cpu_add(nr_vmalloc_pages, area->nr_pages); goto fail; } area->pages[i] = page; if (gfpflags_allow_blocking(gfp_mask|highmem_mask)) cond_resched(); } + this_cpu_add(nr_vmalloc_pages, area->nr_pages); if (map_vm_area(area, prot, pages)) goto fail;