Skip to content

Commit 6e2332e

Browse files
committed
Merge tag 'cgroup-for-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup updates from Tejun Heo: - Whenever cpuset needs to rebuild sched_domain, it walked all tasks looking for DEADLINE tasks as they need to be accounted on the new domain. Walking all tasks can be expensive and there may not be any DEADLINE tasks at all. Task iteration is now omitted if there are no DEADLINE tasks - Fixes DEADLINE bandwidth misaccounting after task migration failures - When no controller is enabled, -Wstringop-overflow warning is triggered. The fix patch added an early exit which is too eager and got reverted for now. Will fix later - Everything else is minor cleanups * tag 'cgroup-for-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: Revert "cgroup: Avoid -Wstringop-overflow warnings" cgroup/misc: Expose misc.current on cgroup v2 root cgroup: Avoid -Wstringop-overflow warnings cgroup: remove obsolete comment on cgroup_on_dfl() cgroup: remove unused task_cgroup_path() cgroup/cpuset: remove unneeded header files cgroup: make cgroup_is_threaded() and cgroup_is_thread_root() static rdmacg: fix kernel-doc warnings in rdmacg cgroup: Replace the css_set call with cgroup_get cgroup: remove unused macro for_each_e_css() cgroup: Update out-of-date comment in cgroup_migrate() cgroup: Replace all non-returning strlcpy with strscpy cgroup/cpuset: remove unneeded header files cgroup/cpuset: Free DL BW in case can_attach() fails sched/deadline: Create DL BW alloc, free & check overflow interface cgroup/cpuset: Iterate only if DEADLINE tasks are present sched/cpuset: Keep track of SCHED_DEADLINE task in cpusets sched/cpuset: Bring back cpuset_mutex cgroup/cpuset: Rename functions dealing with DEADLINE accounting
2 parents 72dc6db + 8162143 commit 6e2332e

13 files changed

Lines changed: 257 additions & 220 deletions

File tree

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ Miscellaneous controller provides 3 interface files. If two misc resources (res_
24432443
res_b 10
24442444

24452445
misc.current
2446-
A read-only flat-keyed file shown in the non-root cgroups. It shows
2446+
A read-only flat-keyed file shown in the all cgroups. It shows
24472447
the current usage of the resources in the cgroup and its children.::
24482448

24492449
$ cat misc.current

include/linux/cgroup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ int cgroup_rm_cftypes(struct cftype *cfts);
118118
void cgroup_file_notify(struct cgroup_file *cfile);
119119
void cgroup_file_show(struct cgroup_file *cfile, bool show);
120120

121-
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
122121
int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry);
123122
int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns,
124123
struct pid *pid, struct task_struct *tsk);

include/linux/cpuset.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ extern void cpuset_init_smp(void);
7171
extern void cpuset_force_rebuild(void);
7272
extern void cpuset_update_active_cpus(void);
7373
extern void cpuset_wait_for_hotplug(void);
74-
extern void cpuset_read_lock(void);
75-
extern void cpuset_read_unlock(void);
74+
extern void inc_dl_tasks_cs(struct task_struct *task);
75+
extern void dec_dl_tasks_cs(struct task_struct *task);
76+
extern void cpuset_lock(void);
77+
extern void cpuset_unlock(void);
7678
extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
7779
extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
7880
extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
@@ -189,8 +191,10 @@ static inline void cpuset_update_active_cpus(void)
189191

190192
static inline void cpuset_wait_for_hotplug(void) { }
191193

192-
static inline void cpuset_read_lock(void) { }
193-
static inline void cpuset_read_unlock(void) { }
194+
static inline void inc_dl_tasks_cs(struct task_struct *task) { }
195+
static inline void dec_dl_tasks_cs(struct task_struct *task) { }
196+
static inline void cpuset_lock(void) { }
197+
static inline void cpuset_unlock(void) { }
194198

195199
static inline void cpuset_cpus_allowed(struct task_struct *p,
196200
struct cpumask *mask)

