public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 -next 0/3] Some optimizations about cpuset
@ 2024-08-20  3:01 Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chen Ridong @ 2024-08-20  3:01 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
  Cc: cgroups, linux-kernel

The first patch changes from v1:
	Rename PERR_PMT to PERR_ACCESS, and update comments.
	Move 'xcpus_empty() check' up for local and remote partition.

The follow patches have been reviewed by Longman.
cgroup/cpuset: remove fetch_xcpus
cgroup/cpuset: remove use_parent_ecpus of cpuset

Chen Ridong (3):
  cgroup/cpuset: Correct invalid remote parition prs
  cgroup/cpuset: remove fetch_xcpus
  cgroup/cpuset: remove use_parent_ecpus of cpuset

 kernel/cgroup/cpuset.c | 71 ++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 48 deletions(-)

-- 
2.34.1


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

* [PATCH v2 -next 1/3] cgroup/cpuset: Correct invalid remote parition prs
  2024-08-20  3:01 [PATCH v2 -next 0/3] Some optimizations about cpuset Chen Ridong
@ 2024-08-20  3:01 ` Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Ridong @ 2024-08-20  3:01 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
  Cc: cgroups, linux-kernel

When enable a remote partition, I found that:

cd /sys/fs/cgroup/
mkdir test
mkdir test/test1
echo +cpuset > cgroup.subtree_control
echo +cpuset >  test/cgroup.subtree_control
echo 3 > test/test1/cpuset.cpus
echo root > test/test1/cpuset.cpus.partition
cat test/test1/cpuset.cpus.partition
root invalid (Parent is not a partition root)

The parent of a remote partition could not be a root. This is due to the
emtpy effective_xcpus. It would be better to prompt the message "invalid
cpu list in cpuset.cpus.exclusive".

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index e34fd6108b06..0ae68e0e5733 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -80,6 +80,7 @@ enum prs_errcode {
 	PERR_HOTPLUG,
 	PERR_CPUSEMPTY,
 	PERR_HKEEPING,
+	PERR_ACCESS,
 };
 
 static const char * const perr_strings[] = {
@@ -91,6 +92,7 @@ static const char * const perr_strings[] = {
 	[PERR_HOTPLUG]   = "No cpu available due to hotplug",
 	[PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are empty",
 	[PERR_HKEEPING]  = "partition config conflicts with housekeeping setup",
+	[PERR_ACCESS]    = "Enable partition not permitted",
 };
 
 struct cpuset {
@@ -1655,7 +1657,7 @@ static inline bool is_local_partition(struct cpuset *cs)
  * @cs: the cpuset to update
  * @new_prs: new partition_root_state
  * @tmp: temparary masks
- * Return: 1 if successful, 0 if error
+ * Return: 0 if successful, errcode if error
  *
  * Enable the current cpuset to become a remote partition root taking CPUs
  * directly from the top cpuset. cpuset_mutex must be held by the caller.
@@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
 	 * The user must have sysadmin privilege.
 	 */
 	if (!capable(CAP_SYS_ADMIN))
-		return 0;
+		return PERR_ACCESS;
 
 	/*
 	 * The requested exclusive_cpus must not be allocated to other
@@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
 	if (cpumask_empty(tmp->new_cpus) ||
 	    cpumask_intersects(tmp->new_cpus, subpartitions_cpus) ||
 	    cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus))
-		return 0;
+		return PERR_INVCPUS;
 
 	spin_lock_irq(&callback_lock);
 	isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
@@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
 	 */
 	update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
 	update_sibling_cpumasks(&top_cpuset, NULL, tmp);
-	return 1;
+	return 0;
 }
 
 /*
@@ -3151,9 +3153,6 @@ static int update_prstate(struct cpuset *cs, int new_prs)
 		goto out;
 
 	if (!old_prs) {
-		enum partition_cmd cmd = (new_prs == PRS_ROOT)
-				       ? partcmd_enable : partcmd_enablei;
-
 		/*
 		 * cpus_allowed and exclusive_cpus cannot be both empty.
 		 */
@@ -3162,13 +3161,18 @@ static int update_prstate(struct cpuset *cs, int new_prs)
 			goto out;
 		}
 
-		err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
 		/*
-		 * If an attempt to become local partition root fails,
-		 * try to become a remote partition root instead.
+		 * If parent is valid partition, enable local partiion.
+		 * Otherwise, enable a remote partition.
 		 */
-		if (err && remote_partition_enable(cs, new_prs, &tmpmask))
-			err = 0;
+		if (is_partition_valid(parent)) {
+			enum partition_cmd cmd = (new_prs == PRS_ROOT)
+					       ? partcmd_enable : partcmd_enablei;
+
+			err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
+		} else {
+			err = remote_partition_enable(cs, new_prs, &tmpmask);
+		}
 	} else if (old_prs && new_prs) {
 		/*
 		 * A change in load balance state only, no change in cpumasks.
-- 
2.34.1


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

* [PATCH v2 -next 2/3] cgroup/cpuset: remove fetch_xcpus
  2024-08-20  3:01 [PATCH v2 -next 0/3] Some optimizations about cpuset Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
@ 2024-08-20  3:01 ` Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
  2024-08-20 18:10 ` [PATCH v2 -next 0/3] Some optimizations about cpuset Waiman Long
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Ridong @ 2024-08-20  3:01 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
  Cc: cgroups, linux-kernel

Both fetch_xcpus and user_xcpus functions are used to retrieve the value
of exclusive_cpus. If exclusive_cpus is not set, cpus_allowed is the
implicit value used as exclusive in a local partition. I can not imagine
a scenario where effective_xcpus is not empty when exclusive_cpus is
empty. Therefore, I suggest removing the fetch_xcpus function.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 0ae68e0e5733..92e79ddc8188 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -771,13 +771,6 @@ static inline bool xcpus_empty(struct cpuset *cs)
 	       cpumask_empty(cs->exclusive_cpus);
 }
 
-static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
-{
-	return !cpumask_empty(cs->exclusive_cpus) ? cs->exclusive_cpus :
-	       cpumask_empty(cs->effective_xcpus) ? cs->cpus_allowed
-						  : cs->effective_xcpus;
-}
-
 /*
  * cpusets_are_exclusive() - check if two cpusets are exclusive
  *
@@ -785,8 +778,8 @@ static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
  */
 static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
 {
-	struct cpumask *xcpus1 = fetch_xcpus(cs1);
-	struct cpumask *xcpus2 = fetch_xcpus(cs2);
+	struct cpumask *xcpus1 = user_xcpus(cs1);
+	struct cpumask *xcpus2 = user_xcpus(cs2);
 
 	if (cpumask_intersects(xcpus1, xcpus2))
 		return false;
@@ -2585,7 +2578,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
 		invalidate = true;
 		rcu_read_lock();
 		cpuset_for_each_child(cp, css, parent) {
-			struct cpumask *xcpus = fetch_xcpus(trialcs);
+			struct cpumask *xcpus = user_xcpus(trialcs);
 
 			if (is_partition_valid(cp) &&
 			    cpumask_intersects(xcpus, cp->effective_xcpus)) {
-- 
2.34.1


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

* [PATCH v2 -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset
  2024-08-20  3:01 [PATCH v2 -next 0/3] Some optimizations about cpuset Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
  2024-08-20  3:01 ` [PATCH v2 -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
@ 2024-08-20  3:01 ` Chen Ridong
  2024-08-20 18:10 ` [PATCH v2 -next 0/3] Some optimizations about cpuset Waiman Long
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Ridong @ 2024-08-20  3:01 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
  Cc: cgroups, linux-kernel

use_parent_ecpus is used to track whether the children are using the
parent's effective_cpus. When a parent's effective_cpus is changed
due to changes in a child partition's effective_xcpus, any child
using parent'effective_cpus must call update_cpumasks_hier. However,
if a child is not a valid partition, it is sufficient to determine
whether to call update_cpumasks_hier based on whether the child's
effective_cpus is going to change. To make the code more succinct,
it is suggested to remove use_parent_ecpus.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 92e79ddc8188..7db55eed63cf 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -185,12 +185,6 @@ struct cpuset {
 	/* partition root state */
 	int partition_root_state;
 
-	/*
-	 * Default hierarchy only:
-	 * use_parent_ecpus - set if using parent's effective_cpus
-	 */
-	int use_parent_ecpus;
-
 	/*
 	 * number of SCHED_DEADLINE tasks attached to this cpuset, so that we
 	 * know when to rebuild associated root domain bandwidth information.
@@ -1505,11 +1499,8 @@ static void reset_partition_data(struct cpuset *cs)
 		if (is_cpu_exclusive(cs))
 			clear_bit(CS_CPU_EXCLUSIVE, &cs->flags);
 	}
-	if (!cpumask_and(cs->effective_cpus,
-			 parent->effective_cpus, cs->cpus_allowed)) {
-		cs->use_parent_ecpus = true;
+	if (!cpumask_and(cs->effective_cpus, parent->effective_cpus, cs->cpus_allowed))
 		cpumask_copy(cs->effective_cpus, parent->effective_cpus);
-	}
 }
 
 /*
@@ -1683,8 +1674,6 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
 	spin_lock_irq(&callback_lock);
 	isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
 	list_add(&cs->remote_sibling, &remote_children);
-	if (cs->use_parent_ecpus)
-		cs->use_parent_ecpus = false;
 	spin_unlock_irq(&callback_lock);
 	update_unbound_workqueue_cpumask(isolcpus_updated);
 
@@ -2309,13 +2298,8 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
 		 * it is a partition root that has explicitly distributed
 		 * out all its CPUs.
 		 */
-		if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) {
+		if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus))
 			cpumask_copy(tmp->new_cpus, parent->effective_cpus);
