lkml.org 
[lkml]   [2010]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[patch 2/4] memcg: catch negative per-cpu sums in dirty info
Date
Folding the per-cpu counters can yield a negative value in case of
accounting races between CPUs.

When collecting the dirty info, the code would read those sums into an
unsigned variable and then check for it being negative, which can not
work.

Instead, fold the counters into a signed local variable, make the
check, and only then assign it.

This way, the function signals correctly when there are insane values
instead of leaking them out to the caller.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
mm/memcontrol.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1261,14 +1261,15 @@ bool mem_cgroup_dirty_info(unsigned long
(dirty_param.dirty_background_ratio *
available_mem) / 100;

- info->nr_reclaimable =
- mem_cgroup_page_stat(MEMCG_NR_RECLAIM_PAGES);
- if (info->nr_reclaimable < 0)
+ value = mem_cgroup_page_stat(MEMCG_NR_RECLAIM_PAGES);
+ if (value < 0)
return false;
+ info->nr_reclaimable = value;

- info->nr_writeback = mem_cgroup_page_stat(MEMCG_NR_WRITEBACK);
- if (info->nr_writeback < 0)
+ value = mem_cgroup_page_stat(MEMCG_NR_WRITEBACK);
+ if (value < 0)
return false;
+ info->nr_writeback = value;

return true;
}



\
 
 \ /
  Last update: 2010-11-07 23:17    [W:0.115 / U:0.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site