linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm: clarify __add_to_swap_cache locking
@ 2007-08-02  5:08 Nick Piggin
  0 siblings, 0 replies; only message in thread
From: Nick Piggin @ 2007-08-02  5:08 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Hugh Dickins, Linux Memory Management List

__add_to_swap_cache unconditionally sets the page locked, which can be
a bit alarming to the unsuspecting reader: in the code paths where the
page is visible to other CPUs, the page should be (and is) already locked.

Instead, just add a check to ensure the page is locked here, and teach
the one path relying on the old behaviour to call SetPageLocked itself.

Signed-off-by: Nick Piggin <npiggin@suse.de>

Index: linux-2.6/mm/swap_state.c
===================================================================
--- linux-2.6.orig/mm/swap_state.c
+++ linux-2.6/mm/swap_state.c
@@ -74,6 +74,7 @@ static int __add_to_swap_cache(struct pa
 {
 	int error;
 
+	BUG_ON(!PageLocked(page));
 	BUG_ON(PageSwapCache(page));
 	BUG_ON(PagePrivate(page));
 	error = radix_tree_preload(gfp_mask);
@@ -83,7 +84,6 @@ static int __add_to_swap_cache(struct pa
 						entry.val, page);
 		if (!error) {
 			page_cache_get(page);
-			SetPageLocked(page);
 			SetPageSwapCache(page);
 			set_page_private(page, entry.val);
 			total_swapcache_pages++;
@@ -338,6 +338,7 @@ struct page *read_swap_cache_async(swp_e
 								vma, addr);
 			if (!new_page)
 				break;		/* Out of memory */
+			SetPageLocked(new_page);/* could be non-atomic op */
 		}
 
 		/*
@@ -361,7 +362,9 @@ struct page *read_swap_cache_async(swp_e
 		}
 	} while (err != -ENOENT && err != -ENOMEM);
 
-	if (new_page)
+	if (new_page) {
+		ClearPageLocked(new_page);
 		page_cache_release(new_page);
+	}
 	return found_page;
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-02  5:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-02  5:08 [patch] mm: clarify __add_to_swap_cache locking Nick Piggin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox