public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: alexs@kernel.org
Cc: SeongJae Park <sj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] mm/damon: remove damon_lock
Date: Wed, 10 Nov 2021 12:40:34 +0000	[thread overview]
Message-ID: <20211110124034.2574-1-sj@kernel.org> (raw)
In-Reply-To: <20211110114721.133808-1-alexs@kernel.org>

Thank you for this patch, Alex!

On Wed, 10 Nov 2021 19:47:21 +0800 alexs@kernel.org wrote:

> From: Alex Shi <alexs@kernel.org>
> 
> Variable nr_running_ctxs guards by damon_lock, but a lock for a int
> variable seems a bit heavy, a atomic_t is enough.

The lock is not only for protecting nr_running_ctxs, but also for avoiding
different users concurrently executing damon_start(), because that could allow
the users interfering others.

> 
> Signed-off-by: Alex Shi <alexs@kernel.org>
> Cc: SeongJae Park <sj@kernel.org> 
> Cc: Andrew Morton <akpm@linux-foundation.org> 
> Cc: linux-mm@kvack.org 
> Cc: linux-kernel@vger.kernel.org 
> ---
>  include/linux/damon.h |  1 -
>  mm/damon/core.c       | 31 +++++--------------------------
>  mm/damon/dbgfs.c      |  8 +++++---
>  3 files changed, 10 insertions(+), 30 deletions(-)
> 
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index b4d4be3cc987..e5dcc6336ef2 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -453,7 +453,6 @@ int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int,
>  		unsigned long min_nr_reg, unsigned long max_nr_reg);
>  int damon_set_schemes(struct damon_ctx *ctx,
>  			struct damos **schemes, ssize_t nr_schemes);
> -int damon_nr_running_ctxs(void);
>  
>  int damon_start(struct damon_ctx **ctxs, int nr_ctxs);
>  int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index c381b3c525d0..e821e36d5c10 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[...]
> @@ -437,19 +422,15 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs)
>  	int i;
>  	int err = 0;
>  
> -	mutex_lock(&damon_lock);
> -	if (nr_running_ctxs) {
> -		mutex_unlock(&damon_lock);
> +	if (atomic_read(&nr_running_ctxs))
>  		return -EBUSY;
> -	}
>  
>  	for (i = 0; i < nr_ctxs; i++) {
>  		err = __damon_start(ctxs[i]);
>  		if (err)
>  			break;
> -		nr_running_ctxs++;
> +		atomic_inc(&nr_running_ctxs);
>  	}
> -	mutex_unlock(&damon_lock);
>  
>  	return err;
>  }

This would let multiple concurrent threads seeing nr_running_ctxs of zero and
therefore proceed together.


Thanks,
SJ


  reply	other threads:[~2021-11-10 12:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 11:47 [RFC PATCH] mm/damon: remove damon_lock alexs
2021-11-10 12:40 ` SeongJae Park [this message]
2021-11-10 13:41   ` Alex Shi
2021-11-10 14:04     ` Alex Shi
2021-11-10 14:35       ` SeongJae Park
2021-11-10 15:35         ` Alex Shi

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=20211110124034.2574-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexs@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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