include/linux/sched.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,9 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
18521852
}
18531853

18541854
extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
1855-
extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_effective_cpus);
1855+
extern int task_can_attach(struct task_struct *p);
1856+
extern int dl_bw_alloc(int cpu, u64 dl_bw);
1857+
extern void dl_bw_free(int cpu, u64 dl_bw);
18561858
#ifdef CONFIG_SMP
18571859
extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask);
18581860
extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask);

kernel/cgroup/cgroup-internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ static inline void get_css_set(struct css_set *cset)
220220

221221
bool cgroup_ssid_enabled(int ssid);
222222
bool cgroup_on_dfl(const struct cgroup *cgrp);
223-
bool cgroup_is_thread_root(struct cgroup *cgrp);
224-
bool cgroup_is_threaded(struct cgroup *cgrp);
225223

226224
struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root);
227225
struct cgroup *task_cgroup_from_root(struct task_struct *task,

kernel/cgroup/cgroup-v1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
563563
if (!cgrp)
564564
return -ENODEV;
565565
spin_lock(&release_agent_path_lock);
566-
strlcpy(cgrp->root->release_agent_path, strstrip(buf),
566+
strscpy(cgrp->root->release_agent_path, strstrip(buf),
567567
sizeof(cgrp->root->release_agent_path));
568568
spin_unlock(&release_agent_path_lock);
569569
cgroup_kn_unlock(of->kn);
@@ -797,7 +797,7 @@ void cgroup1_release_agent(struct work_struct *work)
797797
goto out_free;
798798

799799
spin_lock(&release_agent_path_lock);
800-
strlcpy(agentbuf, cgrp->root->release_agent_path, PATH_MAX);
800+
strscpy(agentbuf, cgrp->root->release_agent_path, PATH_MAX);
801801
spin_unlock(&release_agent_path_lock);
802802
if (!agentbuf[0])
803803
goto out_free;

kernel/cgroup/cgroup.c

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/file.h>
5858
#include <linux/fs_parser.h>
5959
#include <linux/sched/cputime.h>
60+
#include <linux/sched/deadline.h>
6061
#include <linux/psi.h>
6162
#include <net/sock.h>
6263

@@ -312,8 +313,6 @@ bool cgroup_ssid_enabled(int ssid)
312313
* masks of ancestors.
313314
*
314315
* - blkcg: blk-throttle becomes properly hierarchical.
315-
*
316-
* - debug: disallowed on the default hierarchy.
317316
*/
318317
bool cgroup_on_dfl(const struct cgroup *cgrp)
319318
{
@@ -356,7 +355,7 @@ static bool cgroup_has_tasks(struct cgroup *cgrp)
356355
return cgrp->nr_populated_csets;
357356
}
358357

359-
bool cgroup_is_threaded(struct cgroup *cgrp)
358+
static bool cgroup_is_threaded(struct cgroup *cgrp)
360359
{
361360
return cgrp->dom_cgrp != cgrp;
362361
}
@@ -395,7 +394,7 @@ static bool cgroup_can_be_thread_root(struct cgroup *cgrp)
395394
}
396395

397396
/* is @cgrp root of a threaded subtree? */
398-
bool cgroup_is_thread_root(struct cgroup *cgrp)
397+
static bool cgroup_is_thread_root(struct cgroup *cgrp)
399398
{
400399
/* thread root should be a domain */
401400
if (cgroup_is_threaded(cgrp))
@@ -618,7 +617,7 @@ EXPORT_SYMBOL_GPL(cgroup_get_e_css);
618617
static void cgroup_get_live(struct cgroup *cgrp)
619618
{
620619
WARN_ON_ONCE(cgroup_is_dead(cgrp));
621-
css_get(&cgrp->self);
620+
cgroup_get(cgrp);
622621
}
623622

624623
/**
@@ -689,21 +688,6 @@ EXPORT_SYMBOL_GPL(of_css);
689688
lockdep_is_held(&cgroup_mutex)))) { } \
690689
else
691690

692-
/**
693-
* for_each_e_css - iterate all effective css's of a cgroup
694-
* @css: the iteration cursor
695-
* @ssid: the index of the subsystem, CGROUP_SUBSYS_COUNT after reaching the end
696-
* @cgrp: the target cgroup to iterate css's of
697-
*
698-
* Should be called under cgroup_[tree_]mutex.
699-
*/
700-
#define for_each_e_css(css, ssid, cgrp) \
701-
for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT; (ssid)++) \
702-
if (!((css) = cgroup_e_css_by_mask(cgrp, \
703-
cgroup_subsys[(ssid)]))) \
704-
; \
705-
else
706-
707691
/**
708692
* do_each_subsys_mask - filter for_each_subsys with a bitmask
709693
* @ss: the iteration cursor
@@ -2392,45 +2376,6 @@ int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
23922376
}
23932377
EXPORT_SYMBOL_GPL(cgroup_path_ns);
23942378

2395-
/**
2396-
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
2397-
* @task: target task
2398-
* @buf: the buffer to write the path into
2399-
* @buflen: the length of the buffer
2400-
*
2401-
* Determine @task's cgroup on the first (the one with the lowest non-zero
2402-
* hierarchy_id) cgroup hierarchy and copy its path into @buf. This
2403-
* function grabs cgroup_mutex and shouldn't be used inside locks used by
2404-
* cgroup controller callbacks.
2405-
*
2406-
* Return value is the same as kernfs_path().
2407-
*/
2408-
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen)
2409-
{
2410-
struct cgroup_root *root;
2411-
struct cgroup *cgrp;
2412-
int hierarchy_id = 1;
2413-
int ret;
2414-
2415-
cgroup_lock();
2416-
spin_lock_irq(&css_set_lock);
2417-
2418-
root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id);
2419-
2420-
if (root) {
2421-
cgrp = task_cgroup_from_root(task, root);
2422-
ret = cgroup_path_ns_locked(cgrp, buf, buflen, &init_cgroup_ns);
2423-
} else {
2424-
/* if no hierarchy exists, everyone is in "/" */
2425-
ret = strscpy(buf, "/", buflen);
2426-
}
2427-
2428-
spin_unlock_irq(&css_set_lock);
2429-
cgroup_unlock();
2430-
return ret;
2431-
}
2432-
EXPORT_SYMBOL_GPL(task_cgroup_path);
2433-
24342379
/**
24352380
* cgroup_attach_lock - Lock for ->attach()
24362381
* @lock_threadgroup: whether to down_write cgroup_threadgroup_rwsem
@@ -2885,9 +2830,9 @@ int cgroup_migrate(struct task_struct *leader, bool threadgroup,
28852830
struct task_struct *task;
28862831

28872832
/*
2888-
* Prevent freeing of tasks while we take a snapshot. Tasks that are
2889-
* already PF_EXITING could be freed from underneath us unless we
2890-
* take an rcu_read_lock.
2833+
* The following thread iteration should be inside an RCU critical
2834+
* section to prevent tasks from being freed while taking the snapshot.
2835+
* spin_lock_irq() implies RCU critical section here.
28912836
*/
28922837
spin_lock_irq(&css_set_lock);
28932838
task = leader;
@@ -6708,6 +6653,9 @@ void cgroup_exit(struct task_struct *tsk)
67086653
list_add_tail(&tsk->cg_list, &cset->dying_tasks);
67096654
cset->nr_tasks--;
67106655

6656+
if (dl_task(tsk))
6657+
dec_dl_tasks_cs(tsk);
6658+
67116659
WARN_ON_ONCE(cgroup_task_frozen(tsk));
67126660
if (unlikely(!(tsk->flags & PF_KTHREAD) &&
67136661
test_bit(CGRP_FREEZE, &task_dfl_cgroup(tsk)->flags)))

0 commit comments

Comments
 (0)