public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check
@ 2023-12-05 22:21 Waiman Long
  2023-12-06 10:55 ` Bagas Sanjaya
  2023-12-06 19:38 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Waiman Long @ 2023-12-05 22:21 UTC (permalink / raw)
  To: Tejun Heo, Zefan Li, Johannes Weiner, Andrew Morton, Michal Hocko,
	Frederic Weisbecker
  Cc: cgroups, linux-kernel, Mrunal Patel, Ryan Phillips, Brent Rowsell,
	Peter Hunt, Cestmir Kalina, Waiman Long

Currently, the cpu_is_isolated() function checks only the statically
isolated CPUs specified via the "isolcpus" and "nohz_full" kernel
command line options. This function is used by vmstat and memcg to
reduce interference with isolated CPUs by not doing stat flushing
or scheduling works on those CPUs.

Workloads running on isolated CPUs within isolated cpuset
partitions should receive the same treatment to reduce unnecessary
interference. This patch introduces a new cpuset_cpu_is_isolated()
function to be called by cpu_is_isolated() so that the set of dynamically
created cpuset isolated CPUs will be included in the check.

Assuming that testing a bit in a cpumask is atomic, no synchronization
primitive is currently used to synchronize access to the cpuset's
isolated_cpus mask.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 include/linux/cpuset.h          |  6 ++++++
 include/linux/sched/isolation.h |  4 +++-
 kernel/cgroup/cpuset.c          | 11 +++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
index d629094fac6e..875d12598bd2 100644
--- a/include/linux/cpuset.h
+++ b/include/linux/cpuset.h
@@ -77,6 +77,7 @@ extern void cpuset_lock(void);
 extern void cpuset_unlock(void);
 extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
 extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
+extern bool cpuset_cpu_is_isolated(int cpu);
 extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
 #define cpuset_current_mems_allowed (current->mems_allowed)
 void cpuset_init_current_mems_allowed(void);
@@ -207,6 +208,11 @@ static inline bool cpuset_cpus_allowed_fallback(struct task_struct *p)
 	return false;
 }
 
+static inline bool cpuset_cpu_is_isolated(int cpu)
+{
+	return false;
+}
+
 static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
 {
 	return node_possible_map;
diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
index fe1a46f30d24..2b461129d1fa 100644
--- a/include/linux/sched/isolation.h
+++ b/include/linux/sched/isolation.h
@@ -2,6 +2,7 @@
 #define _LINUX_SCHED_ISOLATION_H
 
 #include <linux/cpumask.h>
+#include <linux/cpuset.h>
 #include <linux/init.h>
 #include <linux/tick.h>
 
@@ -67,7 +68,8 @@ static inline bool housekeeping_cpu(int cpu, enum hk_type type)
 static inline bool cpu_is_isolated(int cpu)
 {
 	return !housekeeping_test_cpu(cpu, HK_TYPE_DOMAIN) ||
-		 !housekeeping_test_cpu(cpu, HK_TYPE_TICK);
+	       !housekeeping_test_cpu(cpu, HK_TYPE_TICK) ||
+	       cpuset_cpu_is_isolated(cpu);
 }
 
 #endif /* _LINUX_SCHED_ISOLATION_H */
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 2a16df86c55c..dfbb16aca9f4 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1518,6 +1518,17 @@ static void update_unbound_workqueue_cpumask(bool isolcpus_updated)
 	WARN_ON_ONCE(ret < 0);
 }
 
+/**
+ * cpuset_cpu_is_isolated - Check if the given CPU is isolated
+ * @cpu: the CPU number to be checked
+ * Return: true if CPU is used in an isolated partition, false otherwise
+ */
+bool cpuset_cpu_is_isolated(int cpu)
+{
+	return cpumask_test_cpu(cpu, isolated_cpus);
+}
+EXPORT_SYMBOL_GPL(cpuset_cpu_is_isolated);
+
 /*
  * compute_effective_exclusive_cpumask - compute effective exclusive CPUs
  * @cs: cpuset
-- 
2.39.3


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

* Re: [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check
  2023-12-05 22:21 [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check Waiman Long
@ 2023-12-06 10:55 ` Bagas Sanjaya
  2023-12-06 19:38 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Bagas Sanjaya @ 2023-12-06 10:55 UTC (permalink / raw)
  To: Waiman Long, Tejun Heo, Zefan Li, Johannes Weiner, Andrew Morton,
	Michal Hocko, Frederic Weisbecker
  Cc: Linux CGroups, Linux Kernel Mailing List, Mrunal Patel,
	Ryan Phillips, Brent Rowsell, Peter Hunt, Cestmir Kalina

