Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757940Ab0HCXLG (ORCPT ); Tue, 3 Aug 2010 19:11:06 -0400 Received: from ogre.sisk.pl ([217.79.144.158]:34158 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756417Ab0HCXLC (ORCPT ); Tue, 3 Aug 2010 19:11:02 -0400 From: "Rafael J. Wysocki" To: KAMEZAWA Hiroyuki Subject: Re: [RFC][PATCH -mm] hibernation: freeze swap at hibernation (Was Re: Memory corruption during hibernation since 2.6.31 Date: Wed, 4 Aug 2010 01:09:15 +0200 User-Agent: KMail/1.13.5 (Linux/2.6.35-rjw+; KDE/4.4.4; x86_64; ; ) Cc: Hugh Dickins , KOSAKI Motohiro , Ondrej Zary , Kernel development list , Andrew Morton , Balbir Singh , Andrea Arcangeli References: <201007282334.08063.rjw@sisk.pl> <20100730131432.891df49a.kamezawa.hiroyu@jp.fujitsu.com> <20100802150225.851b48fe.kamezawa.hiroyu@jp.fujitsu.com> In-Reply-To: <20100802150225.851b48fe.kamezawa.hiroyu@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201008040109.15818.rjw@sisk.pl> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3727 Lines: 93 On Monday, August 02, 2010, KAMEZAWA Hiroyuki wrote: > On Fri, 30 Jul 2010 13:14:32 +0900 > KAMEZAWA Hiroyuki wrote: > > > On Thu, 29 Jul 2010 21:10:10 -0700 > > Hugh Dickins wrote: > > > > > On Thu, Jul 29, 2010 at 5:01 PM, KAMEZAWA Hiroyuki > > > wrote: > > > > > > > I think the best way is kexec(). But maybe rollback from hibernation failure > > > > will be difficult. Considering how crash-dump works well and under maintainance > > > > by many enterprise guys, hibernation-by-kexec is a choice. I think. It can make > > > > reuse of kdump code, ...or, hibernation-resume code can eat kdump image > > > > directly. Maybe the problem will be the speed of dump. > > > > > > I've no appetite for a total rework of hibernation, and I don't see > > > how that would > > > address the issue: I'm just looking for some protection against swap > > > reuse danger. > > > > > Okay ;) (And I forget that kexec has to prepare memory at boot time for 2nd kernel. > > It will be harmful for small device guys.) > > > > I'll prepare a routine not-quick-fix. > > Ok, here. Passed easy tests as > # echo disk > /sys/power/state > > > Looks like a big hammer ? But I think following kind of patch is required. > About swap-reuse, it's only possible when a page is added to swap cache > but try_to_unmap() fails and the page remains in memory. IIUC, most of this > kind of pages will be backed to swap by shrink_all_memory(). So, reuse-swap > happens only when the user unlucky. This patch ignores reuse-swap but freeze > swap_map[] for saving swap_map[] to the disk in consistent way. > > == > From: KAMEZAWA Hiroyuki > > swap_map[] is a one of objects which can be update while hibernation. I.E, > usage counter in swap_map[] is updated while hibernation is making a copy > of memory image to the disk. > > At resume, hibenation code doesn't call swap_free() against the swaps they > used...So, the swap_map[] will turns to be an initial state. > > With small consideration, the question is how swap_map[] updated before > dumping to the disk is treated. In swap-system view, there are no guarantee > that swap_map[] are properly reloaded and there is no leak in swap count. > > This patch tries to freeze swap_map[] during hibernation. > By this, no updates will be happen to swap_map[] among save_image(). > At load_image(), the swap_map[] has no record for swap entries used by > save_image(), we can simply forget it. > > Note: I'm not a specialist of hibernation...so, I'm not sure the hooks > to kernel/power/user.c is appropriate or not. > And this disables swap-out once hibernation starts saving. > Should we afraid of OOM ? > > Signed-off-by: KAMEZAWA Hiroyuki I have only one comment (below). > --- ... > Index: mmotm-0727/kernel/power/user.c > =================================================================== > --- mmotm-0727.orig/kernel/power/user.c > +++ mmotm-0727/kernel/power/user.c > @@ -135,6 +135,7 @@ static int snapshot_release(struct inode > free_basic_memory_bitmaps(); > data = filp->private_data; > free_all_swap_pages(data->swap); > + hibernation_thaw_swap(); free_all_swap_pages() calls hibernation_thaw_swap(), so it doesn't need to be called again. > if (data->frozen) > thaw_processes(); > pm_notifier_call_chain(data->mode == O_WRONLY ? > > > -- Rafael -- 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/