Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3454806ybb; Mon, 23 Mar 2020 01:07:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuDRUvl6w97gIgikBC0l8saHJ0zgUzNPXRfa0m/Pg6RW1Er02BeuISAAqZbYy+RkyQWd7Cw X-Received: by 2002:a54:4001:: with SMTP id x1mr16694998oie.67.1584950847938; Mon, 23 Mar 2020 01:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584950847; cv=none; d=google.com; s=arc-20160816; b=qOkjhaUlYRJvV/0RGrjLvrB59SnkLaay7iW/zJKMB8q2eeEC5Jb7QBtgnSMEWcLmzi 1wHKBrNcduYF2F4kXUMCpr8Y8XuJoq5Ky9n36n0UUw4HOd3u6WwtzK2LUJpLbQkZD08D xeF4rwya8fI1UUMXoF9nAz4fFP4O6zthWG8q62owdvy0m959C5M1eUj/GCbbDBhjiRs3 j+b2DTJgDjGE00e/Wf6htlqU5pB/dnZ1yPcu+rFmALSH6NhaSOmlDt2nbVVRifNMGh1o KAAtkHk0jOrBSFpfKpP8m6L5cQ07KJ9dYP7PZ0/idbL/SjCDBp32eliy5FV0Kf1HHRQT dWmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=TRbGcx9ZV+IqrIG8JwLR8QmselJK4B5I11L2jHQXF2Y=; b=a+WAG8KmLAQV5zrI3jUwu25JqNR1FKmj73+9rJWtI7t2x7FXBj4Ph2Hprhja/ZAcfD ow8W77rxCtpR3s9tnaaPEZ1Kutbt6RTsJLGse4KoI4yoOL0E8qO5m+Cc4cMgFIEQk5ml HkJz65f0Kq/+dzrxzB1qL6QNkjwwJ7js+ykpxxwiKsR/sPcIgOFNWVb9/UvspfkNOr8c 38eKyQSHtwY4CHmcSnpmQsFSIPZxzW5bocW1S51Hv7P66vd8uI5Ee5CE9rXnOMfpvK0M gHuP3OBM4DuJm95octAexO73TboWPmHEkyUXhPwjAZYSKt8k+5fgdKgRSPKKylX/Aj55 8OSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=lkPTNkKW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r23si7393647otq.255.2020.03.23.01.07.15; Mon, 23 Mar 2020 01:07:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=lkPTNkKW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbgCWIFS (ORCPT + 99 others); Mon, 23 Mar 2020 04:05:18 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:34883 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727493AbgCWIFP (ORCPT ); Mon, 23 Mar 2020 04:05:15 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20200323080511epoutp041535d6510d23be4f5111459eac6f77b1~_4EZt-NXz1425514255epoutp04v for ; Mon, 23 Mar 2020 08:05:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20200323080511epoutp041535d6510d23be4f5111459eac6f77b1~_4EZt-NXz1425514255epoutp04v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584950712; bh=TRbGcx9ZV+IqrIG8JwLR8QmselJK4B5I11L2jHQXF2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkPTNkKW34Nr83/BA5jeRhsaATENKf7iFNm1BaH+7DxMD2SCaGXKPIHvhiQJpQO+H o/OZNqqvR7HMGcGYOuu3OyOWBpZpUGaP1MKAhWR52iEnogSbxSXHPN47Urcj5OGYd+ 1xCKW0y37hWvKjCQci8RgDufF48soNuViO4xMVys= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20200323080511epcas1p2d7cdcc4edcce296e22135a322e7c704b~_4EZI67xg2102421024epcas1p2l; Mon, 23 Mar 2020 08:05:11 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.40.164]) by epsnrtp4.localdomain (Postfix) with ESMTP id 48m6PL2KbPzMqYkd; Mon, 23 Mar 2020 08:05:10 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 95.2A.04074.4BD687E5; Mon, 23 Mar 2020 17:05:08 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20200323080508epcas1p387c9c19b480da53be40fe5d51e76a477~_4EWBfKY43019030190epcas1p3C; Mon, 23 Mar 2020 08:05:08 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200323080507epsmtrp18e52c71f3a54794974a1c99e59279abe~_4EWAYGbR0063700637epsmtrp1e; Mon, 23 Mar 2020 08:05:07 +0000 (GMT) X-AuditID: b6c32a39-58bff70000000fea-59-5e786db4b413 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 67.15.04158.3BD687E5; Mon, 23 Mar 2020 17:05:07 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.104.82]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200323080507epsmtip15ad9b6907ccc4b094399b05cc333e9db~_4EVz4Cu80126401264epsmtip1M; Mon, 23 Mar 2020 08:05:07 +0000 (GMT) From: Jaewon Kim To: gregkh@linuxfoundation.org, leon@kernel.org, vbabka@suse.cz, adobriyan@gmail.com, akpm@linux-foundation.org, labbott@redhat.com, sumit.semwal@linaro.org, minchan@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, kasong@redhat.com, bhe@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, linux-api@vger.kernel.org, kexec@lists.infradead.org, Jaewon Kim Subject: [RFC PATCH v2 1/3] meminfo_extra: introduce meminfo extra Date: Mon, 23 Mar 2020 17:05:01 +0900 Message-Id: <20200323080503.6224-2-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200323080503.6224-1-jaewon31.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA02Tf0xTVxTHd9/re6+Y1rxU507QIL5EJi5ASy1eN7roZpY3xjIWEk32B+wF bihZf7z0FaUkGyCEKAhUonEiGATFDXGQtnEgCEuBsc3FLhB/xhK3bCZzExIM4srUtX0a99/3 nPP55px77r1a2jDBJmvLnR7idkp2gV2luTiRnpERdFQWGX2P0/Dx2jzcMdDP4vDdKIvregZY 3BQ4gXDzwn0Kn5u/gvDIlSUKfz36mMJHo2dpHFg+yOLZSx0snut/xuDepQUOD9a3c/g3XxuF f4o85PDJ2ha00yAOt0c40d93iBX9i22ceOf6KCv+8OWKRhzv7OfEwJlqcWHsGiu2BPuQ+HPX JCcOLwYY8aE/pUD3iT3XRqRS4k4lzhJXabmzzCp8UFj8brElx2jKMO3A24VUp+QgVm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gSvj7bw2xoJJGhVH93g1MC5W7GLk5JAQMJGYvukbcxcjF4eQwG5GibOLvzNDJGQk3px/ytLF yAFkC0scPlwMUfOVUWLnywVgNWwC2hLvF0xiBbFFBOYzSfS384MUMQtsZpSYuLSZBSQhLOAk MeX4YiYQm0VAVeLm6gmMIDavgI3E7iP3oBbISyz8DzaTU8BWYt+lW2wgthBQydbuZ8wTGPkW MDKsYpRMLSjOTc8tNiwwykst1ytOzC0uzUvXS87P3cQIjhEtrR2MJ07EH2IU4GBU4uG90Vse J8SaWFZcmXuIUYKDWUmEd3NqRZwQb0piZVVqUX58UWlOavEhRmkOFiVxXvn8Y5FCAumJJanZ qakFqUUwWSYOTqkGRqZv3/ZucD51/AabsuIKsz+K8/o4tPaoi8y689E7Tf7hdMnd6qJJby6v lZf75Vjv+fJq974tJjUpTsbT3yzO2he+jl84IXTRrFXzPvxwjbjEeCVsgbfw2/0TFd8XuJw2 ncjENH2VdF3fR/ELdivEdu7Z8CMsnkHjSPTPIq0XMxbob3nk2/KIS1qJpTgj0VCLuag4EQC6 tjChjQIAAA== X-CMS-MailID: 20200323080508epcas1p387c9c19b480da53be40fe5d51e76a477 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200323080508epcas1p387c9c19b480da53be40fe5d51e76a477 References: <20200323080503.6224-1-jaewon31.kim@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide APIs to drivers so that they can show its memory usage on /proc/meminfo_extra. int register_meminfo_extra(atomic_long_t *val, int shift, const char *name); int unregister_meminfo_extra(atomic_long_t *val); Signed-off-by: Jaewon Kim --- v2: move to /proc/meminfo_extra as a new file, meminfo_extra.c use rcu to reduce lock overhead v1: print info at /proc/meminfo --- fs/proc/Makefile | 1 + fs/proc/meminfo_extra.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 4 ++ mm/page_alloc.c | 1 + 4 files changed, 129 insertions(+) create mode 100644 fs/proc/meminfo_extra.c diff --git a/fs/proc/Makefile b/fs/proc/Makefile index bd08616ed8ba..83d2f55591c6 100644 --- a/fs/proc/Makefile +++ b/fs/proc/Makefile @@ -19,6 +19,7 @@ proc-y += devices.o proc-y += interrupts.o proc-y += loadavg.o proc-y += meminfo.o +proc-y += meminfo_extra.o proc-y += stat.o proc-y += uptime.o proc-y += util.o diff --git a/fs/proc/meminfo_extra.c b/fs/proc/meminfo_extra.c new file mode 100644 index 000000000000..bd3f0d2b7fb7 --- /dev/null +++ b/fs/proc/meminfo_extra.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +static void show_val_kb(struct seq_file *m, const char *s, unsigned long num) +{ + seq_put_decimal_ull_width(m, s, num << (PAGE_SHIFT - 10), 8); + seq_write(m, " kB\n", 4); +} + +static LIST_HEAD(meminfo_head); +static DEFINE_SPINLOCK(meminfo_lock); + +#define NAME_SIZE 15 +#define NAME_BUF_SIZE (NAME_SIZE + 2) /* ':' and '\0' */ + +struct meminfo_extra { + struct list_head list; + atomic_long_t *val; + int shift_for_page; + char name[NAME_BUF_SIZE]; + char name_pad[NAME_BUF_SIZE]; +}; + +int register_meminfo_extra(atomic_long_t *val, int shift, const char *name) +{ + struct meminfo_extra *meminfo, *memtemp; + int len; + int error = 0; + + meminfo = kzalloc(sizeof(*meminfo), GFP_KERNEL); + if (!meminfo) { + error = -ENOMEM; + goto out; + } + + meminfo->val = val; + meminfo->shift_for_page = shift; + strncpy(meminfo->name, name, NAME_SIZE); + len = strlen(meminfo->name); + meminfo->name[len] = ':'; + strncpy(meminfo->name_pad, meminfo->name, NAME_BUF_SIZE); + while (++len < NAME_BUF_SIZE - 1) + meminfo->name_pad[len] = ' '; + + spin_lock(&meminfo_lock); + list_for_each_entry_rcu(memtemp, &meminfo_head, list) { + if (memtemp->val == val) { + error = -EINVAL; + break; + } + } + if (!error) + list_add_tail_rcu(&meminfo->list, &meminfo_head); + spin_unlock(&meminfo_lock); + if (error) + kfree(meminfo); +out: + + return error; +} +EXPORT_SYMBOL(register_meminfo_extra); + +int unregister_meminfo_extra(atomic_long_t *val) +{ + struct meminfo_extra *memtemp; + int error = -EINVAL; + + spin_lock(&meminfo_lock); + list_for_each_entry_rcu(memtemp, &meminfo_head, list) { + if (memtemp->val == val) { + list_del_rcu(&memtemp->list); + error = 0; + break; + } + } + spin_unlock(&meminfo_lock); + if (!error) { + synchronize_rcu(); + kfree(memtemp); + } + + return error; +} +EXPORT_SYMBOL(unregister_meminfo_extra); + +static void __meminfo_extra(struct seq_file *m) +{ + struct meminfo_extra *memtemp; + unsigned long nr_page; + + rcu_read_lock(); + list_for_each_entry_rcu(memtemp, &meminfo_head, list) { + nr_page = (unsigned long)atomic_long_read(memtemp->val); + nr_page = nr_page >> memtemp->shift_for_page; + if (m) + show_val_kb(m, memtemp->name_pad, nr_page); + else + pr_cont("%s%lukB ", memtemp->name, nr_page); + } + rcu_read_unlock(); +} + +void show_meminfo_extra(void) +{ + __meminfo_extra(NULL); +} + +static int meminfo_extra_proc_show(struct seq_file *m, void *v) +{ + __meminfo_extra(m); + + return 0; +} + +static int __init proc_meminfo_extra_init(void) +{ + proc_create_single("meminfo_extra", 0, NULL, meminfo_extra_proc_show); + return 0; +} +fs_initcall(proc_meminfo_extra_init); diff --git a/include/linux/mm.h b/include/linux/mm.h index 52269e56c514..55317161ab57 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2898,6 +2898,10 @@ void __init setup_nr_node_ids(void); static inline void setup_nr_node_ids(void) {} #endif +void show_meminfo_extra(void); +int register_meminfo_extra(atomic_long_t *val, int shift, const char *name); +int unregister_meminfo_extra(atomic_long_t *val); + extern int memcmp_pages(struct page *page1, struct page *page2); static inline int pages_identical(struct page *page1, struct page *page2) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3c4eb750a199..db1be9a39783 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5229,6 +5229,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) struct zone *zone; pg_data_t *pgdat; + show_meminfo_extra(); for_each_populated_zone(zone) { if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask)) continue; -- 2.13.7