diff options
author | Sha Zhengju <handai.szj@taobao.com> | 2012-05-29 18:06:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 19:22:25 -0400 |
commit | 748dad36d645f5c4517a115d60bb3a0e8f877ac0 (patch) | |
tree | 0f3206a06c3d58b922535957083d5216467eddb9 /mm | |
parent | a0db00fcf5da79911b7ff2db63ea7c0a5711e096 (diff) |
memcg: make threshold index in the right position
Index current_threshold may point to threshold that just equal to usage
after last call of __mem_cgroup_threshold. But after registering a new
event, it will change (pointing to threshold just below usage). So make
it consistent here.
For example:
now:
threshold array: 3 [5] 7 9 (usage = 6, [index] = 5)
next turn (after calling __mem_cgroup_threshold):
threshold array: 3 5 [7] 9 (usage = 7, [index] = 7)
after registering a new event (threshold = 10):
threshold array: 3 [5] 7 9 10 (usage = 7, [index] = 5)
Signed-off-by: Sha Zhengju <handai.szj@taobao.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 775b94b1b8b..a8abf919c70 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -181,7 +181,7 @@ struct mem_cgroup_threshold { | |||
181 | 181 | ||
182 | /* For threshold */ | 182 | /* For threshold */ |
183 | struct mem_cgroup_threshold_ary { | 183 | struct mem_cgroup_threshold_ary { |
184 | /* An array index points to threshold just below usage. */ | 184 | /* An array index points to threshold just below or equal to usage. */ |
185 | int current_threshold; | 185 | int current_threshold; |
186 | /* Size of entries[] */ | 186 | /* Size of entries[] */ |
187 | unsigned int size; | 187 | unsigned int size; |
@@ -4280,7 +4280,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) | |||
4280 | usage = mem_cgroup_usage(memcg, swap); | 4280 | usage = mem_cgroup_usage(memcg, swap); |
4281 | 4281 | ||
4282 | /* | 4282 | /* |
4283 | * current_threshold points to threshold just below usage. | 4283 | * current_threshold points to threshold just below or equal to usage. |
4284 | * If it's not true, a threshold was crossed after last | 4284 | * If it's not true, a threshold was crossed after last |
4285 | * call of __mem_cgroup_threshold(). | 4285 | * call of __mem_cgroup_threshold(). |
4286 | */ | 4286 | */ |
@@ -4406,14 +4406,15 @@ static int mem_cgroup_usage_register_event(struct cgroup *cgrp, | |||
4406 | /* Find current threshold */ | 4406 | /* Find current threshold */ |
4407 | new->current_threshold = -1; | 4407 | new->current_threshold = -1; |
4408 | for (i = 0; i < size; i++) { | 4408 | for (i = 0; i < size; i++) { |
4409 | if (new->entries[i].threshold < usage) { | 4409 | if (new->entries[i].threshold <= usage) { |
4410 | /* | 4410 | /* |
4411 | * new->current_threshold will not be used until | 4411 | * new->current_threshold will not be used until |
4412 | * rcu_assign_pointer(), so it's safe to increment | 4412 | * rcu_assign_pointer(), so it's safe to increment |
4413 | * it here. | 4413 | * it here. |
4414 | */ | 4414 | */ |
4415 | ++new->current_threshold; | 4415 | ++new->current_threshold; |
4416 | } | 4416 | } else |
4417 | break; | ||
4417 | } | 4418 | } |
4418 | 4419 | ||
4419 | /* Free old spare buffer and save old primary buffer as spare */ | 4420 | /* Free old spare buffer and save old primary buffer as spare */ |
@@ -4482,7 +4483,7 @@ static void mem_cgroup_usage_unregister_event(struct cgroup *cgrp, | |||
4482 | continue; | 4483 | continue; |
4483 | 4484 | ||
4484 | new->entries[j] = thresholds->primary->entries[i]; | 4485 | new->entries[j] = thresholds->primary->entries[i]; |
4485 | if (new->entries[j].threshold < usage) { | 4486 | if (new->entries[j].threshold <= usage) { |
4486 | /* | 4487 | /* |
4487 | * new->current_threshold will not be used | 4488 | * new->current_threshold will not be used |
4488 | * until rcu_assign_pointer(), so it's safe to increment | 4489 | * until rcu_assign_pointer(), so it's safe to increment |