Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 186214
b: refs/heads/master
c: 452aa69
h: refs/heads/master
v: v3
  • Loading branch information
Rafael J. Wysocki authored and Linus Torvalds committed Mar 6, 2010
1 parent 72c96e6 commit 7488bbb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ad2bd7e0e9647cd48593a6b3a2be07dc2c2d28ed
refs/heads/master: 452aa6999e6703ffbddd7f6ea124d3968915f3e3
7 changes: 3 additions & 4 deletions trunk/include/linux/gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct vm_area_struct;
#define GFP_HIGHUSER_MOVABLE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
__GFP_HARDWALL | __GFP_HIGHMEM | \
__GFP_MOVABLE)
#define GFP_IOFS (__GFP_IO | __GFP_FS)

#ifdef CONFIG_NUMA
#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
Expand Down Expand Up @@ -337,9 +338,7 @@ void drain_local_pages(void *dummy);

extern gfp_t gfp_allowed_mask;

static inline void set_gfp_allowed_mask(gfp_t mask)
{
gfp_allowed_mask = mask;
}
extern void set_gfp_allowed_mask(gfp_t mask);
extern gfp_t clear_gfp_allowed_mask(gfp_t mask);

#endif /* __LINUX_GFP_H */
2 changes: 1 addition & 1 deletion trunk/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ asmlinkage void __init start_kernel(void)
local_irq_enable();

/* Interrupts are enabled now so all GFP allocations are safe. */
set_gfp_allowed_mask(__GFP_BITS_MASK);
gfp_allowed_mask = __GFP_BITS_MASK;

kmem_cache_init_late();

Expand Down
9 changes: 9 additions & 0 deletions trunk/kernel/power/hibernate.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ static int create_image(int platform_mode)
int hibernation_snapshot(int platform_mode)
{
int error;
gfp_t saved_mask;

error = platform_begin(platform_mode);
if (error)
Expand All @@ -334,6 +335,7 @@ int hibernation_snapshot(int platform_mode)
goto Close;

suspend_console();
saved_mask = clear_gfp_allowed_mask(GFP_IOFS);
error = dpm_suspend_start(PMSG_FREEZE);
if (error)
goto Recover_platform;
Expand All @@ -351,6 +353,7 @@ int hibernation_snapshot(int platform_mode)

dpm_resume_end(in_suspend ?
(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
set_gfp_allowed_mask(saved_mask);
resume_console();
Close:
platform_end(platform_mode);
Expand Down Expand Up @@ -445,14 +448,17 @@ static int resume_target_kernel(bool platform_mode)
int hibernation_restore(int platform_mode)
{
int error;
gfp_t saved_mask;

pm_prepare_console();
suspend_console();
saved_mask = clear_gfp_allowed_mask(GFP_IOFS);
error = dpm_suspend_start(PMSG_QUIESCE);
if (!error) {
error = resume_target_kernel(platform_mode);
dpm_resume_end(PMSG_RECOVER);
}
set_gfp_allowed_mask(saved_mask);
resume_console();
pm_restore_console();
return error;
Expand All @@ -466,6 +472,7 @@ int hibernation_restore(int platform_mode)
int hibernation_platform_enter(void)
{
int error;
gfp_t saved_mask;

if (!hibernation_ops)
return -ENOSYS;
Expand All @@ -481,6 +488,7 @@ int hibernation_platform_enter(void)

entering_platform_hibernation = true;
suspend_console();
saved_mask = clear_gfp_allowed_mask(GFP_IOFS);
error = dpm_suspend_start(PMSG_HIBERNATE);
if (error) {
if (hibernation_ops->recover)
Expand Down Expand Up @@ -518,6 +526,7 @@ int hibernation_platform_enter(void)
Resume_devices:
entering_platform_hibernation = false;
dpm_resume_end(PMSG_RESTORE);
set_gfp_allowed_mask(saved_mask);
resume_console();

Close:
Expand Down
3 changes: 3 additions & 0 deletions trunk/kernel/power/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static int suspend_enter(suspend_state_t state)
int suspend_devices_and_enter(suspend_state_t state)
{
int error;
gfp_t saved_mask;

if (!suspend_ops)
return -ENOSYS;
Expand All @@ -199,6 +200,7 @@ int suspend_devices_and_enter(suspend_state_t state)
goto Close;
}
suspend_console();
saved_mask = clear_gfp_allowed_mask(GFP_IOFS);
suspend_test_start();
error = dpm_suspend_start(PMSG_SUSPEND);
if (error) {
Expand All @@ -215,6 +217,7 @@ int suspend_devices_and_enter(suspend_state_t state)
suspend_test_start();
dpm_resume_end(PMSG_RESUME);
suspend_test_finish("resume devices");
set_gfp_allowed_mask(saved_mask);
resume_console();
Close:
if (suspend_ops->end)
Expand Down
25 changes: 25 additions & 0 deletions trunk/mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ unsigned long totalreserve_pages __read_mostly;
int percpu_pagelist_fraction;
gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;

#ifdef CONFIG_PM_SLEEP
/*
* The following functions are used by the suspend/hibernate code to temporarily
* change gfp_allowed_mask in order to avoid using I/O during memory allocations
* while devices are suspended. To avoid races with the suspend/hibernate code,
* they should always be called with pm_mutex held (gfp_allowed_mask also should
* only be modified with pm_mutex held, unless the suspend/hibernate code is
* guaranteed not to run in parallel with that modification).
*/
void set_gfp_allowed_mask(gfp_t mask)
{
WARN_ON(!mutex_is_locked(&pm_mutex));
gfp_allowed_mask = mask;
}

gfp_t clear_gfp_allowed_mask(gfp_t mask)
{
gfp_t ret = gfp_allowed_mask;

WARN_ON(!mutex_is_locked(&pm_mutex));
gfp_allowed_mask &= ~mask;
return ret;
}
#endif /* CONFIG_PM_SLEEP */

#ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
int pageblock_order __read_mostly;
#endif
Expand Down

0 comments on commit 7488bbb

Please sign in to comment.