Skip to content

Commit

Permalink
mm: do not use unnecessary atomic operations when adding pages to the…
Browse files Browse the repository at this point in the history
… LRU

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 <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Mel Gorman authored and torvalds committed Jun 4, 2014
1 parent e3741b5 commit 6fb81a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,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);
Expand Down

0 comments on commit 6fb81a1

Please sign in to comment.