[-- Attachment #1: Type: text/plain, Size: 3861 bytes --]

On Tue, Dec 05, 2023 at 05:21:14PM -0500, Waiman Long wrote:
> Currently, the cpu_is_isolated() function checks only the statically
> isolated CPUs specified via the "isolcpus" and "nohz_full" kernel
> command line options. This function is used by vmstat and memcg to
> reduce interference with isolated CPUs by not doing stat flushing
> or scheduling works on those CPUs.
> 
> Workloads running on isolated CPUs within isolated cpuset
> partitions should receive the same treatment to reduce unnecessary
> interference. This patch introduces a new cpuset_cpu_is_isolated()
> function to be called by cpu_is_isolated() so that the set of dynamically
> created cpuset isolated CPUs will be included in the check.
> 
> Assuming that testing a bit in a cpumask is atomic, no synchronization
> primitive is currently used to synchronize access to the cpuset's
> isolated_cpus mask.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  include/linux/cpuset.h          |  6 ++++++
>  include/linux/sched/isolation.h |  4 +++-
>  kernel/cgroup/cpuset.c          | 11 +++++++++++
>  3 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index d629094fac6e..875d12598bd2 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -77,6 +77,7 @@ extern void cpuset_lock(void);
>  extern void cpuset_unlock(void);
>  extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
>  extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
> +extern bool cpuset_cpu_is_isolated(int cpu);
>  extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
>  #define cpuset_current_mems_allowed (current->mems_allowed)
>  void cpuset_init_current_mems_allowed(void);
> @@ -207,6 +208,11 @@ static inline bool cpuset_cpus_allowed_fallback(struct task_struct *p)
>  	return false;
>  }
>  
> +static inline bool cpuset_cpu_is_isolated(int cpu)
> +{
> +	return false;
> +}
> +
>  static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
>  {
>  	return node_possible_map;
> diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
> index fe1a46f30d24..2b461129d1fa 100644
> --- a/include/linux/sched/isolation.h
> +++ b/include/linux/sched/isolation.h
> @@ -2,6 +2,7 @@
>  #define _LINUX_SCHED_ISOLATION_H
>  
>  #include <linux/cpumask.h>
> +#include <linux/cpuset.h>
>  #include <linux/init.h>
>  #include <linux/tick.h>
>  
> @@ -67,7 +68,8 @@ static inline bool housekeeping_cpu(int cpu, enum hk_type type)
>  static inline bool cpu_is_isolated(int cpu)
>  {
>  	return !housekeeping_test_cpu(cpu, HK_TYPE_DOMAIN) ||
> -		 !housekeeping_test_cpu(cpu, HK_TYPE_TICK);
> +	       !housekeeping_test_cpu(cpu, HK_TYPE_TICK) ||
> +	       cpuset_cpu_is_isolated(cpu);
>  }
>  
>  #endif /* _LINUX_SCHED_ISOLATION_H */
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 2a16df86c55c..dfbb16aca9f4 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1518,6 +1518,17 @@ static void update_unbound_workqueue_cpumask(bool isolcpus_updated)
>  	WARN_ON_ONCE(ret < 0);
>  }
>  
> +/**
> + * cpuset_cpu_is_isolated - Check if the given CPU is isolated
> + * @cpu: the CPU number to be checked
> + * Return: true if CPU is used in an isolated partition, false otherwise
> + */
> +bool cpuset_cpu_is_isolated(int cpu)
> +{
> +	return cpumask_test_cpu(cpu, isolated_cpus);
> +}
> +EXPORT_SYMBOL_GPL(cpuset_cpu_is_isolated);
> +
>  /*
>   * compute_effective_exclusive_cpumask - compute effective exclusive CPUs
>   * @cs: cpuset


No regressions when booting the kernel with this patch applied.

Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>

-- 
An old man doll... just what I always wanted! - Clara

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check
  2023-12-05 22:21 [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check Waiman Long
  2023-12-06 10:55 ` Bagas Sanjaya
@ 2023-12-06 19:38 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2023-12-06 19:38 UTC (permalink / raw)
  To: Waiman Long
  Cc: Zefan Li, Johannes Weiner, Andrew Morton, Michal Hocko,
	Frederic Weisbecker, cgroups, linux-kernel, Mrunal Patel,
	Ryan Phillips, Brent Rowsell, Peter Hunt, Cestmir Kalina

On Tue, Dec 05, 2023 at 05:21:14PM -0500, Waiman Long wrote:
> Currently, the cpu_is_isolated() function checks only the statically
> isolated CPUs specified via the "isolcpus" and "nohz_full" kernel
> command line options. This function is used by vmstat and memcg to
> reduce interference with isolated CPUs by not doing stat flushing
> or scheduling works on those CPUs.
> 
> Workloads running on isolated CPUs within isolated cpuset
> partitions should receive the same treatment to reduce unnecessary
> interference. This patch introduces a new cpuset_cpu_is_isolated()
> function to be called by cpu_is_isolated() so that the set of dynamically
> created cpuset isolated CPUs will be included in the check.
> 
> Assuming that testing a bit in a cpumask is atomic, no synchronization
> primitive is currently used to synchronize access to the cpuset's
> isolated_cpus mask.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>

Applied to cgroup/for-6.8.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2023-12-06 19:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-05 22:21 [PATCH-cgroup v2] cgroup/cpuset: Include isolated cpuset CPUs in cpu_is_isolated() check Waiman Long
2023-12-06 10:55 ` Bagas Sanjaya
2023-12-06 19:38 ` Tejun Heo

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