From patchwork Wed Apr 17 19:40:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10906071 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 3EFAB161F for ; Wed, 17 Apr 2019 19:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AFCC28748 for ; Wed, 17 Apr 2019 19:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F53628763; Wed, 17 Apr 2019 19:40:16 +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 5F54728BA5 for ; Wed, 17 Apr 2019 19:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39CA16B000D; Wed, 17 Apr 2019 15:40:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2D0616B000E; Wed, 17 Apr 2019 15:40:10 -0400 (EDT) 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 126C36B0010; Wed, 17 Apr 2019 15:40:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id CDE1B6B000D for ; Wed, 17 Apr 2019 15:40:09 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id s26so16840576pfm.18 for ; Wed, 17 Apr 2019 12:40:09 -0700 (PDT) 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=Z6vdUIHF/782qrNIQKa8Llo9bmW1C1O8TsdSUUoVzig=; b=csOeR4YOVhGrJeWi9Fwzi1kL9bC81n3m9HkDD6EuQxAI8itmDW8JTQSeZAfJYeiBdF rc9IpBGqBsmTZ2BcRsyApGFpXRCzdo5wg4Pizcoh1WY0UZ7XIJKI/4Y3WUjdZbjDZfER ou6XfmXgNh4U9nYghc70UCCFWy5wOVWEOuPxGrqR/0yj9FUYDoSWEwDGCiEwoN4hIXNM I9B5HnFCnVyyitzsMGotCgimSeTO1UQikXNHRpsMyIGs2vFOD7Os1drOnHf4W0cs5/FA LetzBAXC+kztBD4akffTR3EpWU5w+XDguej2s7PxNeQTchw0ta3uA/+jTPUX82jHq0hv Ni0w== X-Gm-Message-State: APjAAAXClaq2U4Ubz86viMRYpDJ5Re/qKcVbMb4LPcCvtoYNEoDShudW izns+e5i6ZGhMo+21rNUKMYw30lpyQHPVghaDe2k+Je5MF+WNANS4vqL5QK+JYtKPqeG6Pjia/w MaOu3NU27Pxf9Ueuk9MOYzJgFj/01cMqPTQ1HDZHDrDtzMQkbYxmC108XMXP2KYidZQ== X-Received: by 2002:a65:424a:: with SMTP id d10mr6848838pgq.335.1555530009443; Wed, 17 Apr 2019 12:40:09 -0700 (PDT) X-Received: by 2002:a65:424a:: with SMTP id d10mr6848737pgq.335.1555530007940; Wed, 17 Apr 2019 12:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555530007; cv=none; d=google.com; s=arc-20160816; b=dhQ88C0Fn0zcvA2KhAe/iC0di0GMajM/FPjV1YquTdWNTV5SxchoPwnfA5Z+dUOzN2 DBoGbsWrFTT5Q+szUfB10FC1G7Vm473qcJ7n1qkhhcj2tKIIjELY3joN+Il031oDBskk o2pwbQgNra1ia3pQ98MQVA3XORBYS0uUw/K9bICvGTpp4gjuij3ajNauRsnz0M64Jm9C MW7C2NZ5pSn63jwO0HRAioM332YuwSjWJV0efD+uTEmPPKyTo6dwlftgCAyLj0MAoajv MoV1O1tMX2hKxJ3Q1o45UavyyBmkDBJijhtjzVcavrCFz/cVlKS4fuDzzCbJNGun7nvf +1dQ== 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=Z6vdUIHF/782qrNIQKa8Llo9bmW1C1O8TsdSUUoVzig=; b=uvXtX2hUDQ9yzJsMX6HP18rwYb+NfbLbZ+S5Zic2XeRQAF9P6sIqO4s883YdN8n3/m ur3LqDRNuRuJqyd/l8MFvPyxNcWv0WnG2TgFtErYSkQp0xStuW6KbWrKEONzxtm7yb5i pY4oWxDTyySvJqCiof0z+T58Uh2h3IMkhxHeO51P9EwrAiruXqH6Y0G23sdjn1nEFHi8 0JcYeAFueShl2DK6ycLr5VIUvB+tkBkSAgB5ntXcwJgR97+Z5y2a1A3enuTMbCtb7Vrd k6VqXVqHIvQ81RYT4rUnYrESn5xK7N5HuhL6gq+Txk0SyAF9wzQA8cxRUC/CCMf+akDM GKig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WdVKecpy; 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 c18sor45635570pgp.80.2019.04.17.12.40.07 for (Google Transport Security); Wed, 17 Apr 2019 12:40:07 -0700 (PDT) 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=WdVKecpy; 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=Z6vdUIHF/782qrNIQKa8Llo9bmW1C1O8TsdSUUoVzig=; b=WdVKecpyO7Ie1YhwT+DDiMfEArYhv+c23FZBR1ZZd70ocStP2bilaAhEzgH5PB9/BZ BlxxWzlzgpwuCydbw3UXI+z94mGqUByiK9tAfPc02hsJBZcPTcK7cPG4+X0AhFn6+e2r DA5cg6CM6DRt327kyOmtCOdnfveVipyJLp7vB3JrA7xw/gUM9taWoakmImaC4qGk2Qjo 0MiZBuD093wMngItT6yJB2nGGPBLlyZOCDKvJ/69x3rkl1oMbgZiLXh8qw6wZ/XsumCH poCkHC9w4e8MhbhFLcaqIgtxKAV3py9WvcY06aiZR3taH5f6P2S5y25tlfXRiPx7JQZm jbqA== X-Google-Smtp-Source: APXvYqwP8MOTe4Mt0elbbcBNPfAEaBQpvL1f/NDOkCWHcYAqgtbAdomBe640ASx6Nz7a5r3YK6Mv2A== X-Received: by 2002:a63:4847:: with SMTP id x7mr85274293pgk.233.1555530007663; Wed, 17 Apr 2019 12:40:07 -0700 (PDT) Received: from tower.thefacebook.com ([2620:10d:c090:200::3:856]) by smtp.gmail.com with ESMTPSA id v9sm8625949pgf.73.2019.04.17.12.40.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 12:40:06 -0700 (PDT) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Matthew Wilcox , Johannes Weiner , Vlastimil Babka , Roman Gushchin Subject: [PATCH v4 1/2] mm: refactor __vunmap() to avoid duplicated call to find_vm_area() Date: Wed, 17 Apr 2019 12:40:01 -0700 Message-Id: <20190417194002.12369-2-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417194002.12369-1-guro@fb.com> References: <20190417194002.12369-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. Perf report before: 22.64% cat [kernel.vmlinux] [k] free_pcppages_bulk 10.30% cat [kernel.vmlinux] [k] __vunmap 9.80% cat [kernel.vmlinux] [k] find_vmap_area 8.11% cat [kernel.vmlinux] [k] vunmap_page_range 4.20% cat [kernel.vmlinux] [k] __slab_free 3.56% cat [kernel.vmlinux] [k] __list_del_entry_valid 3.46% cat [kernel.vmlinux] [k] smp_call_function_many 3.33% cat [kernel.vmlinux] [k] kfree 3.32% cat [kernel.vmlinux] [k] free_unref_page Perf report after: 23.01% cat [kernel.kallsyms] [k] free_pcppages_bulk 9.46% cat [kernel.kallsyms] [k] __vunmap 9.15% cat [kernel.kallsyms] [k] vunmap_page_range 6.17% cat [kernel.kallsyms] [k] __slab_free 5.61% cat [kernel.kallsyms] [k] kfree 4.86% cat [kernel.kallsyms] [k] bad_range 4.67% cat [kernel.kallsyms] [k] free_unref_page_commit 4.24% cat [kernel.kallsyms] [k] __list_del_entry_valid 3.68% cat [kernel.kallsyms] [k] free_unref_page 3.65% cat [kernel.kallsyms] [k] __list_add_valid 3.19% cat [kernel.kallsyms] [k] __purge_vmap_area_lazy 3.10% cat [kernel.kallsyms] [k] find_vmap_area 3.05% cat [kernel.kallsyms] [k] rcu_cblist_dequeue Signed-off-by: Roman Gushchin Acked-by: Johannes Weiner Reviewed-by: Matthew Wilcox Acked-by: Vlastimil Babka Signed-off-by: Roman Gushchin --- mm/vmalloc.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 92b784d8088c..8ad8e8464e55 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2068,6 +2068,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 @@ -2080,31 +2098,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; @@ -2113,17 +2120,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; @@ -2138,7 +2146,6 @@ static void __vunmap(const void *addr, int deallocate_pages) } kfree(area); - return; } static inline void __vfree_deferred(const void *addr) From patchwork Wed Apr 17 19:40:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10906073 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 0A697161F for ; Wed, 17 Apr 2019 19:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB6AF28495 for ; Wed, 17 Apr 2019 19:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFBBF28BAC; Wed, 17 Apr 2019 19:40:18 +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 BEF9028495 for ; Wed, 17 Apr 2019 19:40:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60BD46B000E; Wed, 17 Apr 2019 15:40:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 592536B0010; Wed, 17 Apr 2019 15:40:11 -0400 (EDT) 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 377416B0266; Wed, 17 Apr 2019 15:40:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id E8E046B000E for ; Wed, 17 Apr 2019 15:40:10 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id x2so15213019pge.16 for ; Wed, 17 Apr 2019 12:40:10 -0700 (PDT) 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=UyR+E+QP9/YBgUof0HLUBtIXg8lauiwUZnv+8kGnwi0=; b=XcbKuH1dlKLyRrY+yl87iR1PrARb1OjY9MuHHBqhcnft6NDAHvkCexsZznbzHBvrUs hogNocp5RWWn55vfhyTJ+F5+puphnzLCw0edSD/MgbUy/eenJMQFJ+jNvjQBgqXKrUGx 0VMRXgFiWv6S+deOLKPCk1NVUj36AD0ZRoXDKDgOXiqWbNTOPxaGa5v+wN3348vRt9uW T9KYqwzF4CJ/Fps91FZL9sRYSBYfB/1JH+UwVDr/s7G7oaAZM9vn+b7/0X8ziMYrDW5F qaqfgybZMjN36LwPWN6Q5U5fQB2bkGQYEu/4qpmvL3lg3hYtXYj7fWS+NL4ygEct91ND kvVg== X-Gm-Message-State: APjAAAXTneTWiXzDACBqpgiIsGaHEzWCcKq5p4sMTQRbErp9UuO30Unk 8siIPqWZM2PFnc8uw4L1xn4vheKA32ft2ehmyuuHuMDOZAEhXkeb0edomQ37X6ETVXbEHOQAUK+ SWPZWdZvGMJ7VH2d0AoauFLHpijUc9UZy9Up/KlAuD/IUXSW+zzpQGomgRHsWXihUoA== X-Received: by 2002:a17:902:848d:: with SMTP id c13mr90658561plo.279.1555530010603; Wed, 17 Apr 2019 12:40:10 -0700 (PDT) X-Received: by 2002:a17:902:848d:: with SMTP id c13mr90658474plo.279.1555530009302; Wed, 17 Apr 2019 12:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555530009; cv=none; d=google.com; s=arc-20160816; b=Mn9tjZhSo5ZTx1qw66wd3N6E3WM+WEg//i5zrsbqXVaZodgGUGIzmOAcp4EBYZ7k5l emBkF3G6IF5DliwU9FVkfrbSE8sG1A3LJpACvdJYWurFG5xSRWD06DlzoHqHBumT6XVw KMH2I+AhST8GxPNfYHO+ZHYVGaDzu9Xz9M4CUa2N814k0GpLely4k69o7BpVVUMwEfpF Z2IfkRs11h/peASAxs7Y0f32R8dYaUU25Xlb1L62hEW+afZH9YreXYzyUgbm4EQF8QEF VwOzrugoDNCcmagI3Vb3SLrMNTgNUnt8A/ghabvnQjtAgBv1jQttOP9UcviVq29N3pZD kUIw== 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=UyR+E+QP9/YBgUof0HLUBtIXg8lauiwUZnv+8kGnwi0=; b=jMfEiKadQhpoUawP+iEPYKGnqlZS+c3Hp/1+qEkiz66gDK8b/Q2nYod5VgJoWrkZb8 KRpMdveroA2GFBfA5ev2Jo6SkVGCXF7FyKLbTy/QqE8W40I8JZ67Eahs+zA/U3nWGkzT 9xtEglR5i9dYMtyqJhLKihLrJHyNsQLC5Bv31RGI74JpbRQKKuyYsZ33itInu+VMO457 o+CFvEfq7DVEqLdZlPjX3IzgbLHueifyYN1CfrQf8rtOIvkMRdlK5kToo6NWhTXSRKDT Y63nWNy9zAwnkzNTjWCGFEJRhuVJqHJIDUXtL7cge+e2HXAVBh0UQUctaRHzeWZzXHRm 4aGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RuXpETwf; 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 62sor44241557pla.43.2019.04.17.12.40.09 for (Google Transport Security); Wed, 17 Apr 2019 12:40:09 -0700 (PDT) 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=RuXpETwf; 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=UyR+E+QP9/YBgUof0HLUBtIXg8lauiwUZnv+8kGnwi0=; b=RuXpETwf6J+1aIICtr0LjFkcyuGTYqyudqgt8yJ0XbVu5l9h3Ww0nVugPD7GI8Rr/O nyHCGDf0oIDjpyXnYFM+rPSnWyp+MJJWqscIXrYy+4hNH36PEN21GXxpa4E29tB8P8O6 JCR9uMaGPtqyYKFHdXpPUYHStJ2s53LHFn1Rfrvxvshx9dwNmkUrr9mK3EQ1NXLeUveS AifpuUIvSYIIj7shDDsB6cHmB9Af2Z/85i6xCMIZQwxBhib8hszXwgSfOFQEv6Jy/lMF 53TCRBDNby1eH9QncyfSnPcZMVoiQEGeq7rxabL9YeEeMYaZhuPLnmM2pBybElmXhPAd uU3A== X-Google-Smtp-Source: APXvYqzML/UNV8wJQff9+LzTiwC5spXfqD2Mqzdl4tmtOaS9M0PSAFTJ3kptuFcifq4SMlxYvWkbug== X-Received: by 2002:a17:902:988e:: with SMTP id s14mr87750846plp.167.1555530009021; Wed, 17 Apr 2019 12:40:09 -0700 (PDT) Received: from tower.thefacebook.com ([2620:10d:c090:200::3:856]) by smtp.gmail.com with ESMTPSA id v9sm8625949pgf.73.2019.04.17.12.40.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 12:40:08 -0700 (PDT) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Matthew Wilcox , Johannes Weiner , Vlastimil Babka , Roman Gushchin Subject: [PATCH v4 2/2] mm: show number of vmalloc pages in /proc/meminfo Date: Wed, 17 Apr 2019 12:40:02 -0700 Message-Id: <20190417194002.12369-3-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417194002.12369-1-guro@fb.com> References: <20190417194002.12369-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 Acked-by: Johannes Weiner Acked-by: Vlastimil Babka --- fs/proc/meminfo.c | 2 +- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 10 ++++++++++ 3 files changed, 13 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 ad483378fdd1..316efa31c8b8 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -67,10 +67,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 8ad8e8464e55..69a5673c4cd3 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -397,6 +397,13 @@ static void purge_vmap_area_lazy(void); static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); static unsigned long lazy_max_pages(void); +static atomic_long_t nr_vmalloc_pages; + +unsigned long vmalloc_nr_pages(void) +{ + return atomic_long_read(&nr_vmalloc_pages); +} + static struct vmap_area *__find_vmap_area(unsigned long addr) { struct rb_node *n = vmap_area_root.rb_node; @@ -2141,6 +2148,7 @@ static void __vunmap(const void *addr, int deallocate_pages) BUG_ON(!page); __free_pages(page, 0); } + atomic_long_sub(area->nr_pages, &nr_vmalloc_pages); kvfree(area->pages); } @@ -2317,12 +2325,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; + atomic_long_add(area->nr_pages, &nr_vmalloc_pages); goto fail; } area->pages[i] = page; if (gfpflags_allow_blocking(gfp_mask|highmem_mask)) cond_resched(); } + atomic_long_add(area->nr_pages, &nr_vmalloc_pages); if (map_vm_area(area, prot, pages)) goto fail;