int i = 0; 
unsigned int i = 0; 
static int try_to_unuse(unsigned int type){	struct swap_info_struct * si = &swap_info[type];	struct mm_struct *start_mm;	unsigned short *swap_map;	unsigned short swcount;	struct page *page;	swp_entry_t entry;	int i = 0;	int retval = 0;	int reset_overflow = 0;	int shmem;	/*	 * When searching mms for an entry, a good strategy is to	 * start at the first mm we freed the previous entry from	 * (though actually we don't notice whether we or coincidence	 * freed the entry).  Initialize this start_mm with a hold.	 *	 * A simpler strategy would be to start at the last mm we	 * freed the previous entry from; but that would take less	 * advantage of mmlist ordering, which clusters forked mms	 * together, child after parent.  If we race with dup_mmap(), we	 * prefer to resolve parent before child, lest we miss entries	 * duplicated after we scanned child: using last mm would invert	 * that.  Though it's only a serious concern when an overflowed	 * swap count is reset from SWAP_MAP_MAX, preventing a rescan.	 */	start_mm = &init_mm;	atomic_inc(&init_mm.mm_users);	/*	 * Keep on scanning until all entries have gone.  Usually,	 * one pass through swap_map is enough, but not necessarily:	 * there are races when an instance of an entry might be missed.	 */	while ((i = find_next_to_unuse(si, i)) != 0) {		if (signal_pending(current)) {			retval = -EINTR;			break;		}		/* 		 * Get a page for the entry, using the existing swap		 * cache page if there is one.  Otherwise, get a clean		 * page and read the swap into it. 		 */		swap_map = &si->swap_map[i];		entry = swp_entry(type, i);		page = read_swap_cache_async(entry, NULL, 0);		if (!page) {			/*			 * Either swap_duplicate() failed because entry			 * has been freed independently, and will not be			 * reused since sys_swapoff() already disabled			 * allocation from here, or alloc_page() failed.			 */			if (!*swap_map)				continue;			retval = -ENOMEM;			break;		}		/*		 * Don't hold on to start_mm if it looks like exiting.		 */		if (atomic_read(&start_mm->mm_users) == 1) {			mmput(start_mm);			start_mm = &init_mm;			atomic_inc(&init_mm.mm_users);		}		/*		 * Wait for and lock page.  When do_swap_page races with		 * try_to_unuse, do_swap_page can handle the fault much		 * faster than try_to_unuse can locate the entry.  This		 * apparently redundant "wait_on_page_locked" lets try_to_unuse		 * defer to do_swap_page in such a case - in some tests,		 * do_swap_page and try_to_unuse repeatedly compete.		 */		wait_on_page_locked(page);		wait_on_page_writeback(page);		lock_page(page);		wait_on_page_writeback(page);		/*		 * Remove all references to entry.		 * Whenever we reach init_mm, there's no address space		 * to search, but use it as a reminder to search shmem.		 */		shmem = 0;		swcount = *swap_map;		if (swcount > 1) {			if (start_mm == &init_mm)				shmem = shmem_unuse(entry, page);			else				retval = unuse_mm(start_mm, entry, page);		}		if (*swap_map > 1) {			int set_start_mm = (*swap_map >= swcount);			struct list_head *p = &start_mm->mmlist;			struct mm_struct *new_start_mm = start_mm;			struct mm_struct *prev_mm = start_mm;			struct mm_struct *mm;			atomic_inc(&new_start_mm->mm_users);			atomic_inc(&prev_mm->mm_users);			spin_lock(&mmlist_lock);			while (*swap_map > 1 && !retval &&					(p = p->next) != &start_mm->mmlist) {				mm = list_entry(p, struct mm_struct, mmlist);				if (atomic_inc_return(&mm->mm_users) == 1) {					atomic_dec(&mm->mm_users);					continue;				}				spin_unlock(&mmlist_lock);				mmput(prev_mm);				prev_mm = mm;				cond_resched();				swcount = *swap_map;				if (swcount <= 1)					;				else if (mm == &init_mm) {					set_start_mm = 1;					shmem = shmem_unuse(entry, page);				} else					retval = unuse_mm(mm, entry, page);				if (set_start_mm && *swap_map < swcount) {					mmput(new_start_mm);					atomic_inc(&mm->mm_users);					new_start_mm = mm;					set_start_mm = 0;				}				spin_lock(&mmlist_lock);			}			spin_unlock(&mmlist_lock);			mmput(prev_mm);			mmput(start_mm);			start_mm = new_start_mm;		}		if (retval) {			unlock_page(page);			page_cache_release(page);			break;		}		/*		 * How could swap count reach 0x7fff when the maximum		 * pid is 0x7fff, and there's no way to repeat a swap		 * page within an mm (except in shmem, where it's the		 * shared object which takes the reference count)?		 * We believe SWAP_MAP_MAX cannot occur in Linux 2.4.		 *		 * If that's wrong, then we should worry more about		 * exit_mmap() and do_munmap() cases described above:		 * we might be resetting SWAP_MAP_MAX too early here.		 * We know "Undead"s can happen, they're okay, so don't		 * report them; but do report if we reset SWAP_MAP_MAX.		 */		if (*swap_map == SWAP_MAP_MAX) {			swap_device_lock(si);			*swap_map = 1;			swap_device_unlock(si);			reset_overflow = 1;		}		/*		 * If a reference remains (rare), we would like to leave		 * the page in the swap cache; but try_to_unmap could		 * then re-duplicate the entry once we drop page lock,		 * so we might loop indefinitely; also, that page could		 * not be swapped out to other storage meanwhile.  So:		 * delete from cache even if there's another reference,		 * after ensuring that the data has been saved to disk -		 * since if the reference remains (rarer), it will be		 * read from disk into another page.  Splitting into two		 * pages would be incorrect if swap supported "shared		 * private" pages, but they are handled by tmpfs files.		 *		 * Note shmem_unuse already deleted a swappage from		 * the swap cache, unless the move to filepage failed:		 * in which case it left swappage in cache, lowered its		 * swap count to pass quickly through the loops above,		 * and now we must reincrement count to try again later.		 */		if ((*swap_map > 1) && PageDirty(page) && PageSwapCache(page)) {			struct writeback_control wbc = {				.sync_mode = WB_SYNC_NONE,			};			swap_writepage(page, &wbc);			lock_page(page);			wait_on_page_writeback(page);		}		if (PageSwapCache(page)) {			if (shmem)				swap_duplicate(entry);			else				delete_from_swap_cache(page);		}		/*		 * So we could skip searching mms once swap count went		 * to 1, we did not mark any present ptes as dirty: must		 * mark page dirty so shrink_list will preserve it.		 */		SetPageDirty(page);		unlock_page(page);		page_cache_release(page);		/*		 * Make sure that we aren't completely killing		 * interactive performance.		 */		cond_resched();	}	mmput(start_mm);	if (reset_overflow) {		printk(KERN_WARNING "swapoff: cleared swap entry overflow\n");		swap_overflow = 0;	}	return retval;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/6eb396dc4a9781c5e7951143ab56ce5710687ab3/swapfile.c/clean/mm/swapfile.c