sched, cgroup: replace signal_struct->group_rwsem with a global percpu_rwsem
Note: This commit was originally committed asd59cfc09c3
but got reverted by0c986253b9
due to the performance regression from the percpu_rwsem write down/up operations added to cgroup task migration path. percpu_rwsem changes which alleviate the performance issue are pending for v4.4-rc1 merge window. Re-apply. The cgroup side of threadgroup locking uses signal_struct->group_rwsem to synchronize against threadgroup changes. This per-process rwsem adds small overhead to thread creation, exit and exec paths, forces cgroup code paths to do lock-verify-unlock-retry dance in a couple places and makes it impossible to atomically perform operations across multiple processes. This patch replaces signal_struct->group_rwsem with a global percpu_rwsem cgroup_threadgroup_rwsem which is cheaper on the reader side and contained in cgroups proper. This patch converts one-to-one. This does make writer side heavier and lower the granularity; however, cgroup process migration is a fairly cold path, we do want to optimize thread operations over it and cgroup migration operations don't take enough time for the lower granularity to matter. Signed-off-by: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/g/55F8097A.7000206@de.ibm.com Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org>
This commit is contained in:
@@ -473,8 +473,31 @@ struct cgroup_subsys {
|
||||
unsigned int depends_on;
|
||||
};
|
||||
|
||||
void cgroup_threadgroup_change_begin(struct task_struct *tsk);
|
||||
void cgroup_threadgroup_change_end(struct task_struct *tsk);
|
||||
extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
|
||||
|
||||
/**
|
||||
* cgroup_threadgroup_change_begin - threadgroup exclusion for cgroups
|
||||
* @tsk: target task
|
||||
*
|
||||
* Called from threadgroup_change_begin() and allows cgroup operations to
|
||||
* synchronize against threadgroup changes using a percpu_rw_semaphore.
|
||||
*/
|
||||
static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk)
|
||||
{
|
||||
percpu_down_read(&cgroup_threadgroup_rwsem);
|
||||
}
|
||||
|
||||
/**
|
||||
* cgroup_threadgroup_change_end - threadgroup exclusion for cgroups
|
||||
* @tsk: target task
|
||||
*
|
||||
* Called from threadgroup_change_end(). Counterpart of
|
||||
* cgroup_threadcgroup_change_begin().
|
||||
*/
|
||||
static inline void cgroup_threadgroup_change_end(struct task_struct *tsk)
|
||||
{
|
||||
percpu_up_read(&cgroup_threadgroup_rwsem);
|
||||
}
|
||||
|
||||
#else /* CONFIG_CGROUPS */
|
||||
|
||||
|
@@ -25,13 +25,6 @@
|
||||
extern struct files_struct init_files;
|
||||
extern struct fs_struct init_fs;
|
||||
|
||||
#ifdef CONFIG_CGROUPS
|
||||
#define INIT_GROUP_RWSEM(sig) \
|
||||
.group_rwsem = __RWSEM_INITIALIZER(sig.group_rwsem),
|
||||
#else
|
||||
#define INIT_GROUP_RWSEM(sig)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CPUSETS
|
||||
#define INIT_CPUSET_SEQ(tsk) \
|
||||
.mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq),
|
||||
@@ -64,7 +57,6 @@ extern struct fs_struct init_fs;
|
||||
INIT_PREV_CPUTIME(sig) \
|
||||
.cred_guard_mutex = \
|
||||
__MUTEX_INITIALIZER(sig.cred_guard_mutex), \
|
||||
INIT_GROUP_RWSEM(sig) \
|
||||
}
|
||||
|
||||
extern struct nsproxy init_nsproxy;
|
||||
|
@@ -762,18 +762,6 @@ struct signal_struct {
|
||||
unsigned audit_tty_log_passwd;
|
||||
struct tty_audit_buf *tty_audit_buf;
|
||||
#endif
|
||||
#ifdef CONFIG_CGROUPS
|
||||
/*
|
||||
* group_rwsem prevents new tasks from entering the threadgroup and
|
||||
* member tasks from exiting,a more specifically, setting of
|
||||
* PF_EXITING. fork and exit paths are protected with this rwsem
|
||||
* using threadgroup_change_begin/end(). Users which require
|
||||
* threadgroup to remain stable should use threadgroup_[un]lock()
|
||||
* which also takes care of exec path. Currently, cgroup is the
|
||||
* only user.
|
||||
*/
|
||||
struct rw_semaphore group_rwsem;
|
||||
#endif
|
||||
|
||||
oom_flags_t oom_flags;
|
||||
short oom_score_adj; /* OOM kill score adjustment */
|
||||
|
Reference in New Issue
Block a user