mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock
@ 2023-07-04 12:03 Miaohe Lin
  2023-07-05  3:10 ` Waiman Long
  2023-07-10 20:26 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Miaohe Lin @ 2023-07-04 12:03 UTC (permalink / raw)
  To: longman, tj, hannes, lizefan.x; +Cc: cgroups, linux-kernel, linmiaohe

cpuset_mutex unlock and lock pair is only needed when transferring tasks
out of empty cpuset. Avoid unneeded cpuset_mutex re-lock when !is_empty
to save cpu cycles.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 kernel/cgroup/cpuset.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 601c40da8e03..e136269c152c 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -3521,17 +3521,16 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
 	is_empty = cpumask_empty(cs->cpus_allowed) ||
 		   nodes_empty(cs->mems_allowed);
 
-	mutex_unlock(&cpuset_mutex);
-
 	/*
 	 * Move tasks to the nearest ancestor with execution resources,
 	 * This is full cgroup operation which will also call back into
 	 * cpuset. Should be done outside any lock.
 	 */
-	if (is_empty)
+	if (is_empty) {
+		mutex_unlock(&cpuset_mutex);
 		remove_tasks_in_empty_cpuset(cs);
-
-	mutex_lock(&cpuset_mutex);
+		mutex_lock(&cpuset_mutex);
+	}
 }
 
 static void
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock
  2023-07-04 12:03 [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock Miaohe Lin
@ 2023-07-05  3:10 ` Waiman Long
  2023-07-10 20:26 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Waiman Long @ 2023-07-05  3:10 UTC (permalink / raw)
  To: Miaohe Lin, tj, hannes, lizefan.x; +Cc: cgroups, linux-kernel

On 7/4/23 08:03, Miaohe Lin wrote:
> cpuset_mutex unlock and lock pair is only needed when transferring tasks
> out of empty cpuset. Avoid unneeded cpuset_mutex re-lock when !is_empty
> to save cpu cycles.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>   kernel/cgroup/cpuset.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 601c40da8e03..e136269c152c 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3521,17 +3521,16 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
>   	is_empty = cpumask_empty(cs->cpus_allowed) ||
>   		   nodes_empty(cs->mems_allowed);
>   
> -	mutex_unlock(&cpuset_mutex);
> -
>   	/*
>   	 * Move tasks to the nearest ancestor with execution resources,
>   	 * This is full cgroup operation which will also call back into
>   	 * cpuset. Should be done outside any lock.
>   	 */
> -	if (is_empty)
> +	if (is_empty) {
> +		mutex_unlock(&cpuset_mutex);
>   		remove_tasks_in_empty_cpuset(cs);
> -
> -	mutex_lock(&cpuset_mutex);
> +		mutex_lock(&cpuset_mutex);
> +	}
>   }
>   
>   static void
Reviewed-by: Waiman Long <longman@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock
  2023-07-04 12:03 [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock Miaohe Lin
  2023-07-05  3:10 ` Waiman Long
@ 2023-07-10 20:26 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2023-07-10 20:26 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: longman, hannes, lizefan.x, cgroups, linux-kernel

On Tue, Jul 04, 2023 at 08:03:52PM +0800, Miaohe Lin wrote:
> cpuset_mutex unlock and lock pair is only needed when transferring tasks
> out of empty cpuset. Avoid unneeded cpuset_mutex re-lock when !is_empty
> to save cpu cycles.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Applied to cgroup/for-6.6.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-10 20:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 12:03 [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock Miaohe Lin
2023-07-05  3:10 ` Waiman Long
2023-07-10 20:26 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®