public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* swsusp: which page should be saved?
@ 2006-03-16  3:53 Shaohua Li
  2006-03-15 23:08 ` Pavel Machek
  2006-03-16 16:05 ` Rafael J. Wysocki
  0 siblings, 2 replies; 17+ messages in thread
From: Shaohua Li @ 2006-03-16  3:53 UTC (permalink / raw)
  To: Linux-pm mailing list; +Cc: Pavel Machek

[-- Attachment #1: Type: text/plain, Size: 3623 bytes --]

I thought there was a discussion before, but I still saw many pages like
BIOS reserved are saved/restored in swsusp. Pages reserved by BIOS, not
used by OS and kernel text should be skipped in swsusp to me. Below
patch works in my test. Any thought?

Thanks,
Shaohua

---

 linux-2.6.15-root/arch/i386/kernel/setup.c |   78 +++++++++++++++++++++++++++++
 linux-2.6.15-root/kernel/power/snapshot.c  |    1 
 2 files changed, 78 insertions(+), 1 deletion(-)

diff -puN arch/i386/kernel/setup.c~nosave_pages arch/i386/kernel/setup.c
--- linux-2.6.15/arch/i386/kernel/setup.c~nosave_pages	2006-03-14 14:42:24.000000000 +0800
+++ linux-2.6.15-root/arch/i386/kernel/setup.c	2006-03-15 09:38:18.000000000 +0800
@@ -1483,6 +1483,83 @@ static void set_mca_bus(int x)
 static void set_mca_bus(int x) { }
 #endif
 
+extern char __end_rodata;
+static void __init mark_nosave_page_range(unsigned long start, unsigned long end)
+{
+	struct page *page;
+	while (start <= end) {
+		printk("%ld,", start);
+		page = pfn_to_page(start);
+		SetPageNosave(page);
+		start ++;
+	}
+}
+
+static int __init efi_mark_nosave_page(unsigned long start, unsigned long end,
+	void *arg)
+{
+	unsigned long start_pfn, end_pfn, last = *(unsigned long*)arg;
+
+	start_pfn = PFN_DOWN(start);
+	end_pfn = PFN_DOWN(end);
+	/* check max_low_pfn */
+	if (start_pfn >= max_low_pfn)
+		return 0;
+	if (end_pfn >= max_low_pfn)
+		end = max_low_pfn;
+	if (start_pfn > last)
+		mark_nosave_page_range(last, start_pfn - 1);
+	*(unsigned long*)arg = end;
+	return 0;
+}
+
+static void __init mark_nosave_pages(void)
+{
+	unsigned long pfn, pfn_end_rodata, last_pfn = 0;
+	int i;
+
+	/* Mark all BIOS reserved regions as nosave */
+	if (efi_enabled) {
+		efi_memmap_walk(efi_mark_nosave_page, &last_pfn);
+		return;
+	} else {
+		for (i = 0; i < e820.nr_map; i++) {
+			unsigned long start_pfn, end_pfn;
+			if (e820.map[i].type != E820_RAM)
+				continue;
+
+			start_pfn = PFN_DOWN(e820.map[i].addr);
+			if (start_pfn >= max_low_pfn)
+				break;
+			end_pfn = PFN_UP(e820.map[i].addr + e820.map[i].size);
+
+			if (end_pfn > max_low_pfn)
+				end_pfn = max_low_pfn;
+			if (end_pfn <= start_pfn)
+				continue;
+			if (start_pfn > last_pfn) {
+				start_pfn--;
+				mark_nosave_page_range(last_pfn, start_pfn);
+			}
+			last_pfn = end_pfn;
+		}
+	}
+
+	if (last_pfn < max_low_pfn)
+		mark_nosave_page_range(last_pfn, max_low_pfn);
+
+	/* kernel text */
+	pfn = PFN_UP(__pa(__KERNEL_START));
+	pfn_end_rodata = PFN_DOWN(__pa(&__end_rodata));
+	mark_nosave_page_range(pfn, pfn_end_rodata);
+
+	/* other pages kernel doesn't use (see setup_bootmem_allocator) */
+	mark_nosave_page_range(0, 0);
+#ifdef CONFIG_SMP
+	mark_nosave_page_range(PFN_DOWN(PAGE_SIZE), PFN_DOWN(PAGE_SIZE));
+#endif
+}
+
 /*
  * Determine if we were loaded by an EFI loader.  If so, then we have also been
  * passed the efi memmap, systab, etc., so we should use these data structures
@@ -1573,6 +1650,7 @@ void __init setup_arch(char **cmdline_p)
 	remapped_pgdat_init();
 	sparse_init();
 	zone_sizes_init();
+	mark_nosave_pages();
 
 	/*
 	 * NOTE: at this point the bootmem allocator is fully available.
diff -puN kernel/power/snapshot.c~nosave_pages kernel/power/snapshot.c
--- linux-2.6.15/kernel/power/snapshot.c~nosave_pages	2006-03-14 14:42:29.000000000 +0800
+++ linux-2.6.15-root/kernel/power/snapshot.c	2006-03-14 14:43:06.000000000 +0800
@@ -173,7 +173,6 @@ static int saveable(struct zone *zone, u
 		return 0;
 
 	page = pfn_to_page(pfn);
-	BUG_ON(PageReserved(page) && PageNosave(page));
 	if (PageNosave(page))
 		return 0;
 	if (PageReserved(page) && pfn_is_nosave(pfn))
_



[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: Re: swsusp: which page should be saved?
@ 2006-03-21  3:11 Yu, Luming
  0 siblings, 0 replies; 17+ messages in thread
From: Yu, Luming @ 2006-03-21  3:11 UTC (permalink / raw)
  To: Li, Shaohua, Pavel Machek; +Cc: Linux-pm mailing list

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

>> > Anyway, skipping kernel text should be safe, isn't it?
>> 
>> It probably is. But you need to save modules. 
>I just consider the region from kernel start(1M) to the end of rodata.
>In my test, the region is about 4M memory. Just adding several lines to
>save 4M memory is worthy.

Why it is safe? :-)  If you think BIOS as a black box, and don't know
how BIOS works,
then, you have to save them for safety concern. 


[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: Re: swsusp: which page should be saved?
@ 2006-03-21  3:23 Yu, Luming
  2006-03-21  3:33 ` Shaohua Li
  0 siblings, 1 reply; 17+ messages in thread
From: Yu, Luming @ 2006-03-21  3:23 UTC (permalink / raw)
  To: Yu, Luming, Li, Shaohua, Pavel Machek; +Cc: Linux-pm mailing list

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

>>> > Anyway, skipping kernel text should be safe, isn't it?
>>> 
>>> It probably is. But you need to save modules. 
>>I just consider the region from kernel start(1M) to the end of rodata.
>>In my test, the region is about 4M memory. Just adding 
>several lines to
>>save 4M memory is worthy.
>
>Why it is safe? :-)  If you think BIOS as a black box, and don't know
>how BIOS works,
>then, you have to save them for safety concern. 
>
s/BIOS/Modules/


[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: Re: swsusp: which page should be saved?
@ 2006-03-21  3:41 Yu, Luming
  0 siblings, 0 replies; 17+ messages in thread
From: Yu, Luming @ 2006-03-21  3:41 UTC (permalink / raw)
  To: Li, Shaohua; +Cc: Linux-pm mailing list

[-- Attachment #1: Type: text/plain, Size: 751 bytes --]

>> >>> It probably is. But you need to save modules. 
>> >>I just consider the region from kernel start(1M) to the 
>end of rodata.
>> >>In my test, the region is about 4M memory. Just adding 
>> >several lines to
>> >>save 4M memory is worthy.
>> >
>> >Why it is safe? :-)  If you think BIOS as a black box, and 
>don't know
>> >how BIOS works,
>> >then, you have to save them for safety concern. 
>> >
>> s/BIOS/Modules/
>As I said, I just consider the region from kernel start to the end of
>rodata (get from the link script). modules should be saved/restored as
>normal.

I'm not sure if this a real case, but I'm sure in this case
kernel text needs to be saved too if  the kernel 
has been patched with binary patch at run-time.

Thanks,
Luming


[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: Re: swsusp: which page should be saved?
@ 2006-03-21  4:25 Yu, Luming
  0 siblings, 0 replies; 17+ messages in thread
From: Yu, Luming @ 2006-03-21  4:25 UTC (permalink / raw)
  To: Yu, Luming, Li, Shaohua; +Cc: Linux-pm mailing list

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

>>> >>> It probably is. But you need to save modules. 
>>> >>I just consider the region from kernel start(1M) to the 
>>end of rodata.
>>> >>In my test, the region is about 4M memory. Just adding 
>>> >several lines to
>>> >>save 4M memory is worthy.
>>> >
>>> >Why it is safe? :-)  If you think BIOS as a black box, and 
>>don't know
>>> >how BIOS works,
>>> >then, you have to save them for safety concern. 
>>> >
>>> s/BIOS/Modules/
>>As I said, I just consider the region from kernel start to the end of
>>rodata (get from the link script). modules should be saved/restored as
>>normal.
>
>I'm not sure if this a real case, but I'm sure in this case
>kernel text needs to be saved too if  the kernel 
>has been patched with binary patch at run-time.

Another real case is that the image on disk has been changed ?
But probably, user need previous S4 resume back correctly.

Yes, all these are corner cases. 


[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-04-11  7:52 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-16  3:53 swsusp: which page should be saved? Shaohua Li
2006-03-15 23:08 ` Pavel Machek
2006-03-17  1:12   ` Shaohua Li
2006-03-17  6:59     ` Pavel Machek
2006-03-21  2:19       ` Shaohua Li
2006-03-21  3:33         ` Nigel Cunningham
2006-03-21  9:42         ` Pavel Machek
2006-04-07  3:46           ` Shaohua Li
2006-04-11  7:39             ` Pavel Machek
2006-04-11  7:52               ` Shaohua Li
2006-03-17 10:50     ` Rafael J. Wysocki
2006-03-16 16:05 ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2006-03-21  3:11 Yu, Luming
2006-03-21  3:23 Yu, Luming
2006-03-21  3:33 ` Shaohua Li
2006-03-21  3:41 Yu, Luming
2006-03-21  4:25 Yu, Luming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox