* [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks
@ 2023-04-19 12:50 Peter Newman
2023-04-19 12:50 ` [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Peter Newman @ 2023-04-19 12:50 UTC (permalink / raw)
To: fenghua.yu, reinette.chatre
Cc: Babu.Moger, bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck, x86, Peter Newman
Hi Reinette, Fenghua,
This patch series implements the solution Reinette suggested in the
earlier RFD thread[1] for the problem of moving a container's tasks to a
different control group on systems that don't provide enough CLOSIDs to
give every container its own control group.
This patch series assumes that a MON group's CLOSID can simply be
changed to that of a new parent CTRL_MON group. This is allowed on Intel
and AMD, but not MPAM implementations. While we (Google) only foresee
needing this functionality on Intel and AMD systems, this series should
hopefully be a good starting point for supporting MPAM.
Thanks!
-Peter
Updates:
v6:
- rebase to v6.3-rc7
- clarify changelog wording
- clarify error message for non-directory move
- remove unneeded parenthesis for checkpatch.pl --strict
- add Reviewed-By's from Reinette
v5:
- rebase to v6.3-rc4
- dropped rdt_move_group_tasks() task filter patch
- code/comment clarifications and errno updates requested by Reinette
- added Documentation patch
v4:
- rebase to v6.2
- commit message updates suggested by Reinette
- replace rdt_move_one_task() patch with rdt_move_group_tasks() filter
function patch
- prevent rename on files or renaming to "mon_groups"
- optimize simple rename case
- disallow renaming groups with non-empty cpumask
- ensure source is a proper MON group directory
- fix missing rdtgrp->closid update
- add more last_command_status output
v3: use revised task CLOSID/RMID update IPI sync method from [3]
v2: reworded change logs based on what I've learned from review comments
in another patch series[2]
[v1] https://lore.kernel.org/lkml/20221115154515.952783-1-peternewman@google.com/
[v2] https://lore.kernel.org/lkml/20221129120149.1035444-1-peternewman@google.com/
[v3] https://lore.kernel.org/lkml/20230125101334.1069060-1-peternewman@google.com/
[v4] https://lore.kernel.org/lkml/20230308131452.383914-1-peternewman@google.com/
[v5] https://lore.kernel.org/lkml/20230330135558.1019658-1-peternewman@google.com/
[1] https://lore.kernel.org/lkml/7b09fb62-e61a-65b9-a71e-ab725f527ded@intel.com/
[2] https://lore.kernel.org/lkml/54e50a9b-268f-2020-f54c-d38312489e2f@intel.com/
[3] https://lore.kernel.org/lkml/20221220161123.432120-1-peternewman@google.com/
Peter Newman (3):
x86/resctrl: Factor rdtgroup lock for multi-file ops
x86/resctrl: Implement rename op for mon groups
Documentation/x86: Documentation for MON group move feature
Documentation/x86/resctrl.rst | 7 ++
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 163 +++++++++++++++++++++++--
2 files changed, 157 insertions(+), 13 deletions(-)
base-commit: 6a8f57ae2eb07ab39a6f0ccad60c760743051026
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops
2023-04-19 12:50 [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
@ 2023-04-19 12:50 ` Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-04-19 12:50 ` [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups Peter Newman
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Peter Newman @ 2023-04-19 12:50 UTC (permalink / raw)
To: fenghua.yu, reinette.chatre
Cc: Babu.Moger, bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck, x86, Peter Newman
rdtgroup_kn_lock_live() can only release a kernfs reference for a single
file before waiting on the rdtgroup_mutex, limiting its usefulness for
operations on multiple files, such as rename.
Factor the work needed to respectively break and unbreak active
protection on an individual file into rdtgroup_kn_{get,put}().
No functional change.
Signed-off-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 ++++++++++++++++----------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 6ad33f355861..51b869149e76 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2301,6 +2301,26 @@ static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
}
}
+static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
+{
+ atomic_inc(&rdtgrp->waitcount);
+ kernfs_break_active_protection(kn);
+}
+
+static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
+{
+ if (atomic_dec_and_test(&rdtgrp->waitcount) &&
+ (rdtgrp->flags & RDT_DELETED)) {
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
+ rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
+ rdtgroup_pseudo_lock_remove(rdtgrp);
+ kernfs_unbreak_active_protection(kn);
+ rdtgroup_remove(rdtgrp);
+ } else {
+ kernfs_unbreak_active_protection(kn);
+ }
+}
+
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
{
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
@@ -2308,8 +2328,7 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
if (!rdtgrp)
return NULL;
- atomic_inc(&rdtgrp->waitcount);
- kernfs_break_active_protection(kn);
+ rdtgroup_kn_get(rdtgrp, kn);
mutex_lock(&rdtgroup_mutex);
@@ -2328,17 +2347,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
return;
mutex_unlock(&rdtgroup_mutex);
-
- if (atomic_dec_and_test(&rdtgrp->waitcount) &&
- (rdtgrp->flags & RDT_DELETED)) {
- if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
- rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
- rdtgroup_pseudo_lock_remove(rdtgrp);
- kernfs_unbreak_active_protection(kn);
- rdtgroup_remove(rdtgrp);
- } else {
- kernfs_unbreak_active_protection(kn);
- }
+ rdtgroup_kn_put(rdtgrp, kn);
}
static int mkdir_mondata_all(struct kernfs_node *parent_kn,
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups
2023-04-19 12:50 [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
2023-04-19 12:50 ` [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
@ 2023-04-19 12:50 ` Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-04-19 12:50 ` [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature Peter Newman
2023-05-03 14:50 ` [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Moger, Babu
3 siblings, 1 reply; 9+ messages in thread
From: Peter Newman @ 2023-04-19 12:50 UTC (permalink / raw)
To: fenghua.yu, reinette.chatre
Cc: Babu.Moger, bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck, x86, Peter Newman
To change the resources allocated to a large group of tasks, such as an
application container, a container manager must write all of the tasks'
IDs into the tasks file interface of the new control group. This is
challenging when the container's task list is always changing.
In addition, if the container manager is using monitoring groups to
separately track the bandwidth of containers assigned to the same
control group, when moving a container, it must first move the
container's tasks to the default monitoring group of the new control
group before it can move these tasks into the container's replacement
monitoring group under the destination control group. This is
undesirable because it makes bandwidth usage during the move
unattributable to the correct tasks and resets monitoring event counters
and cache usage information for the group.
Implement the rename operation only for resctrlfs monitor groups to
enable users to move a monitoring group from one control group to
another. This effects a change in resources allocated to all the tasks
in the monitoring group while otherwise leaving the monitoring data
intact.
Signed-off-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 128 +++++++++++++++++++++++++
1 file changed, 128 insertions(+)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 51b869149e76..6a301233b9ef 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -3514,6 +3514,133 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
return ret;
}
+/**
+ * mongrp_reparent() - replace parent CTRL_MON group of a MON group
+ * @rdtgrp: the MON group whose parent should be replaced
+ * @new_prdtgrp: replacement parent CTRL_MON group for @rdtgrp
+ * @cpus: cpumask provided by the caller for use during this call
+ *
+ * Replaces the parent CTRL_MON group for a MON group, resulting in all member
+ * tasks' CLOSID immediately changing to that of the new parent group.
+ * Monitoring data for the group is unaffected by this operation.
+ */
+static void mongrp_reparent(struct rdtgroup *rdtgrp,
+ struct rdtgroup *new_prdtgrp,
+ cpumask_var_t cpus)
+{
+ struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+
+ WARN_ON(rdtgrp->type != RDTMON_GROUP);
+ WARN_ON(new_prdtgrp->type != RDTCTRL_GROUP);
+
+ /* Nothing to do when simply renaming a MON group. */
+ if (prdtgrp == new_prdtgrp)
+ return;
+
+ WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
+ list_move_tail(&rdtgrp->mon.crdtgrp_list,
+ &new_prdtgrp->mon.crdtgrp_list);
+
+ rdtgrp->mon.parent = new_prdtgrp;
+ rdtgrp->closid = new_prdtgrp->closid;
+
+ /* Propagate updated closid to all tasks in this group. */
+ rdt_move_group_tasks(rdtgrp, rdtgrp, cpus);
+
+ update_closid_rmid(cpus, NULL);
+}
+
+static int rdtgroup_rename(struct kernfs_node *kn,
+ struct kernfs_node *new_parent, const char *new_name)
+{
+ struct rdtgroup *new_prdtgrp;
+ struct rdtgroup *rdtgrp;
+ cpumask_var_t tmpmask;
+ int ret;
+
+ rdtgrp = kernfs_to_rdtgroup(kn);
+ new_prdtgrp = kernfs_to_rdtgroup(new_parent);
+ if (!rdtgrp || !new_prdtgrp)
+ return -ENOENT;
+
+ /* Release both kernfs active_refs before obtaining rdtgroup mutex. */
+ rdtgroup_kn_get(rdtgrp, kn);
+ rdtgroup_kn_get(new_prdtgrp, new_parent);
+
+ mutex_lock(&rdtgroup_mutex);
+
+ rdt_last_cmd_clear();
+
+ /*
+ * Don't allow kernfs_to_rdtgroup() to return a parent rdtgroup if
+ * either kernfs_node is a file.
+ */
+ if (kernfs_type(kn) != KERNFS_DIR ||
+ kernfs_type(new_parent) != KERNFS_DIR) {
+ rdt_last_cmd_puts("Source and destination must be directories");
+ ret = -EPERM;
+ goto out;
+ }
+
+ if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) {
+ ret = -ENOENT;
+ goto out;
+ }
+
+ if (rdtgrp->type != RDTMON_GROUP || !kn->parent ||
+ !is_mon_groups(kn->parent, kn->name)) {
+ rdt_last_cmd_puts("Source must be a MON group\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ if (!is_mon_groups(new_parent, new_name)) {
+ rdt_last_cmd_puts("Destination must be a mon_groups subdirectory\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ /*
+ * If the MON group is monitoring CPUs, the CPUs must be assigned to the
+ * current parent CTRL_MON group and therefore cannot be assigned to
+ * the new parent, making the move illegal.
+ */
+ if (!cpumask_empty(&rdtgrp->cpu_mask) &&
+ rdtgrp->mon.parent != new_prdtgrp) {
+ rdt_last_cmd_puts("Cannot move a MON group that monitors CPUs\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ /*
+ * Allocate the cpumask for use in mongrp_reparent() to avoid the
+ * possibility of failing to allocate it after kernfs_rename() has
+ * succeeded.
+ */
+ if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ /*
+ * Perform all input validation and allocations needed to ensure
+ * mongrp_reparent() will succeed before calling kernfs_rename(),
+ * otherwise it would be necessary to revert this call if
+ * mongrp_reparent() failed.
+ */
+ ret = kernfs_rename(kn, new_parent, new_name);
+ if (!ret)
+ mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask);
+
+ free_cpumask_var(tmpmask);
+
+out:
+ mutex_unlock(&rdtgroup_mutex);
+ rdtgroup_kn_put(rdtgrp, kn);
+ rdtgroup_kn_put(new_prdtgrp, new_parent);
+ return ret;
+}
+
static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
{
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
@@ -3531,6 +3658,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
.mkdir = rdtgroup_mkdir,
.rmdir = rdtgroup_rmdir,
+ .rename = rdtgroup_rename,
.show_options = rdtgroup_show_options,
};
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature
2023-04-19 12:50 [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
2023-04-19 12:50 ` [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
2023-04-19 12:50 ` [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups Peter Newman
@ 2023-04-19 12:50 ` Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-05-03 14:50 ` [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Moger, Babu
3 siblings, 1 reply; 9+ messages in thread
From: Peter Newman @ 2023-04-19 12:50 UTC (permalink / raw)
To: fenghua.yu, reinette.chatre
Cc: Babu.Moger, bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck, x86, Peter Newman
Describe new support for moving MON groups to a new parent CTRL_MON
group and its restrictions.
Signed-off-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
Documentation/x86/resctrl.rst | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
index 387ccbcb558f..cb05d90111b4 100644
--- a/Documentation/x86/resctrl.rst
+++ b/Documentation/x86/resctrl.rst
@@ -287,6 +287,13 @@ Removing a directory will move all tasks and cpus owned by the group it
represents to the parent. Removing one of the created CTRL_MON groups
will automatically remove all MON groups below it.
+Moving MON group directories to a new parent CTRL_MON group is supported
+for the purpose of changing the resource allocations of a MON group
+without impacting its monitoring data or assigned tasks. This operation
+is not allowed for MON groups which monitor CPUs. No other move
+operation is currently allowed other than simply renaming a CTRL_MON or
+MON group.
+
All groups contain the following files:
"tasks":
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks
2023-04-19 12:50 [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
` (2 preceding siblings ...)
2023-04-19 12:50 ` [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature Peter Newman
@ 2023-05-03 14:50 ` Moger, Babu
2023-06-01 21:38 ` Reinette Chatre
3 siblings, 1 reply; 9+ messages in thread
From: Moger, Babu @ 2023-05-03 14:50 UTC (permalink / raw)
To: Peter Newman, fenghua.yu, reinette.chatre
Cc: bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck, x86
Tested the series. Looks good.
Tested-by: Babu Moger <babu.moger@amd.com>
On 4/19/23 07:50, Peter Newman wrote:
> Hi Reinette, Fenghua,
>
> This patch series implements the solution Reinette suggested in the
> earlier RFD thread[1] for the problem of moving a container's tasks to a
> different control group on systems that don't provide enough CLOSIDs to
> give every container its own control group.
>
> This patch series assumes that a MON group's CLOSID can simply be
> changed to that of a new parent CTRL_MON group. This is allowed on Intel
> and AMD, but not MPAM implementations. While we (Google) only foresee
> needing this functionality on Intel and AMD systems, this series should
> hopefully be a good starting point for supporting MPAM.
>
> Thanks!
> -Peter
>
> Updates:
>
> v6:
> - rebase to v6.3-rc7
> - clarify changelog wording
> - clarify error message for non-directory move
> - remove unneeded parenthesis for checkpatch.pl --strict
> - add Reviewed-By's from Reinette
>
> v5:
> - rebase to v6.3-rc4
> - dropped rdt_move_group_tasks() task filter patch
> - code/comment clarifications and errno updates requested by Reinette
> - added Documentation patch
>
> v4:
> - rebase to v6.2
> - commit message updates suggested by Reinette
> - replace rdt_move_one_task() patch with rdt_move_group_tasks() filter
> function patch
> - prevent rename on files or renaming to "mon_groups"
> - optimize simple rename case
> - disallow renaming groups with non-empty cpumask
> - ensure source is a proper MON group directory
> - fix missing rdtgrp->closid update
> - add more last_command_status output
>
> v3: use revised task CLOSID/RMID update IPI sync method from [3]
> v2: reworded change logs based on what I've learned from review comments
> in another patch series[2]
>
> [v1] https://lore.kernel.org/lkml/20221115154515.952783-1-peternewman@google.com/
> [v2] https://lore.kernel.org/lkml/20221129120149.1035444-1-peternewman@google.com/
> [v3] https://lore.kernel.org/lkml/20230125101334.1069060-1-peternewman@google.com/
> [v4] https://lore.kernel.org/lkml/20230308131452.383914-1-peternewman@google.com/
> [v5] https://lore.kernel.org/lkml/20230330135558.1019658-1-peternewman@google.com/
>
> [1] https://lore.kernel.org/lkml/7b09fb62-e61a-65b9-a71e-ab725f527ded@intel.com/
> [2] https://lore.kernel.org/lkml/54e50a9b-268f-2020-f54c-d38312489e2f@intel.com/
> [3] https://lore.kernel.org/lkml/20221220161123.432120-1-peternewman@google.com/
>
> Peter Newman (3):
> x86/resctrl: Factor rdtgroup lock for multi-file ops
> x86/resctrl: Implement rename op for mon groups
> Documentation/x86: Documentation for MON group move feature
>
> Documentation/x86/resctrl.rst | 7 ++
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 163 +++++++++++++++++++++++--
> 2 files changed, 157 insertions(+), 13 deletions(-)
>
>
> base-commit: 6a8f57ae2eb07ab39a6f0ccad60c760743051026
--
Thanks
Babu Moger
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks
2023-05-03 14:50 ` [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Moger, Babu
@ 2023-06-01 21:38 ` Reinette Chatre
0 siblings, 0 replies; 9+ messages in thread
From: Reinette Chatre @ 2023-06-01 21:38 UTC (permalink / raw)
To: babu.moger, Peter Newman, fenghua.yu, x86
Cc: bp, dave.hansen, eranian, gupasani, hpa, james.morse,
linux-kernel, mingo, skodak, tglx, tony.luck
Hi x86 Maintainers,
Could you please consider this series for inclusion?
Thank you very much
Reinette
On 5/3/2023 7:50 AM, Moger, Babu wrote:
> Tested the series. Looks good.
>
> Tested-by: Babu Moger <babu.moger@amd.com>
>
> On 4/19/23 07:50, Peter Newman wrote:
>> Hi Reinette, Fenghua,
>>
>> This patch series implements the solution Reinette suggested in the
>> earlier RFD thread[1] for the problem of moving a container's tasks to a
>> different control group on systems that don't provide enough CLOSIDs to
>> give every container its own control group.
>>
>> This patch series assumes that a MON group's CLOSID can simply be
>> changed to that of a new parent CTRL_MON group. This is allowed on Intel
>> and AMD, but not MPAM implementations. While we (Google) only foresee
>> needing this functionality on Intel and AMD systems, this series should
>> hopefully be a good starting point for supporting MPAM.
>>
>> Thanks!
>> -Peter
>>
>> Updates:
>>
>> v6:
>> - rebase to v6.3-rc7
>> - clarify changelog wording
>> - clarify error message for non-directory move
>> - remove unneeded parenthesis for checkpatch.pl --strict
>> - add Reviewed-By's from Reinette
>>
>> v5:
>> - rebase to v6.3-rc4
>> - dropped rdt_move_group_tasks() task filter patch
>> - code/comment clarifications and errno updates requested by Reinette
>> - added Documentation patch
>>
>> v4:
>> - rebase to v6.2
>> - commit message updates suggested by Reinette
>> - replace rdt_move_one_task() patch with rdt_move_group_tasks() filter
>> function patch
>> - prevent rename on files or renaming to "mon_groups"
>> - optimize simple rename case
>> - disallow renaming groups with non-empty cpumask
>> - ensure source is a proper MON group directory
>> - fix missing rdtgrp->closid update
>> - add more last_command_status output
>>
>> v3: use revised task CLOSID/RMID update IPI sync method from [3]
>> v2: reworded change logs based on what I've learned from review comments
>> in another patch series[2]
>>
>> [v1] https://lore.kernel.org/lkml/20221115154515.952783-1-peternewman@google.com/
>> [v2] https://lore.kernel.org/lkml/20221129120149.1035444-1-peternewman@google.com/
>> [v3] https://lore.kernel.org/lkml/20230125101334.1069060-1-peternewman@google.com/
>> [v4] https://lore.kernel.org/lkml/20230308131452.383914-1-peternewman@google.com/
>> [v5] https://lore.kernel.org/lkml/20230330135558.1019658-1-peternewman@google.com/
>>
>> [1] https://lore.kernel.org/lkml/7b09fb62-e61a-65b9-a71e-ab725f527ded@intel.com/
>> [2] https://lore.kernel.org/lkml/54e50a9b-268f-2020-f54c-d38312489e2f@intel.com/
>> [3] https://lore.kernel.org/lkml/20221220161123.432120-1-peternewman@google.com/
>>
>> Peter Newman (3):
>> x86/resctrl: Factor rdtgroup lock for multi-file ops
>> x86/resctrl: Implement rename op for mon groups
>> Documentation/x86: Documentation for MON group move feature
>>
>> Documentation/x86/resctrl.rst | 7 ++
>> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 163 +++++++++++++++++++++++--
>> 2 files changed, 157 insertions(+), 13 deletions(-)
>>
>>
>> base-commit: 6a8f57ae2eb07ab39a6f0ccad60c760743051026
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tip: x86/cache] Documentation/x86: Documentation for MON group move feature
2023-04-19 12:50 ` [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature Peter Newman
@ 2023-06-07 10:52 ` tip-bot2 for Peter Newman
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Newman @ 2023-06-07 10:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Peter Newman, Borislav Petkov (AMD),
Reinette Chatre, Babu Moger, x86, linux-kernel
The following commit has been merged into the x86/cache branch of tip:
Commit-ID: e0a6ede2dd884adb73a7dde80444185b655f7c79
Gitweb: https://git.kernel.org/tip/e0a6ede2dd884adb73a7dde80444185b655f7c79
Author: Peter Newman <peternewman@google.com>
AuthorDate: Wed, 19 Apr 2023 14:50:15 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 07 Jun 2023 12:42:12 +02:00
Documentation/x86: Documentation for MON group move feature
Describe new support for moving MON groups to a new parent CTRL_MON
group and its restrictions.
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lore.kernel.org/r/20230419125015.693566-4-peternewman@google.com
---
Documentation/arch/x86/resctrl.rst | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index 387ccbc..cb05d90 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -287,6 +287,13 @@ Removing a directory will move all tasks and cpus owned by the group it
represents to the parent. Removing one of the created CTRL_MON groups
will automatically remove all MON groups below it.
+Moving MON group directories to a new parent CTRL_MON group is supported
+for the purpose of changing the resource allocations of a MON group
+without impacting its monitoring data or assigned tasks. This operation
+is not allowed for MON groups which monitor CPUs. No other move
+operation is currently allowed other than simply renaming a CTRL_MON or
+MON group.
+
All groups contain the following files:
"tasks":
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tip: x86/cache] x86/resctrl: Implement rename op for mon groups
2023-04-19 12:50 ` [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups Peter Newman
@ 2023-06-07 10:52 ` tip-bot2 for Peter Newman
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Newman @ 2023-06-07 10:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Peter Newman, Borislav Petkov (AMD),
Reinette Chatre, Babu Moger, x86, linux-kernel
The following commit has been merged into the x86/cache branch of tip:
Commit-ID: 8da2b938eb7e2ef407b8ef99def12e3054a99645
Gitweb: https://git.kernel.org/tip/8da2b938eb7e2ef407b8ef99def12e3054a99645
Author: Peter Newman <peternewman@google.com>
AuthorDate: Wed, 19 Apr 2023 14:50:14 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 07 Jun 2023 12:40:36 +02:00
x86/resctrl: Implement rename op for mon groups
To change the resources allocated to a large group of tasks, such as an
application container, a container manager must write all of the tasks'
IDs into the tasks file interface of the new control group. This is
challenging when the container's task list is always changing.
In addition, if the container manager is using monitoring groups to
separately track the bandwidth of containers assigned to the same
control group, when moving a container, it must first move the
container's tasks to the default monitoring group of the new control
group before it can move these tasks into the container's replacement
monitoring group under the destination control group. This is
undesirable because it makes bandwidth usage during the move
unattributable to the correct tasks and resets monitoring event counters
and cache usage information for the group.
Implement the rename operation only for resctrlfs monitor groups to
enable users to move a monitoring group from one control group to
another. This effects a change in resources allocated to all the tasks
in the monitoring group while otherwise leaving the monitoring data
intact.
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lore.kernel.org/r/20230419125015.693566-3-peternewman@google.com
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 128 ++++++++++++++++++++++++-
1 file changed, 128 insertions(+)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 653d258..7253440 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -3518,6 +3518,133 @@ out:
return ret;
}
+/**
+ * mongrp_reparent() - replace parent CTRL_MON group of a MON group
+ * @rdtgrp: the MON group whose parent should be replaced
+ * @new_prdtgrp: replacement parent CTRL_MON group for @rdtgrp
+ * @cpus: cpumask provided by the caller for use during this call
+ *
+ * Replaces the parent CTRL_MON group for a MON group, resulting in all member
+ * tasks' CLOSID immediately changing to that of the new parent group.
+ * Monitoring data for the group is unaffected by this operation.
+ */
+static void mongrp_reparent(struct rdtgroup *rdtgrp,
+ struct rdtgroup *new_prdtgrp,
+ cpumask_var_t cpus)
+{
+ struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+
+ WARN_ON(rdtgrp->type != RDTMON_GROUP);
+ WARN_ON(new_prdtgrp->type != RDTCTRL_GROUP);
+
+ /* Nothing to do when simply renaming a MON group. */
+ if (prdtgrp == new_prdtgrp)
+ return;
+
+ WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
+ list_move_tail(&rdtgrp->mon.crdtgrp_list,
+ &new_prdtgrp->mon.crdtgrp_list);
+
+ rdtgrp->mon.parent = new_prdtgrp;
+ rdtgrp->closid = new_prdtgrp->closid;
+
+ /* Propagate updated closid to all tasks in this group. */
+ rdt_move_group_tasks(rdtgrp, rdtgrp, cpus);
+
+ update_closid_rmid(cpus, NULL);
+}
+
+static int rdtgroup_rename(struct kernfs_node *kn,
+ struct kernfs_node *new_parent, const char *new_name)
+{
+ struct rdtgroup *new_prdtgrp;
+ struct rdtgroup *rdtgrp;
+ cpumask_var_t tmpmask;
+ int ret;
+
+ rdtgrp = kernfs_to_rdtgroup(kn);
+ new_prdtgrp = kernfs_to_rdtgroup(new_parent);
+ if (!rdtgrp || !new_prdtgrp)
+ return -ENOENT;
+
+ /* Release both kernfs active_refs before obtaining rdtgroup mutex. */
+ rdtgroup_kn_get(rdtgrp, kn);
+ rdtgroup_kn_get(new_prdtgrp, new_parent);
+
+ mutex_lock(&rdtgroup_mutex);
+
+ rdt_last_cmd_clear();
+
+ /*
+ * Don't allow kernfs_to_rdtgroup() to return a parent rdtgroup if
+ * either kernfs_node is a file.
+ */
+ if (kernfs_type(kn) != KERNFS_DIR ||
+ kernfs_type(new_parent) != KERNFS_DIR) {
+ rdt_last_cmd_puts("Source and destination must be directories");
+ ret = -EPERM;
+ goto out;
+ }
+
+ if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) {
+ ret = -ENOENT;
+ goto out;
+ }
+
+ if (rdtgrp->type != RDTMON_GROUP || !kn->parent ||
+ !is_mon_groups(kn->parent, kn->name)) {
+ rdt_last_cmd_puts("Source must be a MON group\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ if (!is_mon_groups(new_parent, new_name)) {
+ rdt_last_cmd_puts("Destination must be a mon_groups subdirectory\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ /*
+ * If the MON group is monitoring CPUs, the CPUs must be assigned to the
+ * current parent CTRL_MON group and therefore cannot be assigned to
+ * the new parent, making the move illegal.
+ */
+ if (!cpumask_empty(&rdtgrp->cpu_mask) &&
+ rdtgrp->mon.parent != new_prdtgrp) {
+ rdt_last_cmd_puts("Cannot move a MON group that monitors CPUs\n");
+ ret = -EPERM;
+ goto out;
+ }
+
+ /*
+ * Allocate the cpumask for use in mongrp_reparent() to avoid the
+ * possibility of failing to allocate it after kernfs_rename() has
+ * succeeded.
+ */
+ if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ /*
+ * Perform all input validation and allocations needed to ensure
+ * mongrp_reparent() will succeed before calling kernfs_rename(),
+ * otherwise it would be necessary to revert this call if
+ * mongrp_reparent() failed.
+ */
+ ret = kernfs_rename(kn, new_parent, new_name);
+ if (!ret)
+ mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask);
+
+ free_cpumask_var(tmpmask);
+
+out:
+ mutex_unlock(&rdtgroup_mutex);
+ rdtgroup_kn_put(rdtgrp, kn);
+ rdtgroup_kn_put(new_prdtgrp, new_parent);
+ return ret;
+}
+
static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
{
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
@@ -3535,6 +3662,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
.mkdir = rdtgroup_mkdir,
.rmdir = rdtgroup_rmdir,
+ .rename = rdtgroup_rename,
.show_options = rdtgroup_show_options,
};
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tip: x86/cache] x86/resctrl: Factor rdtgroup lock for multi-file ops
2023-04-19 12:50 ` [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
@ 2023-06-07 10:52 ` tip-bot2 for Peter Newman
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Peter Newman @ 2023-06-07 10:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Peter Newman, Borislav Petkov (AMD),
Reinette Chatre, Babu Moger, x86, linux-kernel
The following commit has been merged into the x86/cache branch of tip:
Commit-ID: c45c06d4ae63a0714efbfa435c5a8f64a5f35b9b
Gitweb: https://git.kernel.org/tip/c45c06d4ae63a0714efbfa435c5a8f64a5f35b9b
Author: Peter Newman <peternewman@google.com>
AuthorDate: Wed, 19 Apr 2023 14:50:13 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 07 Jun 2023 12:15:18 +02:00
x86/resctrl: Factor rdtgroup lock for multi-file ops
rdtgroup_kn_lock_live() can only release a kernfs reference for a single
file before waiting on the rdtgroup_mutex, limiting its usefulness for
operations on multiple files, such as rename.
Factor the work needed to respectively break and unbreak active
protection on an individual file into rdtgroup_kn_{get,put}().
No functional change.
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lore.kernel.org/r/20230419125015.693566-2-peternewman@google.com
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 +++++++++++++++----------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 61cdd9b..653d258 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2305,6 +2305,26 @@ static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
}
}
+static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
+{
+ atomic_inc(&rdtgrp->waitcount);
+ kernfs_break_active_protection(kn);
+}
+
+static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
+{
+ if (atomic_dec_and_test(&rdtgrp->waitcount) &&
+ (rdtgrp->flags & RDT_DELETED)) {
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
+ rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
+ rdtgroup_pseudo_lock_remove(rdtgrp);
+ kernfs_unbreak_active_protection(kn);
+ rdtgroup_remove(rdtgrp);
+ } else {
+ kernfs_unbreak_active_protection(kn);
+ }
+}
+
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
{
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
@@ -2312,8 +2332,7 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
if (!rdtgrp)
return NULL;
- atomic_inc(&rdtgrp->waitcount);
- kernfs_break_active_protection(kn);
+ rdtgroup_kn_get(rdtgrp, kn);
mutex_lock(&rdtgroup_mutex);
@@ -2332,17 +2351,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
return;
mutex_unlock(&rdtgroup_mutex);
-
- if (atomic_dec_and_test(&rdtgrp->waitcount) &&
- (rdtgrp->flags & RDT_DELETED)) {
- if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
- rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
- rdtgroup_pseudo_lock_remove(rdtgrp);
- kernfs_unbreak_active_protection(kn);
- rdtgroup_remove(rdtgrp);
- } else {
- kernfs_unbreak_active_protection(kn);
- }
+ rdtgroup_kn_put(rdtgrp, kn);
}
static int mkdir_mondata_all(struct kernfs_node *parent_kn,
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-06-07 10:53 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 12:50 [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
2023-04-19 12:50 ` [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-04-19 12:50 ` [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-04-19 12:50 ` [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature Peter Newman
2023-06-07 10:52 ` [tip: x86/cache] " tip-bot2 for Peter Newman
2023-05-03 14:50 ` [PATCH v6 0/3] x86/resctrl: Implement rename to help move containers' tasks Moger, Babu
2023-06-01 21:38 ` Reinette Chatre
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®