From 36e07b9a9d35e1d518f9ac180def3a6db9a52ab7 Mon Sep 17 00:00:00 2001 From: Hugh Dickins Date: Thu, 9 Sep 2010 16:38:09 -0700 Subject: [PATCH] --- yaml --- r: 210471 b: refs/heads/master c: b73d7fcecd93dc15eaa3c45c8c587b613f6673c4 h: refs/heads/master i: 210469: bd3dc5b460f4d5cb4640ae1581f87035052a8e21 210467: 730c476e1f2c3cdb9be98ee48593c2b518c5177d 210463: e9c084011af78196404ea003fa01d5eb7e1242a0 v: v3 --- [refs] | 2 +- trunk/mm/swapfile.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index ac599497f91c..145ad814d60e 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 910321ea817a202ff70fac666e37e2c8e2f88823 +refs/heads/master: b73d7fcecd93dc15eaa3c45c8c587b613f6673c4 diff --git a/trunk/mm/swapfile.c b/trunk/mm/swapfile.c index f08d165871b3..ed5151079f59 100644 --- a/trunk/mm/swapfile.c +++ b/trunk/mm/swapfile.c @@ -318,10 +318,8 @@ static inline unsigned long scan_swap_map(struct swap_info_struct *si, if (offset > si->highest_bit) scan_base = offset = si->lowest_bit; - /* reuse swap entry of cache-only swap if not hibernation. */ - if (vm_swap_full() - && usage == SWAP_HAS_CACHE - && si->swap_map[offset] == SWAP_HAS_CACHE) { + /* reuse swap entry of cache-only swap if not busy. */ + if (vm_swap_full() && si->swap_map[offset] == SWAP_HAS_CACHE) { int swap_was_freed; spin_unlock(&swap_lock); swap_was_freed = __try_to_reclaim_swap(si, offset); @@ -688,6 +686,24 @@ int try_to_free_swap(struct page *page) if (page_swapcount(page)) return 0; + /* + * Once hibernation has begun to create its image of memory, + * there's a danger that one of the calls to try_to_free_swap() + * - most probably a call from __try_to_reclaim_swap() while + * hibernation is allocating its own swap pages for the image, + * but conceivably even a call from memory reclaim - will free + * the swap from a page which has already been recorded in the + * image as a clean swapcache page, and then reuse its swap for + * another page of the image. On waking from hibernation, the + * original page might be freed under memory pressure, then + * later read back in from swap, now with the wrong data. + * + * Hibernation clears bits from gfp_allowed_mask to prevent + * memory reclaim from writing to disk, so check that here. + */ + if (!(gfp_allowed_mask & __GFP_IO)) + return 0; + delete_from_swap_cache(page); SetPageDirty(page); return 1;