aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugh Dickins <hugh@veritas.com>2008-02-05 01:28:49 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 12:44:15 -0500
commitf000944d03a5b74ab3c92b2fcdf0e944cc898065 (patch)
tree07b64eeed416f3869a3fc4f06d00bd1fb1321f20
parentbb63be0a091c512fb566ee235eb8320d5831b6e2 (diff)
tmpfs: shuffle add_to_swap_caches
add_to_swap_cache doesn't amount to much: merge it into its sole caller read_swap_cache_async. But we'll be needing to call __add_to_swap_cache from shmem.c, so promote it to the new add_to_swap_cache. Both were static, so there's no interface confusion to worry about. And lose that inappropriate "Anon pages are already on the LRU" comment in the merging: they're not already on the LRU, as Nick Piggin noticed. Signed-off-by: Hugh Dickins <hugh@veritas.com> No-problems-with: Nick Piggin <npiggin@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/swap_state.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 18fce3613e5a..c75eda2c9cc5 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -64,10 +64,10 @@ void show_swap_cache_info(void)
64} 64}
65 65
66/* 66/*
67 * __add_to_swap_cache resembles add_to_page_cache on swapper_space, 67 * add_to_swap_cache resembles add_to_page_cache on swapper_space,
68 * but sets SwapCache flag and private instead of mapping and index. 68 * but sets SwapCache flag and private instead of mapping and index.
69 */ 69 */
70static int __add_to_swap_cache(struct page *page, swp_entry_t entry, 70static int add_to_swap_cache(struct page *page, swp_entry_t entry,
71 gfp_t gfp_mask) 71 gfp_t gfp_mask)
72{ 72{
73 int error; 73 int error;
@@ -94,28 +94,6 @@ static int __add_to_swap_cache(struct page *page, swp_entry_t entry,
94 return error; 94 return error;
95} 95}
96 96
97static int add_to_swap_cache(struct page *page, swp_entry_t entry,
98 gfp_t gfp_mask)
99{
100 int error;
101
102 BUG_ON(PageLocked(page));
103 if (!swap_duplicate(entry))
104 return -ENOENT;
105
106 SetPageLocked(page);
107 error = __add_to_swap_cache(page, entry, gfp_mask & GFP_KERNEL);
108 /*
109 * Anon pages are already on the LRU, we don't run lru_cache_add here.
110 */
111 if (error) {
112 ClearPageLocked(page);
113 swap_free(entry);
114 return error;
115 }
116 return 0;
117}
118
119/* 97/*
120 * This must be called only on pages that have 98 * This must be called only on pages that have
121 * been verified to be in the swap cache. 99 * been verified to be in the swap cache.
@@ -165,7 +143,7 @@ int add_to_swap(struct page * page, gfp_t gfp_mask)
165 /* 143 /*
166 * Add it to the swap cache and mark it dirty 144 * Add it to the swap cache and mark it dirty
167 */ 145 */
168 err = __add_to_swap_cache(page, entry, 146 err = add_to_swap_cache(page, entry,
169 gfp_mask|__GFP_NOMEMALLOC|__GFP_NOWARN); 147 gfp_mask|__GFP_NOMEMALLOC|__GFP_NOWARN);
170 148
171 switch (err) { 149 switch (err) {
@@ -210,7 +188,7 @@ void delete_from_swap_cache(struct page *page)
210 */ 188 */
211int move_to_swap_cache(struct page *page, swp_entry_t entry) 189int move_to_swap_cache(struct page *page, swp_entry_t entry)
212{ 190{
213 int err = __add_to_swap_cache(page, entry, GFP_ATOMIC); 191 int err = add_to_swap_cache(page, entry, GFP_ATOMIC);
214 if (!err) { 192 if (!err) {
215 remove_from_page_cache(page); 193 remove_from_page_cache(page);
216 page_cache_release(page); /* pagecache ref */ 194 page_cache_release(page); /* pagecache ref */
@@ -335,16 +313,21 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
335 } 313 }
336 314
337 /* 315 /*
316 * Swap entry may have been freed since our caller observed it.
317 */
318 if (!swap_duplicate(entry))
319 break;
320
321 /*
338 * Associate the page with swap entry in the swap cache. 322 * Associate the page with swap entry in the swap cache.
339 * May fail (-ENOENT) if swap entry has been freed since 323 * May fail (-EEXIST) if there is already a page associated
340 * our caller observed it. May fail (-EEXIST) if there 324 * with this entry in the swap cache: added by a racing
341 * is already a page associated with this entry in the 325 * read_swap_cache_async, or add_to_swap or shmem_writepage
342 * swap cache: added by a racing read_swap_cache_async, 326 * re-using the just freed swap entry for an existing page.
343 * or by try_to_swap_out (or shmem_writepage) re-using
344 * the just freed swap entry for an existing page.
345 * May fail (-ENOMEM) if radix-tree node allocation failed. 327 * May fail (-ENOMEM) if radix-tree node allocation failed.
346 */ 328 */
347 err = add_to_swap_cache(new_page, entry, gfp_mask); 329 SetPageLocked(new_page);
330 err = add_to_swap_cache(new_page, entry, gfp_mask & GFP_KERNEL);
348 if (!err) { 331 if (!err) {
349 /* 332 /*
350 * Initiate read into locked page and return. 333 * Initiate read into locked page and return.
@@ -353,7 +336,9 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
353 swap_readpage(NULL, new_page); 336 swap_readpage(NULL, new_page);
354 return new_page; 337 return new_page;
355 } 338 }
356 } while (err != -ENOENT && err != -ENOMEM); 339 ClearPageLocked(new_page);
340 swap_free(entry);
341 } while (err != -ENOMEM);
357 342
358 if (new_page) 343 if (new_page)
359 page_cache_release(new_page); 344 page_cache_release(new_page);