cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: JP Kobryn <inwardvessel@gmail.com>
Cc: tj@kernel.org, llong@redhat.com, klarasmodin@gmail.com,
	shakeel.butt@linux.dev, yosryahmed@google.com, mkoutny@suse.com,
	hannes@cmpxchg.org, akpm@linux-foundation.org,
	cgroups@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH linus/master] cgroup: adjust criteria for rstat subsystem cpu lock access
Date: Mon, 2 Jun 2025 22:53:17 -0700	[thread overview]
Message-ID: <9eca911e-67f1-46b1-b5a6-df36b1758f60@roeck-us.net> (raw)
In-Reply-To: <20250528235130.200966-1-inwardvessel@gmail.com>

On Wed, May 28, 2025 at 04:51:30PM -0700, JP Kobryn wrote:
> Previously it was found that on uniprocessor machines the size of
> raw_spinlock_t could be zero so a pre-processor conditional was used to
> avoid the allocation of ss->rstat_ss_cpu_lock. The conditional did not take
> into account cases where lock debugging features were enabled. Cover these
> cases along with the original non-smp case by explicitly using the size of
> size of the lock type as criteria for allocation/access where applicable.
> 
> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
> Fixes: 748922dcfabd "cgroup: use subsystem-specific rstat locks to avoid contention"
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202505281034.7ae1668d-lkp@intel.com

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  kernel/cgroup/rstat.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index ce4752ab9e09..cbeaa499a96a 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
> @@ -47,8 +47,20 @@ static spinlock_t *ss_rstat_lock(struct cgroup_subsys *ss)
>  
>  static raw_spinlock_t *ss_rstat_cpu_lock(struct cgroup_subsys *ss, int cpu)
>  {
> -	if (ss)
> +	if (ss) {
> +		/*
> +		 * Depending on config, the subsystem per-cpu lock type may be an
> +		 * empty struct. In enviromnents where this is the case, allocation
> +		 * of this field is not performed in ss_rstat_init(). Avoid a
> +		 * cpu-based offset relative to NULL by returning early. When the
> +		 * lock type is zero in size, the corresponding lock functions are
> +		 * no-ops so passing them NULL is acceptable.
> +		 */
> +		if (sizeof(*ss->rstat_ss_cpu_lock) == 0)
> +			return NULL;
> +
>  		return per_cpu_ptr(ss->rstat_ss_cpu_lock, cpu);
> +	}
>  
>  	return per_cpu_ptr(&rstat_base_cpu_lock, cpu);
>  }
> @@ -510,20 +522,15 @@ int __init ss_rstat_init(struct cgroup_subsys *ss)
>  {
>  	int cpu;
>  
> -#ifdef CONFIG_SMP
>  	/*
> -	 * On uniprocessor machines, arch_spinlock_t is defined as an empty
> -	 * struct. Avoid allocating a size of zero by having this block
> -	 * excluded in this case. It's acceptable to leave the subsystem locks
> -	 * unitialized since the associated lock functions are no-ops in the
> -	 * non-smp case.
> +	 * Depending on config, the subsystem per-cpu lock type may be an empty
> +	 * struct. Avoid allocating a size of zero in this case.
>  	 */
> -	if (ss) {
> +	if (ss && sizeof(*ss->rstat_ss_cpu_lock)) {
>  		ss->rstat_ss_cpu_lock = alloc_percpu(raw_spinlock_t);
>  		if (!ss->rstat_ss_cpu_lock)
>  			return -ENOMEM;
>  	}
> -#endif
>  
>  	spin_lock_init(ss_rstat_lock(ss));
>  	for_each_possible_cpu(cpu)
> -- 
> 2.47.1
> 

      parent reply	other threads:[~2025-06-03  5:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28 23:51 [PATCH linus/master] cgroup: adjust criteria for rstat subsystem cpu lock access JP Kobryn
2025-05-29  0:00 ` Shakeel Butt
2025-05-29  5:23 ` Waiman Long
2025-05-29 15:14   ` JP Kobryn
2025-05-29 16:43     ` Waiman Long
2025-05-30  9:58 ` Michal Koutný
2025-05-31  0:07   ` JP Kobryn
2025-05-31  0:39   ` Tejun Heo
2025-05-31  0:37 ` Tejun Heo
2025-06-03  5:53 ` Guenter Roeck [this message]

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=9eca911e-67f1-46b1-b5a6-df36b1758f60@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=inwardvessel@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=klarasmodin@gmail.com \
    --cc=llong@redhat.com \
    --cc=mkoutny@suse.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).