aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMel Gorman2014-08-28 13:35:30 -0500
committerJiri Slaby2014-09-26 04:52:04 -0500
commit6ffef5d8bfc16845e25a7ee784426382b5c82c20 (patch)
tree08a958fe92e04c85c433d84add48c5550d94e1a8
parentfa6d2dd2223cafd36fcd901d83eed2f134c8b793 (diff)
downloadti-linux-kernel-6ffef5d8bfc16845e25a7ee784426382b5c82c20.tar.gz
ti-linux-kernel-6ffef5d8bfc16845e25a7ee784426382b5c82c20.tar.xz
ti-linux-kernel-6ffef5d8bfc16845e25a7ee784426382b5c82c20.zip
mm: do not use unnecessary atomic operations when adding pages to the LRU
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: Jiri Slaby <jslaby@suse.cz>
-rw-r--r--mm/swap.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/mm/swap.c b/mm/swap.c
index afeabe3133e7..270b520e4f4b 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -565,13 +565,15 @@ static void __lru_cache_add(struct page *page)
565 */ 565 */
566void lru_cache_add_anon(struct page *page) 566void lru_cache_add_anon(struct page *page)
567{ 567{
568 ClearPageActive(page); 568 if (PageActive(page))
569 ClearPageActive(page);
569 __lru_cache_add(page); 570 __lru_cache_add(page);
570} 571}
571 572
572void lru_cache_add_file(struct page *page) 573void lru_cache_add_file(struct page *page)
573{ 574{
574 ClearPageActive(page); 575 if (PageActive(page))
576 ClearPageActive(page);
575 __lru_cache_add(page); 577 __lru_cache_add(page);
576} 578}
577EXPORT_SYMBOL(lru_cache_add_file); 579EXPORT_SYMBOL(lru_cache_add_file);