lkml.org 
[lkml]   [2009]   [Aug]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] mm: make nr_scan_try_batch() more safe on races
nr_scan_try_batch() can be called concurrently on the same zone
and the non-atomic calculations can go wrong. This is not a big
problem as long as the errors are small and won't impact the
balanced zone aging noticeably.

@nr_to_scan could be much larger values than @swap_cluster_max.
So don't store such large values to *nr_saved_scan directly,
which helps reducing possible errors on races.

CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
mm/vmscan.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

--- linux.orig/mm/vmscan.c 2009-08-20 10:46:30.000000000 +0800
+++ linux/mm/vmscan.c 2009-08-20 10:49:36.000000000 +0800
@@ -1496,15 +1496,14 @@ static unsigned long nr_scan_try_batch(u
unsigned long *nr_saved_scan,
unsigned long swap_cluster_max)
{
- unsigned long nr;
-
- *nr_saved_scan += nr_to_scan;
- nr = *nr_saved_scan;
+ unsigned long nr = *nr_saved_scan + nr_to_scan;

if (nr >= swap_cluster_max)
*nr_saved_scan = 0;
- else
+ else {
+ *nr_saved_scan = nr;
nr = 0;
+ }

return nr;
}

\
 
 \ /
  Last update: 2009-08-20 04:55    [W:0.085 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site