linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sjpark@amazon.com>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: SeongJae Park <sjpark@amazon.com>, <akpm@linux-foundation.org>,
	"SeongJae Park" <sjpark@amazon.de>, <aarcange@redhat.com>,
	<yang.shi@linux.alibaba.com>, <acme@kernel.org>,
	<alexander.shishkin@linux.intel.com>, <amit@kernel.org>,
	<brendan.d.gregg@gmail.com>, <brendanhiggins@google.com>,
	<cai@lca.pw>, <colin.king@canonical.com>, <corbet@lwn.net>,
	<dwmw@amazon.com>, <jolsa@redhat.com>, <kirill@shutemov.name>,
	<mark.rutland@arm.com>, <mgorman@suse.de>, <minchan@kernel.org>,
	<mingo@redhat.com>, <namhyung@kernel.org>, <peterz@infradead.org>,
	<rdunlap@infradead.org>, <rientjes@google.com>,
	<rostedt@goodmis.org>, <shuah@kernel.org>, <sj38.park@gmail.com>,
	<vbabka@suse.cz>, <vdavydov.dev@gmail.com>, <linux-mm@kvack.org>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: Re: [PATCH v6 01/14] mm: Introduce Data Access MONitor (DAMON)
Date: Tue, 10 Mar 2020 12:50:59 +0100	[thread overview]
Message-ID: <20200310115059.22831-1-sjpark@amazon.com> (raw)
In-Reply-To: <20200310085405.000061af@Huawei.com> (raw)

On Tue, 10 Mar 2020 08:54:05 +0000 Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:

> Apologies if anyone gets these twice. I had an email server throttling
> issue yesterday.
> 
> On Mon, 24 Feb 2020 13:30:34 +0100
> SeongJae Park <sjpark@amazon.com> wrote:
> 
> > From: SeongJae Park <sjpark@amazon.de>
> > 
> > This commit introduces a kernel module named DAMON.  Note that this
> > commit is implementing only the stub for the module load/unload, basic
> > data structures, and simple manipulation functions of the structures to
> > keep the size of commit small.  The core mechanisms of DAMON will be
> > implemented one by one by following commits.
> 
> Interesting piece of work.  I'm reviewing this partly as an exercise in
> understanding it, but I'll point out minor stuff on the basis I might
> as well whilst I'm here. ;)  Note I review bottom up so some comments
> won't make much sense read from the top.

Thanks for review, Jonathan :)  I added reply in line below, but agree to your
whole suggestion.  Will apply those in next spin.

> 
> > 
> > Brief Introduction
> > ==================
> 
> I'd keep this level of intro for the cover letter / docs.  It's not
> particularly useful in commit message it git.

Agreed.

> 
> > 
[...]
> >  
> > +config DAMON
> > +	tristate "Data Access Monitor"
> > +	depends on MMU
> > +	default n
> 
> No need to specify a default of n.

Got it.

