kernels/linux-2.4.0/mm/shmem.c
/*
 * Move the page from the page cache to the swap cache
 */
Move the page from the page cache to the swap cache
Move the page from the page cache to the swap cache
static int shmem_writepage(struct page * page)
{
	int error;
	struct shmem_inode_info *info;
	swp_entry_t *entry, swap;
	info = &page->mapping->host->u.shmem_i;
	if (info->locked)
		return 1;
	swap = __get_swap_page(2);
	if (!swap.val)
		return 1;
	spin_lock(&info->lock);
	entry = shmem_swp_entry (info, page->index);
	if (!entry)	
		BUG();
	error = -EAGAIN;
	if (entry->val) {
                __swap_free(swap, 2);
		goto out;
        }
        *entry = swap;
	error = 0;
	lru_cache_del(page);
	remove_inode_page(page);
	add_to_swap_cache(page, swap);
	page_cache_release(page);
	set_page_dirty(page);
	info->swapped++;
out:
	spin_unlock(&info->lock);
	UnlockPage(page);
	return error;
}
static int shmem_writepage ( struct page * page ) { int error ; struct shmem_inode_info * info ; swp_entry_t * entry , swap ; info = & page -> mapping -> host -> u . shmem_i ; if ( info -> locked ) return 1 ; swap = __get_swap_page ( 2 ) ; if ( ! swap . val ) return 1 ; spin_lock ( & info -> lock ) ; entry = shmem_swp_entry ( info , page -> index ) ; if ( ! entry ) BUG ( ) ; error = - EAGAIN ; if ( entry -> val ) { __swap_free ( swap , 2 ) ; goto out ; } * entry = swap ; error = 0 ; lru_cache_del ( page ) ; remove_inode_page ( page ) ; add_to_swap_cache ( page , swap ) ; page_cache_release ( page ) ; set_page_dirty ( page ) ; info -> swapped ++ ; out : spin_unlock ( & info -> lock ) ; UnlockPage ( page ) ; return error ; }
Move the page from the page cache to the swap cache
Move the page from the page cache to the swap cache
/* this had been allocted on page allocation */ /* Remove the from the page cache */ /* Add it to the swap cache */