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 Signed-off-by: Dave Hansen --- 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~AA-PM-06-add_to_swap-gfpmask include/linux/swap.h --- memhotplug/include/linux/swap.h~AA-PM-06-add_to_swap-gfpmask 2005-07-28 13:50:34.000000000 -0700 +++ memhotplug-dave/include/linux/swap.h 2005-07-28 13:50:34.000000000 -0700 @@ -207,7 +207,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~AA-PM-06-add_to_swap-gfpmask mm/swap_state.c --- memhotplug/mm/swap_state.c~AA-PM-06-add_to_swap-gfpmask 2005-07-28 13:50:34.000000000 -0700 +++ memhotplug-dave/mm/swap_state.c 2005-07-28 13:50:34.000000000 -0700 @@ -141,7 +141,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 err; @@ -166,7 +166,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_NOMEMALLOC|__GFP_NOWARN); + gfp_mask|__GFP_NOMEMALLOC|__GFP_NOWARN); switch (err) { case 0: /* Success */ diff -puN mm/vmscan.c~AA-PM-06-add_to_swap-gfpmask mm/vmscan.c --- memhotplug/mm/vmscan.c~AA-PM-06-add_to_swap-gfpmask 2005-07-28 13:50:34.000000000 -0700 +++ memhotplug-dave/mm/vmscan.c 2005-07-28 13:50:34.000000000 -0700 @@ -406,7 +406,7 @@ static int shrink_list(struct list_head * Try to allocate it some swap space here. */ if (PageAnon(page) && !PageSwapCache(page) && sc->may_swap) { - if (!add_to_swap(page)) + if (!add_to_swap(page, GFP_ATOMIC)) goto activate_locked; } #endif /* CONFIG_SWAP */ _