From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 961DBC4332E for ; Mon, 23 Mar 2020 12:01:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24AF92072E for ; Mon, 23 Mar 2020 12:01:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PopCAc73" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24AF92072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5D6916B0005; Mon, 23 Mar 2020 08:01:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5867D6B0006; Mon, 23 Mar 2020 08:01:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49B9C6B0007; Mon, 23 Mar 2020 08:01:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 360256B0005 for ; Mon, 23 Mar 2020 08:01:12 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3FD8B180AD81A for ; Mon, 23 Mar 2020 12:01:12 +0000 (UTC) X-FDA: 76626486384.03.honey43_7edaf24f9fd0a X-HE-Tag: honey43_7edaf24f9fd0a X-Filterd-Recvd-Size: 8447 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Mar 2020 12:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584964870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=P+3Ok5a+3t9Z9rUpZF1j8rUoWy/hS/ROQXyPscaiMOE=; b=PopCAc73mk/8bePjo+ob8jezwGBkR1sr0iNt7YmqLzZNrgSopGDGv8qf4Ec/ArY/rGhkV6 iztzS7W6VGrM9j5lBiL7NlpRVQ4EFgEsYyzDqUc9/dbZ5atTH/DqzfRae7+gWQpc3S3jXI UZjMBadMuPhFcpsAYZAqnzUXipbivdE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-vHvO5dqPPBC-nWeANp4hUg-1; Mon, 23 Mar 2020 08:00:59 -0400 X-MC-Unique: vHvO5dqPPBC-nWeANp4hUg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7813E101FC60; Mon, 23 Mar 2020 12:00:56 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C00C194BB; Mon, 23 Mar 2020 12:00:49 +0000 (UTC) Date: Mon, 23 Mar 2020 20:00:44 +0800 From: Dave Young To: Jaewon Kim Cc: 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, linux-api@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jaewon31.kim@gmail.com Subject: Re: [RFC PATCH v2 1/3] meminfo_extra: introduce meminfo extra Message-ID: <20200323120044.GA29433@dhcp-128-65.nay.redhat.com> References: <20200323080503.6224-1-jaewon31.kim@samsung.com> <20200323080503.6224-2-jaewon31.kim@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323080503.6224-2-jaewon31.kim@samsung.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: Hi Jaewon, On 03/23/20 at 05:05pm, Jaewon Kim wrote: > 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; Can this be simplified to use a bytes value without an extra shift? > + char name[NAME_BUF_SIZE]; > + char name_pad[NAME_BUF_SIZE]; > +}; > + There should be document about below function here. > +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); nr_page != nr_kb? > + } > + 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 > > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec > Thanks Dave