Some optimizations about freezer
v3 cover Some optimizations about freezer
I optimized the freezer to reduce redundant loops, and I add helper to make code concise.
The following subtree was tested to prove whether my optimizations are effective.
0
/ | \ \
A B C 1
/ | \ \
A B C 2
.....
n
/ | \
A B CI tested by following steps:
1. freeze 0
2. unfreeze 0
3. freeze 0
4. freeze 1
And I measured the elapsed time(ns).
n=10
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 106179390 94016050 110423650 95063770
AFTER 96473608 91054188 94936398 93198510
n=50
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 109506660 105643800 105970220 96948940
AFTER 105244651 97357482 97517358 88466266
n=100
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 127944210 122049330 120988900 101232850
AFTER 117298106 107034146 105696895 91977833
As shown above, after optimizations, it can save elapsed time. By freezing 0 and subsequently freezing 1, the elapsed time is consistent, indicating that my optimizations are highly effective.
---
v3:
- fix build warnings reported-by kernel test robot.
v2:
- open code inside the loop of cgroup_freeze instead of inline function.
- add helper to make code concise.
- remove selftest script(There are hierarchy test in test_freeze.c, I think that is enough for this series).
Chen Ridong (3):
cgroup/freezer: Reduce redundant traversal for cgroup_freeze cgroup/freezer: Add cgroup CGRP_FROZEN flag update helper cgroup/freezer: Reduce redundant propagation for
cgroup_propagate_frozen
include/linux/cgroup-defs.h | 6 +- kernel/cgroup/freezer.c | 110 ++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 57 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/3 cgroup/freezer: Reduce redundant traversal for cgroup_freeze
Whether a cgroup is frozen is determined solely by whether it is set to to be frozen and whether its parent is frozen. Currently, when is cgroup is frozen or unfrozen, it iterates through the entire subtree to freeze or unfreeze its descentdants. However, this is unesessary for a cgroup that does not change its effective frozen status. This path aims to skip the subtree if its parent does not have a change in effective freeze.
For an example, subtree like, a-b-c-d-e-f-g, when a is frozen, the entire tree is frozen. If we freeze b and c again, it is unesessary to iterate d, e, f and g. So does that If we unfreeze b/c.
--- include/linux/cgroup-defs.h | 2 +- kernel/cgroup/freezer.c | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-)
include/linux/cgroup-defs.h +1 -1
@@ -397,7 +397,7 @@ struct cgroup_freezer_state {bool freeze;/* Should the cgroup actually be frozen? */ -int e_freeze; +bool e_freeze;/* Fields below are protected by css_set_lock */
kernel/cgroup/freezer.c +14 -16
@@ -260,8 +260,10 @@ void cgroup_freezer_migrate_task(struct task_struct *task,void cgroup_freeze (struct cgroup *cgrp,bool freeze) {struct cgroup_subsys_state *css; +struct cgroup *parent;struct cgroup *dsct;bool applied = false; +bool old_e;lockdep_assert_held (&cgroup_mutex);
@@ -282,22 +284,18 @@ void cgroup_freeze(struct cgroup *cgrp, bool freeze)if (cgroup_is_dead (dsct))continue ; -if (freeze) { - dsct->freezer.e_freeze++; -/* -* Already frozen because of ancestor's settings? -*/ -if (dsct->freezer.e_freeze >1 ) -continue ; - }else { - dsct->freezer.e_freeze--; -/* -* Still frozen because of ancestor's settings? -*/ -if (dsct->freezer.e_freeze >0 ) -continue ; - -WARN_ON_ONCE (dsct->freezer.e_freeze <0 ); +/* +* e_freeze is affected by parent's e_freeze and dst's freeze. +* If old e_freeze eq new e_freeze, no change, its children +* will not be affected. So do nothing and skip the subtree +*/ + old_e = dsct->freezer.e_freeze; + parent =cgroup_parent (dsct); + dsct->freezer.e_freeze = (dsct->freezer.freeze || + parent->freezer.e_freeze); +if (dsct->freezer.e_freeze == old_e) { + css =css_rightmost_descendant (css); +continue ; }/*
Signature · 1 line
2.34.1
Re: [PATHC v3 -next 1/3] cgroup/freezer: Reduce redundant traversal for cgroup_freeze
Quoted 5 lines · Chen Ridong
Signed-off-by Chen Ridong <[email protected]>--- include/linux/cgroup-defs.h | 2 +- kernel/cgroup/freezer.c | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-)
PATCH v3 2/3 cgroup/freezer: Add cgroup CGRP_FROZEN flag update helper
In reply to Chen RidongAdd help to update cgroup CGRP_FROZEN flag. Both cgroup_propagate_frozen and cgroup_update_frozen functions update CGRP_FROZEN flag, this makes code concise.
--- kernel/cgroup/freezer.c | 67 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 35 deletions(-)
kernel/cgroup/freezer.c +32 -35
@@ -8,6 +8,28 @@#include <trace/events/cgroup.h> +/* +* Update CGRP_FROZEN of cgroup.flag +* Return true if flags is updated; false if flags has no change +*/ +static bool cgroup_update_frozen_flag (struct cgroup *cgrp,bool frozen) +{ +lockdep_assert_held (&css_set_lock); + +/* Already there? */ +if (test_bit (CGRP_FROZEN , &cgrp->flags) == frozen) +return false; + +if (frozen) +set_bit (CGRP_FROZEN , &cgrp->flags); +else +clear_bit (CGRP_FROZEN , &cgrp->flags); + +cgroup_file_notify (&cgrp->events_file); +TRACE_CGROUP_PATH (notify_frozen, cgrp, frozen); +return true; +} +/* * Propagate the cgroup frozen state upwards by the cgroup tree. */
@@ -24,24 +46,16 @@ static void cgroup_propagate_frozen(struct cgroup *cgrp, bool frozen)while ((cgrp =cgroup_parent (cgrp))) {if (frozen) { cgrp->freezer.nr_frozen_descendants += desc; -if (!test_bit (CGRP_FROZEN , &cgrp->flags) && -test_bit (CGRP_FREEZE , &cgrp->flags) && - cgrp->freezer.nr_frozen_descendants == - cgrp->nr_descendants) { -set_bit (CGRP_FROZEN , &cgrp->flags); -cgroup_file_notify (&cgrp->events_file); -TRACE_CGROUP_PATH (notify_frozen, cgrp,1 ); - desc++; - } +if (!test_bit (CGRP_FREEZE , &cgrp->flags) || + (cgrp->freezer.nr_frozen_descendants != + cgrp->nr_descendants)) +continue ; }else { cgrp->freezer.nr_frozen_descendants -= desc; -if (test_bit (CGRP_FROZEN , &cgrp->flags)) { -clear_bit (CGRP_FROZEN , &cgrp->flags); -cgroup_file_notify (&cgrp->events_file); -TRACE_CGROUP_PATH (notify_frozen, cgrp,0 ); - desc++; - } } + +if (cgroup_update_frozen_flag (cgrp, frozen)) + desc++; } }
@@ -53,8 +67,6 @@ void cgroup_update_frozen(struct cgroup *cgrp) {bool frozen; -lockdep_assert_held (&css_set_lock); -/* * If the cgroup has to be frozen (CGRP_FREEZE bit set), * and all tasks are frozen and/or stopped, let's consider
@@ -63,24 +75,9 @@ void cgroup_update_frozen(struct cgroup *cgrp) frozen =test_bit (CGRP_FREEZE , &cgrp->flags) && cgrp->freezer.nr_frozen_tasks ==__cgroup_task_count (cgrp); -if (frozen) { -/* Already there? */ -if (test_bit (CGRP_FROZEN , &cgrp->flags)) -return ; - -set_bit (CGRP_FROZEN , &cgrp->flags); - }else { -/* Already there? */ -if (!test_bit (CGRP_FROZEN , &cgrp->flags)) -return ; - -clear_bit (CGRP_FROZEN , &cgrp->flags); - } -cgroup_file_notify (&cgrp->events_file); -TRACE_CGROUP_PATH (notify_frozen, cgrp, frozen); - -/* Update the state of ancestor cgroups. */ -cgroup_propagate_frozen (cgrp, frozen); +/* If flags is updated, update the state of ancestor cgroups. */ +if (cgroup_update_frozen_flag (cgrp, frozen)) +cgroup_propagate_frozen (cgrp, frozen); }/*
Signature · 1 line
2.34.1
Re: [PATHC v3 -next 2/3] cgroup/freezer: Add cgroup CGRP_FROZEN flag update helper
Quoted 8 lines · Chen Ridong
Add help to update cgroup
CGRP_FROZENflag. Bothcgroup_propagate_frozenandcgroup_update_frozenfunctions updateCGRP_FROZENflag, this makes code concise.Signed-off-by Chen Ridong <[email protected]>--- kernel/cgroup/freezer.c | 67 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 35 deletions(-)
PATCH v3 3/3 cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen
In reply to Chen RidongWhen a cgroup is frozen/unfrozen, it will always propagate bottom up. However it is unnecessary to propagate to the top every time. This patch aims to reduce redundant propagation for cgroup_propagate_frozen.
For example, subtree like:
a
|
b
/ | \
c d eIf c is frozen, and d and e are not frozen now, it doesn't have to propagate to a; Only when c, d and e are all frozen, b and a could be set to frozen. Therefore, if nr_frozen_descendants is not equal to nr_descendants, just stop propagate. If a descendant is frozen, the parent's nr_frozen_descendants add child->nr_descendants + 1. This can reduce redundant propagation.
Additionally, cgroup_propagate_frozen is not only used to update the ancestor state but also to update itself. This approach can make the code clearer and significantly simplify cgroup_update_frozen.
--- include/linux/cgroup-defs.h | 4 +++- kernel/cgroup/freezer.c | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-)
include/linux/cgroup-defs.h +3 -1
@@ -401,7 +401,9 @@ struct cgroup_freezer_state {/* Fields below are protected by css_set_lock */ -/* Number of frozen descendant cgroups */ +/* Aggregating frozen descendant cgroups, only when all +* descendants of a child are frozen will the count increase. +*/ int nr_frozen_descendants;/*
kernel/cgroup/freezer.c +17 -12
@@ -35,27 +35,34 @@ static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen)*/ static void cgroup_propagate_frozen (struct cgroup *cgrp,bool frozen) { -int desc =1 ; - +int deta; +struct cgroup *parent;/* * If the new state is frozen, some freezing ancestor cgroups may change * their state too, depending on if all their descendants are frozen. * * Otherwise, all ancestor cgroups are forced into the non-frozen state. */ -while ((cgrp =cgroup_parent (cgrp))) { +for (; cgrp; cgrp =cgroup_parent (cgrp)) {if (frozen) { - cgrp->freezer.nr_frozen_descendants += desc; +/* If freezer is not set, or cgrp has descendants +* that are not frozen, cgrp can't be frozen +*/ if (!test_bit (CGRP_FREEZE , &cgrp->flags) || (cgrp->freezer.nr_frozen_descendants != - cgrp->nr_descendants)) -continue ; + cgrp->nr_descendants)) +break ; + deta = cgrp->freezer.nr_frozen_descendants +1 ; }else { - cgrp->freezer.nr_frozen_descendants -= desc; + deta = -(cgrp->freezer.nr_frozen_descendants +1 ); } -if (cgroup_update_frozen_flag (cgrp, frozen)) - desc++; +/* No change, stop propagate */ +if (!cgroup_update_frozen_flag (cgrp, frozen)) +break ; + + parent =cgroup_parent (cgrp); + parent->freezer.nr_frozen_descendants += deta; } }
@@ -75,9 +82,7 @@ void cgroup_update_frozen(struct cgroup *cgrp) frozen =test_bit (CGRP_FREEZE , &cgrp->flags) && cgrp->freezer.nr_frozen_tasks ==__cgroup_task_count (cgrp); -/* If flags is updated, update the state of ancestor cgroups. */ -if (cgroup_update_frozen_flag (cgrp, frozen)) -cgroup_propagate_frozen (cgrp, frozen); +cgroup_propagate_frozen (cgrp, frozen); }/*
Signature · 1 line
2.34.1
Michal Koutný
maintainerRe: [PATHC v3 -next 3/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen
Quoted 20 lines · Chen Ridong
include/linux/cgroup-defs.h +3
-1@@ -401,7 +401,9 @@ struct cgroup_freezer_state {/* Fields below are protected by css_set_lock */ -/* Number of frozen descendant cgroups */ +/* Aggregating frozen descendant cgroups, only when all +* descendants of a child are frozen will the count increase. +*/ int nr_frozen_descendants;/* kernel/cgroup/freezer.c +0
-0
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 38
Quoted 6 lines
kernel/cgroup/freezer.c +1
-2@@ -35,27 +35,34 @@ static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen)*/ static void cgroup_propagate_frozen (struct cgroup *cgrp,bool frozen) { -int desc =1 ; - +int deta;
delta
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 39
Quoted 1 line
kernel/cgroup/freezer.c +1
-0+struct cgroup *parent;
I'd suggest here something like
/* root cgroup never changes freeze state */ if (WARN_ON(cgroup_parent(cgrp)) return;
so that the parent-> dereference below is explicitly safe.
Quoted 13 lines
kernel/cgroup/freezer.c +4
-2/* * If the new state is frozen, some freezing ancestor cgroups may change * their state too, depending on if all their descendants are frozen. * * Otherwise, all ancestor cgroups are forced into the non-frozen state. */ -while ((cgrp =cgroup_parent (cgrp))) { +for (; cgrp; cgrp =cgroup_parent (cgrp)) {if (frozen) { - cgrp->freezer.nr_frozen_descendants += desc; +/* If freezer is not set, or cgrp has descendants +* that are not frozen, cgrp can't be frozen +*/
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 57
Quoted 10 lines
kernel/cgroup/freezer.c +4
-3if (!test_bit (CGRP_FREEZE , &cgrp->flags) || (cgrp->freezer.nr_frozen_descendants != - cgrp->nr_descendants)) -continue ; + cgrp->nr_descendants)) +break ; + deta = cgrp->freezer.nr_frozen_descendants +1 ; }else { - cgrp->freezer.nr_frozen_descendants -= desc; + deta = -(cgrp->freezer.nr_frozen_descendants +1 );
In this branch, if cgrp is unfrozen, delta = -1 is cgrp itself, however is delta = -cgrp->freezer.nr_frozen_descendants warranted? What if they are frozen empty children (of cgrp)? They likely shouldn't be subtracted from ancestors nf_frozen_descendants.
(This refers to a situation when
C CGRP_FREEZE is set
|\
D E both CGRP_FREEZE is set
and an unfrozen task is migrated into C which would make C (temporarily) unfrozen but not D nor E.)
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 65
Quoted 10 lines
kernel/cgroup/freezer.c +6
-2} -if (cgroup_update_frozen_flag (cgrp, frozen)) - desc++; +/* No change, stop propagate */ +if (!cgroup_update_frozen_flag (cgrp, frozen)) +break ; + + parent =cgroup_parent (cgrp); + parent->freezer.nr_frozen_descendants += deta;
Thanks,
Michal
Re: [PATHC v3 -next 3/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen
Quoted 68 lines · Michal Koutný
Quoted 20 lines · Chen Ridong
include/linux/cgroup-defs.h +3
-1@@ -401,7 +401,9 @@ struct cgroup_freezer_state {/* Fields below are protected by css_set_lock */ -/* Number of frozen descendant cgroups */ +/* Aggregating frozen descendant cgroups, only when all +* descendants of a child are frozen will the count increase. +*/ int nr_frozen_descendants;/* kernel/cgroup/freezer.c +0
-0kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 38
Quoted 6 lines
kernel/cgroup/freezer.c +1
-2@@ -35,27 +35,34 @@ static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen)*/ static void cgroup_propagate_frozen (struct cgroup *cgrp,bool frozen) { -int desc =1 ; - +int deta;delta
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 39
Quoted 1 line
kernel/cgroup/freezer.c +1
-0+struct cgroup *parent;I'd suggest here something like
/* root cgroup never changes freeze state */ if (WARN_ON(cgroup_parent(cgrp)) return;so that the parent-> dereference below is explicitly safe.
Quoted 13 lines
kernel/cgroup/freezer.c +4
-2/* * If the new state is frozen, some freezing ancestor cgroups may change * their state too, depending on if all their descendants are frozen. * * Otherwise, all ancestor cgroups are forced into the non-frozen state. */ -while ((cgrp =cgroup_parent (cgrp))) { +for (; cgrp; cgrp =cgroup_parent (cgrp)) {if (frozen) { - cgrp->freezer.nr_frozen_descendants += desc; +/* If freezer is not set, or cgrp has descendants +* that are not frozen, cgrp can't be frozen +*/ kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 57
Quoted 10 lines
kernel/cgroup/freezer.c +4
-3if (!test_bit (CGRP_FREEZE , &cgrp->flags) || (cgrp->freezer.nr_frozen_descendants != - cgrp->nr_descendants)) -continue ; + cgrp->nr_descendants)) +break ; + deta = cgrp->freezer.nr_frozen_descendants +1 ; }else { - cgrp->freezer.nr_frozen_descendants -= desc; + deta = -(cgrp->freezer.nr_frozen_descendants +1 );In this branch, if cgrp is unfrozen, delta = -1 is cgrp itself, however is delta = -cgrp->freezer.nr_frozen_descendants warranted? What if they are frozen empty children (of cgrp)? They likely shouldn't be subtracted from ancestors
nf_frozen_descendants.
Quoted 9 lines
(This refers to a situation when
C
CGRP_FREEZEis set
|\
D E bothCGRP_FREEZEis setand an unfrozen task is migrated into C which would make C (temporarily) unfrozen but not D nor E.)
Thank you, Michal.
I sorry I missed this situation.
If unfreezing a cgroup, it seems it has to propagate to the top.
After consideration, I modify this function.
the following is acceptable?
/*
* Propagate the cgroup frozen state upwards by the cgroup tree. */
static void cgroup_propagate_frozen(struct cgroup *cgrp, bool frozen)
{
int deta = 0;
struct cgroup *parent;
/*
* case1: If the new state is frozen, some freezing ancestor cgroups may change
* their state too, depending on if all their descendants are frozen. *
* case2: unfrozen, all ancestor cgroups are forced into the non-frozen
state.
*/
for (; cgrp; cgrp = cgroup_parent(cgrp)) {
if (frozen) {
/* If freezer is not set, or cgrp has descendants
* that are not frozen, cgrp can't be frozen
*/
if (!test_bit(CGRP_FREEZE, &cgrp->flags) ||
(cgrp->freezer.nr_frozen_descendants !=
cgrp->nr_descendants))
break;
/* No change, stop propagate */
if (!cgroup_update_frozen_flag(cgrp, frozen))
break;
deta = cgrp->freezer.nr_frozen_descendants + 1;
} else {
/* case2: have to propagate all ancestor */
if (cgroup_update_frozen_flag(cgrp, frozen))
deta++;
}
parent = cgroup_parent(cgrp);
parent->freezer.nr_frozen_descendants += deta;
}
}Best regards,
Ridong
Re: [PATHC v3 -next 3/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen
Quoted 120 lines · Chen Ridong
Quoted 66 lines · Michal Koutný
Quoted 17 lines · Chen Ridong
include/linux/cgroup-defs.h +3
-1@@ -401,7 +401,9 @@ struct cgroup_freezer_state { /* Fields below are protected by css_set_lock */ - /* Number of frozen descendant cgroups */ + /* Aggregating frozen descendant cgroups, only when all + * descendants of a child are frozen will the count increase. + */ int nr_frozen_descendants; /*kernel/cgroup/freezer.c +0
-0kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct · line 39
Quoted 7 lines
kernel/cgroup/freezer.c +1
-2@@ -35,27 +35,34 @@ static bool cgroup_update_frozen_flag(structcgroup *cgrp, bool frozen) */ static void cgroup_propagate_frozen(struct cgroup *cgrp, bool frozen) { - int desc = 1; - + int deta;delta
kernel/cgroup/freezer.c static bool cgroup_update_frozen_flag(struct cgroup *cgrp, bool frozen) · line 39
Quoted 1 line
kernel/cgroup/freezer.c +1
-0+ struct cgroup *parent;I'd suggest here something like
/* root cgroup never changes freeze state */
if (WARN_ON(cgroup_parent(cgrp))
return;so that the parent-> dereference below is explicitly safe.
Quoted 15 lines
kernel/cgroup/freezer.c +4
-2/* * If the new state is frozen, some freezing ancestor cgroups may change * their state too, depending on if all their descendants are frozen. * * Otherwise, all ancestor cgroups are forced into the non-frozen state. */ - while ((cgrp = cgroup_parent(cgrp))) { + for (; cgrp; cgrp = cgroup_parent(cgrp)) { if (frozen) { - cgrp->freezer.nr_frozen_descendants += desc; + /* If freezer is not set, or cgrp has descendants +* that are not frozen, cgrp can't be frozen +*/ if (!test_bit(CGRP_FREEZE,
&cgrp->flags) || (cgrp->freezer.nr_frozen_descendants!=Quoted 8 lines
-
cgrp->nr_descendants))
- continue;
+cgrp->nr_descendants))
+ break;
+ deta =cgrp->freezer.nr_frozen_descendants+ 1; } else {
-cgrp->freezer.nr_frozen_descendants-= desc; + deta = -(cgrp->freezer.nr_frozen_descendants + 1);In this branch, if cgrp is unfrozen, delta = -1 is cgrp itself, however is delta = -cgrp->freezer.nr_frozen_descendants warranted? What if they are frozen empty children (of cgrp)? They likely shouldn't be subtracted from ancestors
nf_frozen_descendants.Quoted 9 lines
(This refers to a situation when
C
CGRP_FREEZEis set
|\
D E bothCGRP_FREEZEis setand an unfrozen task is migrated into C which would make C (temporarily) unfrozen but not D nor E.)
Thank you, Michal.
I sorry I missed this situation.
If unfreezing a cgroup, it seems it has to propagate to the top.After consideration, I modify this function.
the following is acceptable?/*
* Propagate the cgroup frozen state upwards by the cgroup tree. */
static voidcgroup_propagate_frozen(struct cgroup *cgrp, bool frozen){
int deta = 0;
struct cgroup *parent;
/*
* case1: If the new state is frozen, some freezing ancestor
cgroups may change
* their state too, depending on if all their descendants are frozen. *
* case2: unfrozen, all ancestor cgroups are forced into the
non-frozen state.
*/
for (; cgrp; cgrp =cgroup_parent(cgrp)) {
if (frozen) {
/* If freezer is not set, or cgrp has descendants
* that are not frozen, cgrp can't be frozen
*/
if (!test_bit(CGRP_FREEZE,&cgrp->flags) || (cgrp->freezer.nr_frozen_descendants!=cgrp->nr_descendants))
break;
/* No change, stop propagate */
if (!cgroup_update_frozen_flag(cgrp, frozen)) break;
deta =cgrp->freezer.nr_frozen_descendants+ 1;
} else {
/* case2: have to propagate all ancestor */
if (cgroup_update_frozen_flag(cgrp, frozen)) deta++;
}
Quoted 8 lines
parent =
cgroup_parent(cgrp);parent->freezer.nr_frozen_descendants+= deta; }
}Best regards,
Ridong
Hi, Michal, Do you think this can be acceptable?
I don't have a better idea, If you have a better a idea, please let me know.
Best regards,
Ridong
Quoted 58 lines · Chen Ridong
I optimized the freezer to reduce redundant loops, and I add helper to make code concise.
The following subtree was tested to prove whether my optimizations are effective.
0 / | \ \ A B C 1 / | \ \ A B C 2 ..... n / | \ A B CI tested by following steps:
1. freeze 0
2. unfreeze 0
3. freeze 0
4. freeze 1And I measured the elapsed time(ns).
n=10
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 106179390 94016050 110423650 95063770
AFTER 96473608 91054188 94936398 93198510n=50
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 109506660 105643800 105970220 96948940
AFTER 105244651 97357482 97517358 88466266n=100
freeze 0 unfreeze 0 freeze 0 freeze 1
BEFORE 127944210 122049330 120988900 101232850
AFTER 117298106 107034146 105696895 91977833As shown above, after optimizations, it can save elapsed time. By freezing 0 and subsequently freezing 1, the elapsed time is consistent, indicating that my optimizations are highly effective.
---
v3:
- fix build warnings reported-by kernel test robot.v2:
- open code inside the loop ofcgroup_freezeinstead of inline function.
- add helper to make code concise.
- remove selftestscript(There are hierarchy test in test_freeze.c, I think that is enough for this series).Chen Ridong (3):
cgroup/freezer: Reduce redundant traversal forcgroup_freezecgroup/freezer: Add cgroupCGRP_FROZENflag update helper cgroup/freezer: Reduce redundant propagation for
cgroup_propagate_frozen
Quoted 4 lines
include/linux/cgroup-defs.h | 6 +- kernel/cgroup/freezer.c | 110 ++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 57 deletions(-)
Friendly ping.
Best regards,
Ridong
Tejun Heo
maintainerQuoted 1 line · chenridong
Friendly ping.
Will apply after the merge window.
Thanks.
Signature · 1 line
tejun
Quoted 7 lines · Tejun Heo
Quoted 1 line · chenridong
Friendly ping.
Will apply after the merge window.
Thanks.
Thank you.
Best regards,
Ridong