-			if (!cp->use_parent_ecpus)
-				cp->use_parent_ecpus = true;
-		} else if (cp->use_parent_ecpus) {
-			cp->use_parent_ecpus = false;
-		}
 
 		if (remote)
 			goto get_css;
@@ -2452,8 +2436,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
 	 * Check all its siblings and call update_cpumasks_hier()
 	 * if their effective_cpus will need to be changed.
 	 *
-	 * With the addition of effective_xcpus which is a subset of
-	 * cpus_allowed. It is possible a change in parent's effective_cpus
+	 * It is possible a change in parent's effective_cpus
 	 * due to a change in a child partition's effective_xcpus will impact
 	 * its siblings even if they do not inherit parent's effective_cpus
 	 * directly.
@@ -2467,8 +2450,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
 	cpuset_for_each_child(sibling, pos_css, parent) {
 		if (sibling == cs)
 			continue;
-		if (!sibling->use_parent_ecpus &&
-		    !is_partition_valid(sibling)) {
+		if (!is_partition_valid(sibling)) {
 			compute_effective_cpumask(tmp->new_cpus, sibling,
 						  parent);
 			if (cpumask_equal(tmp->new_cpus, sibling->effective_cpus))
@@ -4128,7 +4110,6 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
 	if (is_in_v2_mode()) {
 		cpumask_copy(cs->effective_cpus, parent->effective_cpus);
 		cs->effective_mems = parent->effective_mems;
-		cs->use_parent_ecpus = true;
 	}
 	spin_unlock_irq(&callback_lock);
 
@@ -4194,9 +4175,6 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
 	    is_sched_load_balance(cs))
 		update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
 
-	if (cs->use_parent_ecpus)
-		cs->use_parent_ecpus = false;
-
 	cpuset_dec();
 	clear_bit(CS_ONLINE, &cs->flags);
 
-- 
2.34.1


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

* Re: [PATCH v2 -next 0/3] Some optimizations about cpuset
  2024-08-20  3:01 [PATCH v2 -next 0/3] Some optimizations about cpuset Chen Ridong
                   ` (2 preceding siblings ...)
  2024-08-20  3:01 ` [PATCH v2 -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
@ 2024-08-20 18:10 ` Waiman Long
  3 siblings, 0 replies; 5+ messages in thread
From: Waiman Long @ 2024-08-20 18:10 UTC (permalink / raw)
  To: Chen Ridong, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
  Cc: cgroups, linux-kernel

On 8/19/24 23:01, Chen Ridong wrote:
> The first patch changes from v1:
> 	Rename PERR_PMT to PERR_ACCESS, and update comments.
> 	Move 'xcpus_empty() check' up for local and remote partition.
>
> The follow patches have been reviewed by Longman.
> cgroup/cpuset: remove fetch_xcpus
> cgroup/cpuset: remove use_parent_ecpus of cpuset
>
> Chen Ridong (3):
>    cgroup/cpuset: Correct invalid remote parition prs
>    cgroup/cpuset: remove fetch_xcpus
>    cgroup/cpuset: remove use_parent_ecpus of cpuset
>
>   kernel/cgroup/cpuset.c | 71 ++++++++++++++----------------------------
>   1 file changed, 23 insertions(+), 48 deletions(-)
>
For the series,

Reviewed-by: Waiman Long <longman@redhat.com>


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

end of thread, other threads:[~2024-08-20 18:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20  3:01 [PATCH v2 -next 0/3] Some optimizations about cpuset Chen Ridong
2024-08-20  3:01 ` [PATCH v2 -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
2024-08-20  3:01 ` [PATCH v2 -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
2024-08-20  3:01 ` [PATCH v2 -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
2024-08-20 18:10 ` [PATCH v2 -next 0/3] Some optimizations about cpuset Waiman Long

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