linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Jesper Dangaard Brouer <hawk@kernel.org>,
	tj@kernel.org, cgroups@vger.kernel.org, yosryahmed@google.com,
	shakeel.butt@linux.dev
Cc: hannes@cmpxchg.org, lizefan.x@bytedance.com,
	kernel-team@cloudflare.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V4 1/2] cgroup/rstat: Helper functions for locking expose trylock
Date: Thu, 27 Jun 2024 18:22:31 -0400	[thread overview]
Message-ID: <08062501-f3fb-4e4d-b72c-f1b0f964640f@redhat.com> (raw)
In-Reply-To: <171952310959.1810550.17003659816794335660.stgit@firesoul>


On 6/27/24 17:18, Jesper Dangaard Brouer wrote:
> Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
> ---
>   kernel/cgroup/rstat.c |   40 ++++++++++++++++++++++++++++++----------
>   1 file changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index fb8b49437573..2a42be3a9bb3 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
> @@ -279,17 +279,30 @@ __bpf_hook_end();
>    * value -1 is used when obtaining the main lock else this is the CPU
>    * number processed last.
>    */
> -static inline void __cgroup_rstat_lock(struct cgroup *cgrp, int cpu_in_loop)
> +static inline bool __cgroup_rstat_trylock(struct cgroup *cgrp, int cpu_in_loop)
> +{
> +	bool locked;
> +
> +	locked = spin_trylock_irq(&cgroup_rstat_lock);
> +	if (!locked)
> +		trace_cgroup_rstat_lock_contended(cgrp, cpu_in_loop, !locked);
> +
> +	return locked;
> +}
> +
> +static inline void __cgroup_rstat_lock(struct cgroup *cgrp, int cpu_in_loop,
> +				       bool check_contention)
>   	__acquires(&cgroup_rstat_lock)
>   {
> -	bool contended;
> +	bool locked = false;
>   
> -	contended = !spin_trylock_irq(&cgroup_rstat_lock);
> -	if (contended) {
> -		trace_cgroup_rstat_lock_contended(cgrp, cpu_in_loop, contended);
> +	if (check_contention)
> +		locked = __cgroup_rstat_trylock(cgrp, cpu_in_loop);
> +
> +	if (!locked)
>   		spin_lock_irq(&cgroup_rstat_lock);
> -	}
> -	trace_cgroup_rstat_locked(cgrp, cpu_in_loop, contended);
> +
> +	trace_cgroup_rstat_locked(cgrp, cpu_in_loop, !locked);
>   }
>   
>   static inline void __cgroup_rstat_unlock(struct cgroup *cgrp, int cpu_in_loop)
> @@ -328,7 +341,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
>   			__cgroup_rstat_unlock(cgrp, cpu);
>   			if (!cond_resched())
>   				cpu_relax();
> -			__cgroup_rstat_lock(cgrp, cpu);
> +			__cgroup_rstat_lock(cgrp, cpu, true);
>   		}
>   	}
>   }
> @@ -348,9 +361,16 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
>    */
>   __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp)
>   {
> +	bool locked;
> +
>   	might_sleep();
>   
> -	__cgroup_rstat_lock(cgrp, -1);
> +	locked = __cgroup_rstat_trylock(cgrp, -1);
> +	if (!locked) {
> +		/* Opportunity to ongoing flush detection */
> +		__cgroup_rstat_lock(cgrp, -1, false);
> +	}
> +
>   	cgroup_rstat_flush_locked(cgrp);
>   	__cgroup_rstat_unlock(cgrp, -1);
>   }
> @@ -368,7 +388,7 @@ void cgroup_rstat_flush_hold(struct cgroup *cgrp)
>   	__acquires(&cgroup_rstat_lock)
>   {
>   	might_sleep();
> -	__cgroup_rstat_lock(cgrp, -1);
> +	__cgroup_rstat_lock(cgrp, -1, true);
>   	cgroup_rstat_flush_locked(cgrp);
>   }
>   
>
>
Will it be cleaner to add a "bool *flushed" output parameter to 
__cgroup_rstat_lock() so that the caller can respond differently whether 
the flushed flag is set or not? In that way, you don't need to expose a 
separate trylock() API. Also your commit log is empty.

Cheers,
Longman



  parent reply	other threads:[~2024-06-27 22:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27 21:18 [PATCH V4 1/2] cgroup/rstat: Helper functions for locking expose trylock Jesper Dangaard Brouer
2024-06-27 21:18 ` [PATCH V4 2/2] cgroup/rstat: Avoid thundering herd problem by kswapd across NUMA nodes Jesper Dangaard Brouer
2024-06-27 23:34   ` Shakeel Butt
2024-06-28  9:39     ` Jesper Dangaard Brouer
2024-06-28 22:15       ` Yosry Ahmed
2024-07-02 10:35         ` Jesper Dangaard Brouer
2024-07-02 12:00           ` Yosry Ahmed
2024-07-08 15:26       ` Jesper Dangaard Brouer
2024-07-16 21:54         ` Yosry Ahmed
2024-07-17  7:46           ` Jesper Dangaard Brouer
2024-07-17 16:04             ` Yosry Ahmed
2024-06-27 22:22 ` Waiman Long [this message]
2024-06-28  1:06   ` [PATCH V4 1/2] cgroup/rstat: Helper functions for locking expose trylock Waiman Long
2024-06-28 12:13   ` Jesper Dangaard Brouer

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=08062501-f3fb-4e4d-b72c-f1b0f964640f@redhat.com \
    --to=longman@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hawk@kernel.org \
    --cc=kernel-team@cloudflare.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizefan.x@bytedance.com \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    --cc=yosryahmed@google.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).