> 
> > +	help
> > +	  Provides data access monitoring.
> > +
> > +	  DAMON is a kernel module that allows users to monitor the actual
> > +	  memory access pattern of specific user-space processes.  It aims to
> > +	  be 1) accurate enough to be useful for performance-centric domains,
> > +	  and 2) sufficiently light-weight so that it can be applied online.
> > +
> >  endmenu
[...]
> > +/*
> > + * Construct a damon_region struct
> > + *
> > + * Returns the pointer to the new struct if success, or NULL otherwise
> > + */
> > +static struct damon_region *damon_new_region(struct damon_ctx *ctx,
> > +				unsigned long vm_start, unsigned long vm_end)
> > +{
> > +	struct damon_region *ret;
> 
> I'd give this a different variable name.  Expectation in kernel is often
> that ret is simply an magic handle to be passed on.  Don't normally expect
> to set elements of it.  I'd go long hand and call it region.

Nice point, will change the name to 'region'.

> 
> > +
> > +	ret = kmalloc(sizeof(struct damon_region), GFP_KERNEL);
> 
> sizeof(*ret)

Thanks for catching it!  Will apply to other similar cases.

> 
> > +	if (!ret)
> > +		return NULL;
> 
> blank line.

Good suggestion.

> 
> > +	ret->vm_start = vm_start;
> > +	ret->vm_end = vm_end;
> > +	ret->nr_accesses = 0;
> > +	ret->sampling_addr = damon_rand(ctx, vm_start, vm_end);
> > +	INIT_LIST_HEAD(&ret->list);
> > +
> > +	return ret;
> > +}
> > +
> > +/*
> > + * Add a region between two other regions
> Interestingly even the list.h comments for __list_add call this
> function "insert".   No idea why it isn't simply called that..
> 
> Perhaps damon_insert_region would be clearer and avoid need
> for comment?

I just wanted to make the name consistent with the 'list.h' file, but your
suggestion sounds better.  Will change so.

> 
> > + */
> > +static inline void damon_add_region(struct damon_region *r,
> > +		struct damon_region *prev, struct damon_region *next)
> > +{
> > +	__list_add(&r->list, &prev->list, &next->list);
> > +}
> > +
> > +/*
> > + * Append a region to a task's list of regions
> 
> I'd argue the naming is sufficient that the comment adds little.

Yes, will delete it.

> 
> > + */
> > +static void damon_add_region_tail(struct damon_region *r, struct damon_task *t)
> > +{
> > +	list_add_tail(&r->list, &t->regions_list);
> > +}
> > +
> > +/*
> > + * Delete a region from its list
> 
> The list is an implementation detail. I'd not mention that in the comments.

Nice suggestion.

> 
> > + */
> > +static void damon_del_region(struct damon_region *r)
> > +{
> > +	list_del(&r->list);
> > +}
> > +
> > +/*
> > + * De-allocate a region
> 
> Obvious comment - seem rot risk note below.

Agreed.

> 
> > + */
> > +static void damon_free_region(struct damon_region *r)
> > +{
> > +	kfree(r);
> > +}
> > +
> > +static void damon_destroy_region(struct damon_region *r)
> > +{
> > +	damon_del_region(r);
> > +	damon_free_region(r);
> > +}
> > +
> > +/*
> > + * Construct a damon_task struct
> > + *
> > + * Returns the pointer to the new struct if success, or NULL otherwise
> > + */
> > +static struct damon_task *damon_new_task(unsigned long pid)
> > +{
> > +	struct damon_task *t;
> > +
> > +	t = kmalloc(sizeof(struct damon_task), GFP_KERNEL);
> 
> sizeof(*t) is probably less error prone if this code is maintained
> in the long run.

Good point, will apply to other cases, either.

> 
> > +	if (!t)
> > +		return NULL;
> 
> blank line.

Will add it.

> 
> > +	t->pid = pid;
> > +	INIT_LIST_HEAD(&t->regions_list);
> > +
> > +	return t;
> > +}
> > +
> > +/* Returns n-th damon_region of the given task */
> > +struct damon_region *damon_nth_region_of(struct damon_task *t, unsigned int n)
> > +{
> > +	struct damon_region *r;
> > +	unsigned int i;
> > +
> > +	i = 0;
> 	unsigned int i = 0;

Yes, it must be much better.

> 
> > +	damon_for_each_region(r, t) {
> > +		if (i++ == n)
> > +			return r;
> > +	}
> 
> blank line helps readability a little.

Yes, indeed.

> 
> > +	return NULL;
> > +}
> > +
> > +static void damon_add_task_tail(struct damon_ctx *ctx, struct damon_task *t)
> 
> I'm curious, do we care that it's on the tail?  If not I'd look on that as an
> implementation detail and just call this 
> 
> damon_add_task()

I named it to be consistent with 'damon_add_region[_tail]()' functions, but as
you suggested renaming 'damon_add_region()', it doesn't need to.  Will change
the name.

