public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <onestero-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: "Christian Brauner"
	<brauner-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Michal Koutný" <mkoutny-IBi9RG/b67k@public.gmane.org>,
	"Peter Zijlstra" <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	"John Stultz"
	<john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	"Dmitry Shmidt"
	<dimitrysh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH RESEND 3/3 cgroup/for-5.20] cgroup: Make !percpu threadgroup_rwsem operations optional
Date: Mon, 25 Jul 2022 14:12:09 +0200	[thread overview]
Message-ID: <20220725121208.GB28662@redhat.com> (raw)
In-Reply-To: <YtwFjPnCtw8ySnuv-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>

On 07/23, Tejun Heo wrote:
>
> +void cgroup_favor_dynmods(struct cgroup_root *root, bool favor)
> +{
> +	bool favoring = root->flags & CGRP_ROOT_FAVOR_DYNMODS;
> +
> +	/* see the comment above CGRP_ROOT_FAVOR_DYNMODS definition */
> +	if (favor && !favoring) {
> +		rcu_sync_enter(&cgroup_threadgroup_rwsem.rss);
> +		root->flags |= CGRP_ROOT_FAVOR_DYNMODS;
> +	} else if (!favor && favoring) {
> +		rcu_sync_exit(&cgroup_threadgroup_rwsem.rss);
> +		root->flags &= ~CGRP_ROOT_FAVOR_DYNMODS;
> +	}
> +}

I see no problems in this patch. But just for record, we do not need
synchronize_rcu() in the "favor && !favoring" case, so we cab probably
do something like

	--- a/kernel/rcu/sync.c
	+++ b/kernel/rcu/sync.c
	@@ -118,7 +118,7 @@ static void rcu_sync_func(struct rcu_head *rhp)
	  * optimize away the grace-period wait via a state machine implemented
	  * by rcu_sync_enter(), rcu_sync_exit(), and rcu_sync_func().
	  */
	-void rcu_sync_enter(struct rcu_sync *rsp)
	+void __rcu_sync_enter(struct rcu_sync *rsp, bool wait)
	 {
		int gp_state;
	 
	@@ -146,13 +146,20 @@ void rcu_sync_enter(struct rcu_sync *rsp)
			 * See the comment above, this simply does the "synchronous"
			 * call_rcu(rcu_sync_func) which does GP_ENTER -> GP_PASSED.
			 */
	-		synchronize_rcu();
	-		rcu_sync_func(&rsp->cb_head);
	-		/* Not really needed, wait_event() would see GP_PASSED. */
	-		return;
	+		if (wait) {
	+			synchronize_rcu();
	+			rcu_sync_func(&rsp->cb_head);
	+		} else {
	+			rcu_sync_call(rsp);
	+		}
	+	} else if (wait) {
	+		wait_event(rsp->gp_wait, READ_ONCE(rsp->gp_state) >= GP_PASSED);
		}
	+}
	 
	-	wait_event(rsp->gp_wait, READ_ONCE(rsp->gp_state) >= GP_PASSED);
	+void rcu_sync_enter(struct rcu_sync *rsp)
	+{
	+	__rcu_sync_enter(rsp, true);
	 }
	 
	 /**

later.

__rcu_sync_enter(rsp, false) works just like rcu_sync_enter_start() but it can
be safely called at any moment.

And can't resist, off-topic question... Say, cgroup_attach_task_all() does

	mutex_lock(&cgroup_mutex);
	percpu_down_write(&cgroup_threadgroup_rwsem);

and this means that synchronize_rcu() can be called with cgroup_mutex held.
Perhaps it makes sense to change this code to do

	rcu_sync_enter(&cgroup_threadgroup_rwsem.rss);
	mutex_lock(&cgroup_mutex);
	percpu_down_write(&cgroup_threadgroup_rwsem);
	...
	percpu_up_write(&cgroup_threadgroup_rwsem);
	mutex_unlock(&cgroup_mutex);
	rcu_sync_exit(&cgroup_threadgroup_rwsem.rss);

? Just curious.

> -	/*
> -	 * The latency of the synchronize_rcu() is too high for cgroups,
> -	 * avoid it at the cost of forcing all readers into the slow path.
> -	 */
> -	rcu_sync_enter_start(&cgroup_threadgroup_rwsem.rss);

Note that it doesn't have other users, probably you can kill it.

Oleg.


  parent reply	other threads:[~2022-07-25 12:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-15  4:38 [PATCH 1/3 cgroup/for-5.20] cgroup: Elide write-locking threadgroup_rwsem when updating csses on an empty subtree Tejun Heo
     [not found] ` <YtDvN0wJ6CKaEPN8-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-07-15  4:38   ` [PATCH 2/3 cgroup/for-5.20] cgroup: Add "no" prefixed mount options Tejun Heo
     [not found]     ` <YtDvU4jRPSsarcNp-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-07-15  4:39       ` [PATCH 3/3 cgroup/for-5.20] cgroup: Make !percpu threadgroup_rwsem operations optional Tejun Heo
2022-07-23  5:12         ` Tejun Heo
2022-07-23 14:28         ` [PATCH RESEND " Tejun Heo
     [not found]           ` <YtwFjPnCtw8ySnuv-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-07-25 12:12             ` Oleg Nesterov [this message]
     [not found]               ` <20220725121208.GB28662-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-07-26 23:14                 ` Tejun Heo
2022-07-27 17:39                   ` Oleg Nesterov
2022-07-25 14:16             ` Christian Brauner
2022-07-26 14:32           ` Michal Koutný
     [not found]             ` <20220726143257.GA23882-9OudH3eul5jcvrawFnH+a6VXKuFTiq87@public.gmane.org>
2022-07-26 17:33               ` Tejun Heo
2022-07-26 14:32       ` [PATCH 2/3 cgroup/for-5.20] cgroup: Add "no" prefixed mount options Michal Koutný
     [not found]         ` <20220726143246.GA23794-9OudH3eul5jcvrawFnH+a6VXKuFTiq87@public.gmane.org>
2022-07-26 20:01           ` Tejun Heo
2022-07-26 23:30             ` Tejun Heo
     [not found]               ` <YuB5ICv3bXsy5Xuh-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-07-26 23:48                 ` [PATCH cgroup/for-5.20] cgroup: remove "no" prefixed mount options options Tejun Heo
     [not found]                   ` <YuB9QXapVUy1t8TZ-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-07-27  9:27                     ` Michal Koutný
     [not found]                       ` <20220727092715.GA1569-9OudH3eul5jcvrawFnH+a6VXKuFTiq87@public.gmane.org>
2022-07-27 17:55                         ` Tejun Heo
2022-07-26 14:31   ` [PATCH 1/3 cgroup/for-5.20] cgroup: Elide write-locking threadgroup_rwsem when updating csses on an empty subtree Michal Koutný

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=20220725121208.GB28662@redhat.com \
    --to=onestero-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=brauner-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dimitrysh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mkoutny-IBi9RG/b67k@public.gmane.org \
    --cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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