Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3531751ybb; Mon, 23 Mar 2020 02:54:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsKOJ2ZjbU3cuNpO2lxXBqZLstV6kbnUapLMQ0bRmNxTEzMP/0mrRk8hRFCv2juWfdlPVMx X-Received: by 2002:aca:4986:: with SMTP id w128mr15798875oia.46.1584957274784; Mon, 23 Mar 2020 02:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584957274; cv=none; d=google.com; s=arc-20160816; b=V09XFHepqHuFqbejrtyHb+vcEdR/OfXM0ZMQAoHMBDXJ87zoU4pqHVmimafBpy0WrJ /nCqfuvuo2On+OD17JlqA/8j439KWW+dqNyU3oO7H7Olrx107qlrOOPwlgO29fgFsy8J soBKIsN8vGcrg+5JCbSh5MynFucA1fktCXAbv3phuCtKJWhUqDzVaUUaVLOybWfnzLAj fYhkh+AR+eE0oGVG3C81nW6pTQlYreewgeAUdtYNNycN2eHZUhGH5tt7m2vhnMCYyIsr jFaF6zFJ+wwW9Oq2xkC+UdHchMJFJpheFa/OYreeefQIC+2CQcj8k7myOGS5upcVqOTq hwwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=UOdg5KCdxvB+j9xArpIUUUZz4KsmXBZxyCc4Z7+QCuc=; b=XSqzdXYHauyr9cmnvhlSGaZmYtia7pLQxUP2MS8W0ftkvyUoV6By1sifHAX3nGffT5 +hElLHKl9safmAWJQKq1jyB9yWLZZ+4BZeMESSQ/n+5+oL5j+HR1l7U/LW2MAxYdQvs0 enlU86Onj3GINJB7wcOVV4gXEvkdClgC9hDKIDDDC5T2troNslfmU/e+utM/SL+6d4lz k46rOI+KkcwlFmjcMTXnV/c0BT7J7DFVwPsRYNnua2oWLUHnY3KvWHN5SvvOG1z3Tqgx vNmY+IOyb+vDKvyX1BoRmVuTEZa/A3UgWheoP2SVQCf0YwOLkPyl5cih832ZWvU5Lcx7 6J5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yWjYuu7k; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n82si6726746oib.123.2020.03.23.02.54.21; Mon, 23 Mar 2020 02:54:34 -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=@kernel.org header.s=default header.b=yWjYuu7k; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbgCWJxs (ORCPT + 99 others); Mon, 23 Mar 2020 05:53:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:56184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727737AbgCWJxs (ORCPT ); Mon, 23 Mar 2020 05:53:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B5CDF2072D; Mon, 23 Mar 2020 09:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584957227; bh=vYQRdibAHre6Z0ZRM2+BRlR2nFJ0LeQHPRN+LvLMVBQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=yWjYuu7kvYMl56D+Y8BuUPq3QPFiMCKuoOxVlWQhwAM+Wm8idPdIVqevNxw69uAAk ovtTcEbcF8rxF1O0XGhGCwlQyvi72gjTGLHWblk502xAlVEL1Pik4+Qi5JPX9hQqV2 2pOn7t/JqTJs1YpmmO9wrZEG1pWDWllk+Oa0PCDY= Date: Mon, 23 Mar 2020 10:53:44 +0100 From: Greg KH To: Jaewon Kim Cc: 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-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, linux-api@vger.kernel.org, kexec@lists.infradead.org Subject: Re: [RFC PATCH v2 1/3] meminfo_extra: introduce meminfo extra Message-ID: <20200323095344.GB425358@kroah.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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 05:05:01PM +0900, 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); Nit, isn't it nicer to have the subsystem name first: meminfo_extra_register() meminfo_extra_unregister() ? > > 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 you have a lock, why are you needing rcu? > + if (error) > + kfree(meminfo); > +out: > + > + return error; > +} > +EXPORT_SYMBOL(register_meminfo_extra); EXPORT_SYMBOL_GPL()? I have to ask :) thanks, greg k-h