
gfp_mask can be passed to add_to_swap() with this patch.
ENOMEM error won't occur if GFP_KERNEL is specified.

The migration code calls the function with GFP_KERNEL
while the swap code calls it with GFP_ATOMIC, because 
the migration code can ask the swap code to free some pages
when we're in a low on memory.

Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 memhotplug-dave/include/linux/swap.h |    2 +-
 memhotplug-dave/mm/swap_state.c      |    4 ++--
 memhotplug-dave/mm/vmscan.c          |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff -puN include/linux/swap.h~page_migration06-add_to_swap-gfpmask include/linux/swap.h
--- memhotplug/include/linux/swap.h~page_migration06-add_to_swap-gfpmask	2005-01-04 13:49:05.000000000 -0800
+++ memhotplug-dave/include/linux/swap.h	2005-01-04 13:49:05.000000000 -0800
@@ -205,7 +205,7 @@ extern int rw_swap_page_sync(int, swp_en
 extern struct address_space swapper_space;
 #define total_swapcache_pages  swapper_space.nrpages
 extern void show_swap_cache_info(void);
-extern int add_to_swap(struct page *);
+extern int add_to_swap(struct page *, unsigned int);
 extern void __delete_from_swap_cache(struct page *);
 extern void delete_from_swap_cache(struct page *);
 extern int move_to_swap_cache(struct page *, swp_entry_t);
diff -puN mm/swap_state.c~page_migration06-add_to_swap-gfpmask mm/swap_state.c
--- memhotplug/mm/swap_state.c~page_migration06-add_to_swap-gfpmask	2005-01-04 13:49:05.000000000 -0800
+++ memhotplug-dave/mm/swap_state.c	2005-01-04 13:49:05.000000000 -0800
@@ -139,7 +139,7 @@ void __delete_from_swap_cache(struct pag
  * Allocate swap space for the page and add the page to the
  * swap cache.  Caller needs to hold the page lock. 
  */
-int add_to_swap(struct page * page)
+int add_to_swap(struct page * page, unsigned int gfp_mask)
 {
 	swp_entry_t entry;
 	int pf_flags;
@@ -172,7 +172,7 @@ int add_to_swap(struct page * page)
 		/*
 		 * Add it to the swap cache and mark it dirty
 		 */
-		err = __add_to_swap_cache(page, entry, GFP_ATOMIC|__GFP_NOWARN);
+		err = __add_to_swap_cache(page, entry, gfp_mask|__GFP_NOWARN);
 
 		if (pf_flags & PF_MEMALLOC)
 			current->flags |= PF_MEMALLOC;
diff -puN mm/vmscan.c~page_migration06-add_to_swap-gfpmask mm/vmscan.c
--- memhotplug/mm/vmscan.c~page_migration06-add_to_swap-gfpmask	2005-01-04 13:49:05.000000000 -0800
+++ memhotplug-dave/mm/vmscan.c	2005-01-04 13:49:05.000000000 -0800
@@ -379,7 +379,7 @@ static int shrink_list(struct list_head 
 		 * Try to allocate it some swap space here.
 		 */
 		if (PageAnon(page) && !PageSwapCache(page)) {
-			if (!add_to_swap(page))
+			if (!add_to_swap(page, GFP_ATOMIC))
 				goto activate_locked;
 		}
 #endif /* CONFIG_SWAP */
_
