Commit ef8745c1e7fc5413d760b3b958f3fd3a0beaad72
Committed by
Linus Torvalds
1 parent
4e649152cb
Exists in
master
and in
4 other branches
memcg: reduce check for softlimit excess
In charge/uncharge/reclaim path, usage_in_excess is calculated repeatedly and it takes res_counter's spin_lock every time. This patch removes unnecessary calls for res_count_soft_limit_excess. Reviewed-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Paul Menage <menage@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Balbir Singh <balbir@in.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 15 additions and 16 deletions Side-by-side Diff
mm/memcontrol.c
... | ... | @@ -313,7 +313,8 @@ |
313 | 313 | static void |
314 | 314 | __mem_cgroup_insert_exceeded(struct mem_cgroup *mem, |
315 | 315 | struct mem_cgroup_per_zone *mz, |
316 | - struct mem_cgroup_tree_per_zone *mctz) | |
316 | + struct mem_cgroup_tree_per_zone *mctz, | |
317 | + unsigned long long new_usage_in_excess) | |
317 | 318 | { |
318 | 319 | struct rb_node **p = &mctz->rb_root.rb_node; |
319 | 320 | struct rb_node *parent = NULL; |
... | ... | @@ -322,7 +323,9 @@ |
322 | 323 | if (mz->on_tree) |
323 | 324 | return; |
324 | 325 | |
325 | - mz->usage_in_excess = res_counter_soft_limit_excess(&mem->res); | |
326 | + mz->usage_in_excess = new_usage_in_excess; | |
327 | + if (!mz->usage_in_excess) | |
328 | + return; | |
326 | 329 | while (*p) { |
327 | 330 | parent = *p; |
328 | 331 | mz_node = rb_entry(parent, struct mem_cgroup_per_zone, |
... | ... | @@ -382,7 +385,7 @@ |
382 | 385 | |
383 | 386 | static void mem_cgroup_update_tree(struct mem_cgroup *mem, struct page *page) |
384 | 387 | { |
385 | - unsigned long long new_usage_in_excess; | |
388 | + unsigned long long excess; | |
386 | 389 | struct mem_cgroup_per_zone *mz; |
387 | 390 | struct mem_cgroup_tree_per_zone *mctz; |
388 | 391 | int nid = page_to_nid(page); |
389 | 392 | |
390 | 393 | |
391 | 394 | |
... | ... | @@ -395,25 +398,21 @@ |
395 | 398 | */ |
396 | 399 | for (; mem; mem = parent_mem_cgroup(mem)) { |
397 | 400 | mz = mem_cgroup_zoneinfo(mem, nid, zid); |
398 | - new_usage_in_excess = | |
399 | - res_counter_soft_limit_excess(&mem->res); | |
401 | + excess = res_counter_soft_limit_excess(&mem->res); | |
400 | 402 | /* |
401 | 403 | * We have to update the tree if mz is on RB-tree or |
402 | 404 | * mem is over its softlimit. |
403 | 405 | */ |
404 | - if (new_usage_in_excess || mz->on_tree) { | |
406 | + if (excess || mz->on_tree) { | |
405 | 407 | spin_lock(&mctz->lock); |
406 | 408 | /* if on-tree, remove it */ |
407 | 409 | if (mz->on_tree) |
408 | 410 | __mem_cgroup_remove_exceeded(mem, mz, mctz); |
409 | 411 | /* |
410 | - * if over soft limit, insert again. mz->usage_in_excess | |
411 | - * will be updated properly. | |
412 | + * Insert again. mz->usage_in_excess will be updated. | |
413 | + * If excess is 0, no tree ops. | |
412 | 414 | */ |
413 | - if (new_usage_in_excess) | |
414 | - __mem_cgroup_insert_exceeded(mem, mz, mctz); | |
415 | - else | |
416 | - mz->usage_in_excess = 0; | |
415 | + __mem_cgroup_insert_exceeded(mem, mz, mctz, excess); | |
417 | 416 | spin_unlock(&mctz->lock); |
418 | 417 | } |
419 | 418 | } |
... | ... | @@ -2221,6 +2220,7 @@ |
2221 | 2220 | unsigned long reclaimed; |
2222 | 2221 | int loop = 0; |
2223 | 2222 | struct mem_cgroup_tree_per_zone *mctz; |
2223 | + unsigned long long excess; | |
2224 | 2224 | |
2225 | 2225 | if (order > 0) |
2226 | 2226 | return 0; |
2227 | 2227 | |
... | ... | @@ -2272,9 +2272,8 @@ |
2272 | 2272 | break; |
2273 | 2273 | } while (1); |
2274 | 2274 | } |
2275 | - mz->usage_in_excess = | |
2276 | - res_counter_soft_limit_excess(&mz->mem->res); | |
2277 | 2275 | __mem_cgroup_remove_exceeded(mz->mem, mz, mctz); |
2276 | + excess = res_counter_soft_limit_excess(&mz->mem->res); | |
2278 | 2277 | /* |
2279 | 2278 | * One school of thought says that we should not add |
2280 | 2279 | * back the node to the tree if reclaim returns 0. |
... | ... | @@ -2283,8 +2282,8 @@ |
2283 | 2282 | * memory to reclaim from. Consider this as a longer |
2284 | 2283 | * term TODO. |
2285 | 2284 | */ |
2286 | - if (mz->usage_in_excess) | |
2287 | - __mem_cgroup_insert_exceeded(mz->mem, mz, mctz); | |
2285 | + /* If excess == 0, no tree ops */ | |
2286 | + __mem_cgroup_insert_exceeded(mz->mem, mz, mctz, excess); | |
2288 | 2287 | spin_unlock(&mctz->lock); |
2289 | 2288 | css_put(&mz->mem->css); |
2290 | 2289 | loop++; |