Commit 6fb81a17 authored by Mel Gorman's avatar Mel Gorman Committed by Linus Torvalds

mm: do not use unnecessary atomic operations when adding pages to the 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: default avatarMel Gorman <>
Acked-by: default avatarJohannes Weiner <>
Cc: Vlastimil Babka <>
Cc: Jan Kara <>
Cc: Michal Hocko <>
Cc: Hugh Dickins <>
Cc: Dave Hansen <>
Cc: Theodore Ts'o <>
Cc: "Paul E. McKenney" <>
Cc: Oleg Nesterov <>
Cc: Rik van Riel <>
Cc: Peter Zijlstra <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent e3741b50
...@@ -631,13 +631,15 @@ static void __lru_cache_add(struct page *page) ...@@ -631,13 +631,15 @@ static void __lru_cache_add(struct page *page)
*/ */
void lru_cache_add_anon(struct page *page) void lru_cache_add_anon(struct page *page)
{ {
ClearPageActive(page); if (PageActive(page))
__lru_cache_add(page); __lru_cache_add(page);
} }
void lru_cache_add_file(struct page *page) void lru_cache_add_file(struct page *page)
{ {
ClearPageActive(page); if (PageActive(page))
__lru_cache_add(page); __lru_cache_add(page);
} }
EXPORT_SYMBOL(lru_cache_add_file); EXPORT_SYMBOL(lru_cache_add_file);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment