diff mbox

PM / hibernate: Move pm_init/pm_disk_init to late_initcall_sync

Message ID 1444093820-6934-1-git-send-email-wonhong.kwon@lge.com (mailing list archive)
State Accepted, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Wonhong Kwon Oct. 6, 2015, 1:10 a.m. UTC
pm_init is being invoked by core_initcall and hibernate_image_size_init
calculates preferred image size (image_size) based on total pages
(totalram_pages). This totalram_pages can be modified during various
initcall-s phase and this can cause miscalculated image_size.

For example, when CMA is being used, init_cma_reserved_pageblock tries
to change the totalram_pages and this job is done during core_initcall.
In order words, the totalram_pages doesn't take CMA reserved pages into
account when image_size is calculated and it can be too small.

Move pm_init and pm_disk_init to late_initcall_sync so that it happens
after all other initcall-s change the totalram_pages.

Reported-by: Sangseok Lee <sangseok.lee@lge.com>
Signed-off-by: Wonhong Kwon <wonhong.kwon@lge.com>
---
 kernel/power/hibernate.c |    2 +-
 kernel/power/main.c      |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Pavel Machek Oct. 6, 2015, 2:42 p.m. UTC | #1
On Tue 2015-10-06 10:10:20, Wonhong Kwon wrote:
> pm_init is being invoked by core_initcall and hibernate_image_size_init
> calculates preferred image size (image_size) based on total pages
> (totalram_pages). This totalram_pages can be modified during various
> initcall-s phase and this can cause miscalculated image_size.
> 
> For example, when CMA is being used, init_cma_reserved_pageblock tries
> to change the totalram_pages and this job is done during core_initcall.
> In order words, the totalram_pages doesn't take CMA reserved pages into
> account when image_size is calculated and it can be too small.
> 
> Move pm_init and pm_disk_init to late_initcall_sync so that it happens
> after all other initcall-s change the totalram_pages.

Hmm, someone else hit same (similar) problem, but had way more complex solution.

So it is nice this is easy.

But is it enough? Can CMA be modular? Can CMA allocate memory after boot?

THanks,
									Pavel
David Kwon (???) Oct. 7, 2015, 2:08 a.m. UTC | #2
> On Tue 2015-10-06 10:10:20, Wonhong Kwon wrote:
> > pm_init is being invoked by core_initcall and
> > hibernate_image_size_init calculates preferred image size (image_size)
> > based on total pages (totalram_pages). This totalram_pages can be
> > modified during various initcall-s phase and this can cause
> miscalculated image_size.
> >
> > For example, when CMA is being used, init_cma_reserved_pageblock tries
> > to change the totalram_pages and this job is done during core_initcall.
> > In order words, the totalram_pages doesn't take CMA reserved pages
> > into account when image_size is calculated and it can be too small.
> >
> > Move pm_init and pm_disk_init to late_initcall_sync so that it happens
> > after all other initcall-s change the totalram_pages.
> 
> Hmm, someone else hit same (similar) problem, but had way more complex
> solution.
> 
> So it is nice this is easy.
> 
> But is it enough? 

I'm not a MM expert, but AFAIU, lots of things including CMA try to change
totalram_pages during and after boot. For instance, memory is being plugged
out after boot, __offline_pages invokes adjust_managed_page_count and
totalram_pages
can be changed.

However, image_size can be changed by user via sysfs after boot, and I think
user's preferred size should have a high priority than one calculated with
totalram_pages.

So, my patch was intended to calculate default image_size based on more
accurate
totalram_pages during boot, not based on real one on any time after boot.

> Can CMA be modular? Can CMA allocate memory after boot?

AFAIK, CMA cannot intercept any memory after boot. Reserving memory for CMA
area
should be required on early stage.

Thanks,
Wonhong

> 
> THanks,
>
Pavel
> 
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures)
> http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki Oct. 15, 2015, 12:36 a.m. UTC | #3
On Tuesday, October 06, 2015 10:10:20 AM Wonhong Kwon wrote:
> pm_init is being invoked by core_initcall and hibernate_image_size_init
> calculates preferred image size (image_size) based on total pages
> (totalram_pages). This totalram_pages can be modified during various
> initcall-s phase and this can cause miscalculated image_size.
> 
> For example, when CMA is being used, init_cma_reserved_pageblock tries
> to change the totalram_pages and this job is done during core_initcall.
> In order words, the totalram_pages doesn't take CMA reserved pages into
> account when image_size is calculated and it can be too small.
> 
> Move pm_init and pm_disk_init to late_initcall_sync so that it happens
> after all other initcall-s change the totalram_pages.
> 
> Reported-by: Sangseok Lee <sangseok.lee@lge.com>
> Signed-off-by: Wonhong Kwon <wonhong.kwon@lge.com>

Applied, thanks!

Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 690f78f..c7ff849 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1087,7 +1087,7 @@  static int __init pm_disk_init(void)
 	return sysfs_create_group(power_kobj, &attr_group);
 }
 
-core_initcall(pm_disk_init);
+late_initcall_sync(pm_disk_init);
 
 
 static int __init resume_setup(char *str)
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 63d395b..c3e223b 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -643,4 +643,4 @@  static int __init pm_init(void)
 	return pm_autosleep_init();
 }
 
-core_initcall(pm_init);
+late_initcall_sync(pm_init);