Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758152Ab0HDB4F (ORCPT ); Tue, 3 Aug 2010 21:56:05 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:55164 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758008Ab0HDBz7 (ORCPT ); Tue, 3 Aug 2010 21:55:59 -0400 X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Date: Wed, 4 Aug 2010 10:50:54 +0900 From: KAMEZAWA Hiroyuki To: KAMEZAWA Hiroyuki Cc: Andrea Gelmini , "Rafael J. Wysocki" , Ondrej Zary , Kernel development list , Andrew Morton , Balbir Singh , nigel@tuxonice.net, stable@kernel.org, Hugh Dickins Subject: [BUGFIX][PATCH] fix corruption of hibernation caused by reusing swap at saving image Message-Id: <20100804105054.af68ee5c.kamezawa.hiroyu@jp.fujitsu.com> In-Reply-To: <20100804083652.92b5b2df.kamezawa.hiroyu@jp.fujitsu.com> References: <201007282320.39528.linux@rainbow-software.org> <201007282334.08063.rjw@sisk.pl> <20100729132325.59871484.kamezawa.hiroyu@jp.fujitsu.com> <20100804083652.92b5b2df.kamezawa.hiroyu@jp.fujitsu.com> Organization: FUJITSU Co. LTD. X-Mailer: Sylpheed 3.0.3 (GTK+ 2.10.14; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2124 Lines: 54 This patch is created against 2.6.35. CC'ed stable. Thank you for all helps. = From: KAMEZAWA Hiroyuki Since 2.6.31, swap_map[]'s refcounting was changed to show that a used swap entry is just for swap-cache, can be reused. Then, while scanning free entry in swap_map[], a swap entry may be able to be reclaimed and reused. It was by the commit c9e444103b5e7a5a3519f9913f59767f92e33baf. But this caused deta corruption at hibernation. Considering how the image is saved, the calls of try_to_reclaim_swap() changes the status of memory and there will be inconsitency between saved-memory-image's swap_map[] / memmap / swapper_space because memory is saved per page with swap-allocation per page. This patch is for avoiding bug by not reclaiming swap-entry at hibernation. This is a quick fix for backporting. Cc: stable@kernel.org Cc: Rafael J. Wysocki Reported-by: Ondreg Zary Tested-by: Andrea Gelmini Acked-by: Hugh Dickins Signed-off-by: KAMEZAWA Hiroyuki --- mm/swapfile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) Index: linux-2.6.35.org/mm/swapfile.c =================================================================== --- linux-2.6.35.org.orig/mm/swapfile.c +++ linux-2.6.35.org/mm/swapfile.c @@ -318,8 +318,10 @@ checks: if (offset > si->highest_bit) scan_base = offset = si->lowest_bit; - /* reuse swap entry of cache-only swap if not busy. */ - if (vm_swap_full() && si->swap_map[offset] == SWAP_HAS_CACHE) { + /* 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) { int swap_was_freed; spin_unlock(&swap_lock); swap_was_freed = __try_to_reclaim_swap(si, offset); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/