From patchwork Wed Dec 19 17:37:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10737829 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 E84DF14DE for ; Wed, 19 Dec 2018 17:38:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDC6D2AD7F for ; Wed, 19 Dec 2018 17:38:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFA8C2B6E4; Wed, 19 Dec 2018 17:38:08 +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 4B2E52AD7F for ; Wed, 19 Dec 2018 17:38:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 642858E0012; Wed, 19 Dec 2018 12:38:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5A4E68E0001; Wed, 19 Dec 2018 12:38:05 -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 3AA508E0012; Wed, 19 Dec 2018 12:38:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by kanga.kvack.org (Postfix) with ESMTP id 0CD0F8E0001 for ; Wed, 19 Dec 2018 12:38:05 -0500 (EST) Received: by mail-it1-f199.google.com with SMTP id p66so7332313itc.0 for ; Wed, 19 Dec 2018 09:38:05 -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=wGPRSNth6iPSKAi8vQAaivAUkebwaHgP+2JHZws28fk=; b=TmxCgaREGVL/uzHMlqnCFtWsdH1Coj2XCkNldz/6lUxguHZQA2YmoABybN3v+m0vZ1 mBVmI+lU2UxubFQtWihuyyzGychMSOWLGWVvVXJ41FudGzJhQ+HmzBsmfQMn17GVdqG9 OuDi7fqbDmiI7zS9tswR8+Y+n25QKl+ub/kEoQDDWCaOdOTsnQ17sOhulvmEB76TuMNk r+gOC8tznhqH7s/7CkjpwEiqn0DjaBX2Eo/FjPC7PEe6PfRPoVhQaLHLxI/WNei2ldwy OQQcjBxlGh7xE3AyiDgL6mnodNWMJAD5BGPF+vFRPat1u52HmRs7zTXhJoJgJBrBDi+X jxHw== X-Gm-Message-State: AA+aEWalsvOPqjqG9NwWEtdaCunxXERu2Jd2jgUY07a2e9lITepNbusH NjOvB91tqUmX7u2QUJJpcKTBOAiQUUx+E3zdM+Mqjva8+eozgFy58qDlPngkJzRRr5ZirK7gey6 5GBwbkKNVMbwYoU2gLpR40BlYyVW9IguXmDcygUzYaO3Uao691pYfSOjp58z7r4bJG94YW38MI3 vsgUgyfKmXbIlNC/uBnzpz18kHNZdc6AMKniirI6r5tZNLuooCJCAIZbaTBfOOgV23IonAKtHZA XpG1DjoM8Xs2J7wvRnzoqHXBRtTQgjgU0HwIpUzBL+2qcJAwb0Se+lS+B1eQzAWVbJEhxc+rLl0 nEpb/9qcvbQ9ZPni/LdEs0nCZAXZD57GyG/hYxAMIcmA5pkluKOz3djyEpIQ7llOPscobDwn6iZ 6 X-Received: by 2002:a24:4242:: with SMTP id i63mr7706925itb.139.1545241084823; Wed, 19 Dec 2018 09:38:04 -0800 (PST) X-Received: by 2002:a24:4242:: with SMTP id i63mr7706873itb.139.1545241083962; Wed, 19 Dec 2018 09:38:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545241083; cv=none; d=google.com; s=arc-20160816; b=rw7a+Gjz1pt/EX/oAdAGgrLn09Kn2j0fcUFzhHGxoHFrtyTm8aZM1reR8JOaKwyrSW /3VWKp2jDiFXeeb0qWWKg9hPR7SGCPTG//f3XT4eljuW98Qexei5wtL7QFnPcOBl2HvD DFcZ2f9M3SFYKWpSA3BcScgwwKLWljJP7BWqY4JmviEEyuh5fceAsAknVcg4MH3NE/H2 1ZhwrOyDMwP69KT2WiqigBJNQv3Xb86STAFZS0nc+pAGM+zLu7+jKob5A4YBsNfN7P+n wrzWRrS3eChZWZeNZA2IbRyeaLqnDLx876DAH+gMaSqhUK5Y1kwfim4SPuhQ9ptpM6ez 9mnA== 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=wGPRSNth6iPSKAi8vQAaivAUkebwaHgP+2JHZws28fk=; b=CRbnwaUmtGQ+Fa02e5zVwgePVdYkKuvONFe7oxkpja7+Dkw3+IgZ98li/La1FDuvx4 8dsCe8G7xAXdEDWdshIAKG8mG1hB2k7Bz7N2ytPJptSJjMcH3egMtnF9hYZ5m0s2CbLO 9uRbANmLV2n9JU0ymJtB0KnZpgV8xGDhYMWOBVmfseunw5lgNcdNGzX5DYoow0TWMbVE mxNav6zJ6ID3dXl52cL6AyDYtGCm+HD0VXlDVEXsYsnS6tzfZCpWSN4g/874HkBlGzrt BO/nwMGXW9gZ9rJUrxeGyhGvI+wdEA+fuWnwvODKkMn9Puqwsq6onSANR3X6iRz8b4MZ Mbkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iRmVSVsZ; 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 h3sor4247055jaa.13.2018.12.19.09.38.03 for (Google Transport Security); Wed, 19 Dec 2018 09:38:03 -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=iRmVSVsZ; 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=wGPRSNth6iPSKAi8vQAaivAUkebwaHgP+2JHZws28fk=; b=iRmVSVsZ98WGq8EZk8v0Fdo8TcqRgGxUJNzUDcty4cMZYeXYDlJggpQ+epKYxN8JTM N6GL6Q5tDXErdfIc/e2Ss9gtNZj6hhsLaFadATQW/lDl6ezqbfWHgM8OeduCGdC4JeGP 69GrF46gXzATbCcLe25dafJYtf9YncdZyOjHNihxmOOFPGd6u1TF5PKJtlXdiJr4PbkX /uRD9mzlYsGWjq0UQBFLk5nG6XIdZyiddf2Nnhgc/nz8P/3ULpKnP0VJDmSw19Ia9Uo9 ytim2irbZMj/EllkJjKfcMY8ghVKK7w0/Ehc4d0i8vPhC+yAvhuJaLxT9Nt9t6XGxE7E lFpg== X-Google-Smtp-Source: AFSGD/Xf0h3jJ4k6s2Zr4NE7SG4Cgf9kLMhBR2J1eZ9j0yX9+WW1xwz1u3Q876n+7BNHKLI+629CHQ== X-Received: by 2002:a02:89a4:: with SMTP id p33mr20680316jaj.0.1545241083388; Wed, 19 Dec 2018 09:38:03 -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.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Dec 2018 09:38:02 -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 3/3] mm: show number of vmalloc pages in /proc/meminfo Date: Wed, 19 Dec 2018 09:37:51 -0800 Message-Id: <20181219173751.28056-4-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 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 --- 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 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 042175d7d95f..efca916940e9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -340,6 +340,13 @@ static unsigned long cached_align; static unsigned long vmap_area_pcpu_hole; +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; @@ -1549,6 +1556,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); } @@ -1717,12 +1725,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;