patch-2.4.4 linux/mm/swap_state.c
Next file: linux/mm/swapfile.c
Previous file: linux/mm/shmem.c
Back to the patch index
Back to the overall index
- Lines: 113
- Date:
Wed Apr 25 14:46:21 2001
- Orig file:
v2.4.3/linux/mm/swap_state.c
- Orig date:
Fri Dec 29 15:04:27 2000
diff -u --recursive --new-file v2.4.3/linux/mm/swap_state.c linux/mm/swap_state.c
@@ -17,9 +17,24 @@
#include <asm/pgtable.h>
+/*
+ * We may have stale swap cache pages in memory: notice
+ * them here and get rid of the unnecessary final write.
+ */
static int swap_writepage(struct page *page)
{
- rw_swap_page(WRITE, page, 0);
+ /* One for the page cache, one for this user, one for page->buffers */
+ if (page_count(page) > 2 + !!page->buffers)
+ goto in_use;
+ if (swap_count(page) > 1)
+ goto in_use;
+
+ /* We could remove it here, but page_launder will do it anyway */
+ UnlockPage(page);
+ return 0;
+
+in_use:
+ rw_swap_page(WRITE, page);
return 0;
}
@@ -130,26 +145,6 @@
UnlockPage(page);
}
-/*
- * Perform a free_page(), also freeing any swap cache associated with
- * this page if it is the last user of the page. Can not do a lock_page,
- * as we are holding the page_table_lock spinlock.
- */
-void free_page_and_swap_cache(struct page *page)
-{
- /*
- * If we are the only user, then try to free up the swap cache.
- */
- if (PageSwapCache(page) && !TryLockPage(page)) {
- if (!is_page_shared(page)) {
- delete_from_swap_cache_nolock(page);
- }
- UnlockPage(page);
- }
- page_cache_release(page);
-}
-
-
/*
* Lookup a swap entry in the swap cache. A found page will be returned
* unlocked and with its refcount incremented - we rely on the kernel
@@ -168,37 +163,18 @@
/*
* Right now the pagecache is 32-bit only. But it's a 32 bit index. =)
*/
-repeat:
- found = find_lock_page(&swapper_space, entry.val);
+ found = find_get_swapcache_page(&swapper_space, entry.val);
if (!found)
return 0;
- /*
- * Though the "found" page was in the swap cache an instant
- * earlier, it might have been removed by refill_inactive etc.
- * Re search ... Since find_lock_page grabs a reference on
- * the page, it can not be reused for anything else, namely
- * it can not be associated with another swaphandle, so it
- * is enough to check whether the page is still in the scache.
- */
- if (!PageSwapCache(found)) {
- UnlockPage(found);
- page_cache_release(found);
- goto repeat;
- }
+ if (!PageSwapCache(found))
+ BUG();
if (found->mapping != &swapper_space)
- goto out_bad;
+ BUG();
#ifdef SWAP_CACHE_INFO
swap_cache_find_success++;
#endif
- UnlockPage(found);
return found;
}
-
-out_bad:
- printk (KERN_ERR "VM: Found a non-swapper swap page!\n");
- UnlockPage(found);
- page_cache_release(found);
- return 0;
}
/*
@@ -210,7 +186,7 @@
* the swap entry is no longer in use.
*/
-struct page * read_swap_cache_async(swp_entry_t entry, int wait)
+struct page * read_swap_cache_async(swp_entry_t entry)
{
struct page *found_page = 0, *new_page;
unsigned long new_page_addr;
@@ -243,7 +219,7 @@
*/
lock_page(new_page);
add_to_swap_cache(new_page, entry);
- rw_swap_page(READ, new_page, wait);
+ rw_swap_page(READ, new_page);
return new_page;
out_free_page:
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)