Skip to content

Commit c8acec9

Browse files
htejungregkh
authored andcommitted
cpuset: consider dying css as offline
commit 41c25707d21716826e3c1f60967f5550610ec1c9 upstream. In most cases, a cgroup controller don't care about the liftimes of cgroups. For the controller, a css becomes online when ->css_online() is called on it and offline when ->css_offline() is called. However, cpuset is special in that the user interface it exposes cares whether certain cgroups exist or not. Combined with the RCU delay between cgroup removal and css offlining, this can lead to user visible behavior oddities where operations which should succeed after cgroup removals fail for some time period. The effects of cgroup removals are delayed when seen from userland. This patch adds css_is_dying() which tests whether offline is pending and updates is_cpuset_online() so that the function returns false also while offline is pending. This gets rid of the userland visible delays. Signed-off-by: Tejun Heo <tj@kernel.org> Reported-by: Daniel Jordan <daniel.m.jordan@oracle.com> Link: http://lkml.kernel.org/r/327ca1f5-7957-fbb9-9e5f-9ba149d40ba2@oracle.com Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fff08d2 commit c8acec9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

include/linux/cgroup.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,26 @@ static inline bool css_tryget_online(struct cgroup_subsys_state *css)
339339
return true;
340340
}
341341

342+
/**
343+
* css_is_dying - test whether the specified css is dying
344+
* @css: target css
345+
*
346+
* Test whether @css is in the process of offlining or already offline. In
347+
* most cases, ->css_online() and ->css_offline() callbacks should be
348+
* enough; however, the actual offline operations are RCU delayed and this
349+
* test returns %true also when @css is scheduled to be offlined.
350+
*
351+
* This is useful, for example, when the use case requires synchronous
352+
* behavior with respect to cgroup removal. cgroup removal schedules css
353+
* offlining but the css can seem alive while the operation is being
354+
* delayed. If the delay affects user visible semantics, this test can be
355+
* used to resolve the situation.
356+
*/
357+
static inline bool css_is_dying(struct cgroup_subsys_state *css)
358+
{
359+
return !(css->flags & CSS_NO_REF) && percpu_ref_is_dying(&css->refcnt);
360+
}
361+
342362
/**
343363
* css_put - put a css reference
344364
* @css: target css

kernel/cpuset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ typedef enum {
173173
} cpuset_flagbits_t;
174174

175175
/* convenient tests for these bits */
176-
static inline bool is_cpuset_online(const struct cpuset *cs)
176+
static inline bool is_cpuset_online(struct cpuset *cs)
177177
{
178-
return test_bit(CS_ONLINE, &cs->flags);
178+
return test_bit(CS_ONLINE, &cs->flags) && !css_is_dying(&cs->css);
179179
}
180180

181181
static inline int is_cpu_exclusive(const struct cpuset *cs)

0 commit comments

Comments
 (0)