]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: do not use unnecessary atomic operations when adding pages to the LRU
authorMel Gorman <mgorman@suse.de>
Wed, 4 Jun 2014 23:10:28 +0000 (16:10 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 30 Jan 2015 01:40:52 +0000 (17:40 -0800)
commit 6fb81a17d21f2a138b8f424af4cf379f2b694060 upstream.

When adding pages to the LRU we clear the active bit unconditionally.
As the page could be reachable from other paths we cannot use unlocked
operations without risk of corruption such as a parallel
mark_page_accessed.  This patch tests if is necessary to clear the
active flag before using an atomic operation.  This potentially opens a
tiny race when PageActive is checked as mark_page_accessed could be
called after PageActive was checked.  The race already exists but this
patch changes it slightly.  The consequence is that that the page may be
promoted to the active list that might have been left on the inactive
list before the patch.  It's too tiny a race and too marginal a
consequence to always use atomic operations for.

Signed-off-by: Mel Gorman <mgorman@suse.de>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Jan Kara <jack@suse.cz>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/swap.c

index c370e59245f9fe8e521cb5fe0f78402e27619434..9649d99db5f925cd4bf3423fee5d6e034d1ad0bc 100644 (file)
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -597,13 +597,15 @@ static void __lru_cache_add(struct page *page)
  */
 void lru_cache_add_anon(struct page *page)
 {
-       ClearPageActive(page);
+       if (PageActive(page))
+               ClearPageActive(page);
        __lru_cache_add(page);
 }
 
 void lru_cache_add_file(struct page *page)
 {
-       ClearPageActive(page);
+       if (PageActive(page))
+               ClearPageActive(page);
        __lru_cache_add(page);
 }
 EXPORT_SYMBOL(lru_cache_add_file);