> 
> > +{
> > +	list_add_tail(&t->list, &ctx->tasks_list);
> > +}
> > +
> > +static void damon_del_task(struct damon_task *t)
> > +{
> > +	list_del(&t->list);
> > +}
> > +
> > +static void damon_free_task(struct damon_task *t)
> > +{
> > +	struct damon_region *r, *next;
> > +
> > +	damon_for_each_region_safe(r, next, t)
> > +		damon_free_region(r);
> > +	kfree(t);
> > +}
> > +
> > +static void damon_destroy_task(struct damon_task *t)
> > +{
> > +	damon_del_task(t);
> > +	damon_free_task(t);
> > +}
> > +
> > +/*
> > + * Returns number of monitoring target tasks
> 
> As below, kind of obvious so just room for rot.

Agreed.

> 
> > + */
> > +static unsigned int nr_damon_tasks(struct damon_ctx *ctx)
> > +{
> > +	struct damon_task *t;
> > +	unsigned int ret = 0;
> > +
> > +	damon_for_each_task(ctx, t)
> > +		ret++;
> > +	return ret;
> > +}
> > +
> > +/*
> > + * Returns the number of target regions for a given target task
> 
> Always a trade off between useful comments and possibility of docs
> rotting.  I'd drop this comment certainly.
> The function name is self explanatory.

Agreed!

> 
> > + */
> > +static unsigned int nr_damon_regions(struct damon_task *t)
> > +{
> > +	struct damon_region *r;
> > +	unsigned int ret = 0;
> > +
> > +	damon_for_each_region(r, t)
> > +		ret++;
> 
> Blank line here would help readability a tiny bit.
> Same in other places where we have something followed by a nice
> simple return statement.

Yes, indeed.

> 
> > +	return ret;
> > +}
> > +
> > +static int __init damon_init(void)
> > +{
> > +	pr_info("init\n");
> 
> Drop these. They are just noise.

Right, it's just noise, will remove.


Thank you again for kind review, Jonathan!


Thanks,
SeongJae Park

> 
> > +
> > +	return 0;
> > +}
> > +
> > +static void __exit damon_exit(void)
> > +{
> > +	pr_info("exit\n");
> > +}
> > +
> > +module_init(damon_init);
> > +module_exit(damon_exit);
> > +
> > +MODULE_LICENSE("GPL");
> > +MODULE_AUTHOR("SeongJae Park <sjpark@amazon.de>");
> > +MODULE_DESCRIPTION("DAMON: Data Access MONitor");
> 


  reply	other threads:[~2020-03-10 11:51 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24 12:30 [PATCH v6 00/14] Introduce Data Access MONitor (DAMON) SeongJae Park
2020-02-24 12:30 ` [PATCH v6 01/14] mm: " SeongJae Park
2020-03-10  8:54   ` Jonathan Cameron
2020-03-10 11:50     ` SeongJae Park [this message]
2020-02-24 12:30 ` [PATCH v6 02/14] mm/damon: Implement region based sampling SeongJae Park
2020-03-10  8:57   ` Jonathan Cameron
2020-03-10 11:52     ` SeongJae Park
2020-03-10 15:55       ` Jonathan Cameron
2020-03-10 16:22         ` SeongJae Park
2020-03-10 17:39           ` Jonathan Cameron
2020-03-12  9:20             ` SeongJae Park
2020-03-13 17:29   ` Jonathan Cameron
2020-03-13 20:16     ` SeongJae Park
2020-03-17 11:32       ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 03/14] mm/damon: Adaptively adjust regions SeongJae Park
2020-03-10  8:57   ` Jonathan Cameron
2020-03-10 11:53     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 04/14] mm/damon: Apply dynamic memory mapping changes SeongJae Park
2020-03-10  9:00   ` Jonathan Cameron
2020-03-10 11:53     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 05/14] mm/damon: Implement callbacks SeongJae Park
2020-03-10  9:01   ` Jonathan Cameron
2020-03-10 11:55     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 06/14] mm/damon: Implement access pattern recording SeongJae Park
2020-03-10  9:01   ` Jonathan Cameron
2020-03-10 11:55     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 07/14] mm/damon: Implement kernel space API SeongJae Park
2020-03-10  9:01   ` Jonathan Cameron
2020-03-10 11:56     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 08/14] mm/damon: Add debugfs interface SeongJae Park
2020-03-10  9:02   ` Jonathan Cameron
2020-03-10 11:56     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 09/14] mm/damon: Add a tracepoint for result writing SeongJae Park
2020-03-10  9:03   ` Jonathan Cameron
2020-03-10 11:57     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 10/14] tools: Add a minimal user-space tool for DAMON SeongJae Park
2020-02-24 12:30 ` [PATCH v6 11/14] Documentation/admin-guide/mm: Add a document " SeongJae Park
2020-03-10  9:03   ` Jonathan Cameron
2020-03-10 11:57     ` SeongJae Park
2020-02-24 12:30 ` [PATCH v6 12/14] mm/damon: Add kunit tests SeongJae Park
2020-02-24 12:30 ` [PATCH v6 13/14] mm/damon: Add user selftests SeongJae Park
2020-02-24 12:30 ` [PATCH v6 14/14] MAINTAINERS: Update for DAMON SeongJae Park
2020-03-02 11:35 ` [PATCH v6 00/14] Introduce Data Access MONitor (DAMON) SeongJae Park
2020-03-09 10:23   ` SeongJae Park
2020-03-10 17:21 ` Shakeel Butt
2020-03-12 10:07   ` SeongJae Park
2020-03-12 10:43     ` SeongJae Park
2020-03-18 19:52       ` Shakeel Butt
2020-03-19  9:03         ` SeongJae Park
2020-03-23 17:29           ` Shakeel Butt
2020-03-24  8:34             ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200310115059.22831-1-sjpark@amazon.com \
    --to=sjpark@amazon.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=aarcange@redhat.com \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=amit@kernel.org \
    --cc=brendan.d.gregg@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=cai@lca.pw \
    --cc=colin.king@canonical.com \
    --cc=corbet@lwn.net \
    --cc=dwmw@amazon.com \
    --cc=jolsa@redhat.com \
    --cc=kirill@shutemov.name \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=mgorman@suse.de \
    --cc=minchan@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=sj38.park@gmail.com \
    --cc=sjpark@amazon.de \
    --cc=vbabka@suse.cz \
    --cc=vdavydov.dev@gmail.com \
    --cc=yang.shi@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).