mm: avoid livelock on !__GFP_FS allocations
Subsystems (2)
PATCH 1/1 mm: avoid livelock on !__GFP_FS allocations
Under the following conditions, __alloc_pages_slowpath can loop forever:gfp_mask & __GFP_WAIT is truegfp_mask & __GFP_FS is false
reclaim and compaction make no progress
order <= PAGE_ALLOC_COSTLY_ORDER
These conditions happen very often during suspend and resume, when pm_restrict_gfp_mask() effectively converts all GFP_KERNEL allocations into __GFP_WAIT.
The oom killer is not run because gfp_mask & __GFP_FS is false, but should_alloc_retry will always return true when order is less than PAGE_ALLOC_COSTLY_ORDER.
Fix __alloc_pages_slowpath to skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.
---
An alternative patch would add a did_some_progress argument to __alloc_pages_may_oom, and remove the checks in __alloc_pages_slowpath that require knowledge of when __alloc_pages_may_oom chooses to run out_of_memory. If did_some_progress was still zero, it would goto nopage whether or not __alloc_pages_may_oom was actually called.
mm/page_alloc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
mm/page_alloc.c +4 -0
@@ -2193,6 +2193,10 @@ rebalance: } goto restart; + }else { +/* If we aren't going to try the OOM killer, give up */ +if (!(gfp_mask & __GFP_NOFAIL)) + goto nopage; } }
Signature · 8 lines
1.7.4.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.
Why does it do that? Why don't we fix the gfp mask instead?
Quoted 26 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>---
An alternative patch would add a
did_some_progressargument to__alloc_pages_may_oom, and remove the checks in__alloc_pages_slowpaththat require knowledge of when__alloc_pages_may_oomchooses to runout_of_memory. Ifdid_some_progresswas still zero, it would goto nopage whether or not__alloc_pages_may_oomwas actually called.mm/page_alloc.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)mm/page_alloc.c +0
-0
mm/page_alloc.c rebalance: · line 2201
Quoted 9 lines
mm/page_alloc.c +4
-0@@ -2193,6 +2193,10 @@ rebalance: } goto restart; + } else { + /* If we aren't going to try the OOM killer, give up */ + if (!(gfp_mask & __GFP_NOFAIL)) + goto nopage; } }
I don't quite understand how __GFP_WAIT is involved here. Which path is causing the infinite loop?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Pekka Enberg
Quoted 7 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDER
Quoted 5 lines
Quoted 3 lines
These conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.Why does it do that? Why don't we fix the gfp mask instead?
It disables __GFP_IO and __GFP_FS because the IO drivers may be suspended.
Quoted 28 lines
Quoted 28 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>---
An alternative patch would add a
did_some_progressargument to__alloc_pages_may_oom, and remove the checks in__alloc_pages_slowpaththat require knowledge of when__alloc_pages_may_oomchooses to runout_of_memory. Ifdid_some_progresswas still zero, it would goto nopage whether or not__alloc_pages_may_oomwas actually called.mm/page_alloc.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)mm/page_alloc.c +0
-0@@ -2193,6 +2193,10 @@ rebalance: }
Quoted 10 lines
mm/page_alloc.c rebalance: · line 2201
Quoted 7 lines
mm/page_alloc.c +4
-0goto restart; + } else { + /* If we aren't going to try the OOM killer, give up */ + if (!(gfp_mask & __GFP_NOFAIL)) + goto nopage; } }I don't quite understand how
__GFP_WAITis involved here. Which path is causing the infinite loop?
GFP_KERNEL is __GFP_WAIT | __GFP_IO | __GFP_FS. Once driver suspend has started, gfp_allowed_mask is ~(__GFP_IO | GFP_FS), so any call to __alloc_pages_nodemask(GFP_KERNEL, ...) gets masked to effectively __alloc_pages_nodemask(__GFP_WAIT, ...).
The loop is in __alloc_pages_slowpath, from the rebalance label to should_alloc_retry. Under the conditions I listed in the commit message, there is no path to the nopage label, because all the relevant "goto nopage" lines that would normally allow a GFP_KERNEL allocation to fail are inside a check for __GFP_FS.
Modifying the gfp_allowed_mask would not completely fix the issue, a GFP_NOIO allocation can meet the conditions outside of suspend. gfp_allowed_mask just makes the issue more likely, by converting GFP_KERNEL into GFP_NOIO.
Pekka Enberg
Acked-byHi Colin,
Quoted 10 lines · Colin Cross
Quoted 10 lines
Quoted 10 lines
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.
Quoted 1 line · Pekka Enberg
Quoted 1 line
Why does it do that? Why don't we fix the gfp mask instead?
Quoted 1 line · Colin Cross
It disables
__GFP_IOand__GFP_FSbecause the IO drivers may be suspended.
Sure but why doesn't it clear __GFP_WAIT too?
Quoted 44 lines
Quoted 28 lines
Quoted 28 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>---
An alternative patch would add a
did_some_progressargument to__alloc_pages_may_oom, and remove the checks in__alloc_pages_slowpaththat require knowledge of when__alloc_pages_may_oomchooses to runout_of_memory. Ifdid_some_progresswas still zero, it would goto nopage whether or not__alloc_pages_may_oomwas actually called.mm/page_alloc.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)mm/page_alloc.c +0
-0@@ -2193,6 +2193,10 @@ rebalance: }Quoted 10 lines
mm/page_alloc.c rebalance: · line 2201
Quoted 7 lines
mm/page_alloc.c +4
-0goto restart; + } else { + /* If we aren't going to try the OOM killer, give up */ + if (!(gfp_mask & __GFP_NOFAIL)) + goto nopage; } }I don't quite understand how
__GFP_WAITis involved here. Which path is causing the infinite loop?
GFP_KERNELis__GFP_WAIT|__GFP_IO|__GFP_FS. Once driver suspend has started,gfp_allowed_maskis ~(__GFP_IO |GFP_FS), so any call to__alloc_pages_nodemask(GFP_KERNEL, ...)gets masked to effectively__alloc_pages_nodemask(__GFP_WAIT, ...).
Quoted 5 lines
The loop is in
__alloc_pages_slowpath, from the rebalance label toshould_alloc_retry. Under the conditions I listed in the commit message, there is no path to the nopage label, because all the relevant "goto nopage" lines that would normally allow aGFP_KERNELallocation to fail are inside a check for__GFP_FS.
Right. Please include that information in the changelog.
Quoted 4 lines
Modifying the
gfp_allowed_maskwould not completely fix the issue, aGFP_NOIOallocation can meet the conditions outside of suspend.gfp_allowed_maskjust makes the issue more likely, by convertingGFP_KERNELintoGFP_NOIO.
Why would anyone want to combine __GFP_WAIT, __GFP_NOFAIL and !__GFP_IO on purpose? What is it useful for?
As for your patch:
but I'd love to hear why we shouldn't also fix the suspend gfp mask to clear __GFP_WAIT and add a WARN_ON_ONCE to your new code path.
Pekka
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.
b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>
Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
That said, it will be difficult to remember why checking __GFP_NOFAIL in this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)
mm/page_alloc.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
mm/page_alloc.c +22 -0
@@ -127,6 +127,20 @@ void pm_restrict_gfp_mask(void) saved_gfp_mask = gfp_allowed_mask; gfp_allowed_mask &= ~GFP_IOFS; } + +static bool pm_suspending (void ) +{ +if ((gfp_allowed_mask &GFP_IOFS ) ==GFP_IOFS ) +return false; +return true; +} + +#else + +static bool pm_suspending (void ) +{ +return false; +}#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
@@ -2207,6 +2221,14 @@ rebalance: goto restart; } + +/* +* Suspend converts GFP_KERNEL to __GFP_WAIT which can +* prevent reclaim making forward progress without +* invoking OOM. Bail if we are suspending +*/ +if (pm_suspending ()) + goto nopage; }/* Check if we should retry the allocation */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 29 lines · Mel Gorman
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
Quoted 4 lines
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)
This issue is not limited to suspend, any GFP_NOIO allocation could end up in the same loop. Suspend is the most likely case, because it effectively converts all GFP_KERNEL allocations into GFP_NOIO.
Quoted 34 lines
mm/page_alloc.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)mm/page_alloc.c +15
-0@@ -127,6 +127,20 @@ void pm_restrict_gfp_mask(void) saved_gfp_mask = gfp_allowed_mask; gfp_allowed_mask &= ~GFP_IOFS; } + +static bool pm_suspending (void ) +{ + if ((gfp_allowed_mask & GFP_IOFS) == GFP_IOFS) + return false; + return true; +} + +#else + +static bool pm_suspending (void ) +{ + return false; +} #endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE@@ -2207,6 +2221,14 @@ rebalance: goto restart; } +
mm/page_alloc.c rebalance: · line 2234
Quoted 10 lines
mm/page_alloc.c +7
-0+ /* + * Suspend converts GFP_KERNEL to __GFP_WAIT which can + * prevent reclaim making forward progress without + * invoking OOM. Bail if we are suspending + */ + if (pm_suspending()) + goto nopage; } /* Check if we should retry the allocation */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 30 lines · Colin Cross
Quoted 29 lines · Mel Gorman
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
Quoted 9 lines
Quoted 4 lines
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)This issue is not limited to suspend, any
GFP_NOIOallocation could end up in the same loop. Suspend is the most likely case, because it effectively converts allGFP_KERNELallocations intoGFP_NOIO.
I see what you mean with GFP_NOIO but there is an important difference between GFP_NOIO and suspend. A GFP_NOIO low-order allocation currently implies __GFP_NOFAIL as commented on in should_alloc_retry(). If no progress is made, we call wait_iff_congested() and sleep for a bit. As the system is running, kswapd and other process activity will proceed and eventually reclaim enough pages for the GFP_NOIO allocation to succeed. In a running system, GFP_NOIO can stall for a period of time but your patch will cause the allocation to fail. While I expect callers return ENOMEM or handle the situation properly with a wait-and-retry loop, there will be operations that fail that used to succeed. This is why I'd prefer it was a suspend-specific fix unless we know there is a case where a machine livelocks due to a GFP_NOIO allocation looping forever and even then I'd wonder why kswapd was not helping.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 41 lines · Mel Gorman
Quoted 30 lines · Colin Cross
Quoted 29 lines · Mel Gorman
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
Quoted 9 lines
Quoted 4 lines
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)This issue is not limited to suspend, any
GFP_NOIOallocation could end up in the same loop. Suspend is the most likely case, because it effectively converts allGFP_KERNELallocations intoGFP_NOIO.
Quoted 13 lines
I see what you mean with
GFP_NOIObut there is an important difference betweenGFP_NOIOand suspend. AGFP_NOIOlow-order allocation currently implies__GFP_NOFAILas commented on inshould_alloc_retry(). If no progress is made, we callwait_iff_congested()and sleep for a bit. As the system is running, kswapd and other process activity will proceed and eventually reclaim enough pages for theGFP_NOIOallocation to succeed. In a running system,GFP_NOIOcan stall for a period of time but your patch will cause the allocation to fail. While I expect callers return ENOMEM or handle the situation properly with a wait-and-retry loop, there will be operations that fail that used to succeed. This is why I'd prefer it was a suspend-specific fix unless we know there is a case where a machine livelocks due to aGFP_NOIOallocation looping forever and even then I'd wonder why kswapd was not helping.
OK, I see the change in behavior you are trying to avoid. With your patch GFP_NOIO allocations can still fail during suspend, is that OK? I'm also worried about GFP_NOIO allocations looping forever when swap is not enabled, but I've never seen it happen, and it would probably recover eventually when another tried tried a GFP_KERNEL allocation and oom killed something.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Colin Cross
Tested-byQuoted 68 lines · Mel Gorman
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)mm/page_alloc.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)mm/page_alloc.c +15
-0@@ -127,6 +127,20 @@ void pm_restrict_gfp_mask(void) saved_gfp_mask = gfp_allowed_mask; gfp_allowed_mask &= ~GFP_IOFS; } + +static bool pm_suspending (void ) +{ + if ((gfp_allowed_mask & GFP_IOFS) == GFP_IOFS) + return false; + return true; +} + +#else + +static bool pm_suspending (void ) +{ + return false; +} #endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE@@ -2207,6 +2221,14 @@ rebalance: goto restart; } +
mm/page_alloc.c rebalance: · line 2234
Quoted 10 lines
mm/page_alloc.c +7
-0+ /* + * Suspend converts GFP_KERNEL to __GFP_WAIT which can + * prevent reclaim making forward progress without + * invoking OOM. Bail if we are suspending + */ + if (pm_suspending()) + goto nopage; } /* Check if we should retry the allocation */
Your patch solves my immediate problem.
Hi Mel,
Quoted 5 lines · Mel Gorman
I see what you mean with
GFP_NOIObut there is an important difference betweenGFP_NOIOand suspend. AGFP_NOIOlow-order allocation currently implies__GFP_NOFAILas commented on inshould_alloc_retry(). If no progress is made, we callwait_iff_congested()and sleep for a bit. As the system is running, kswapd and other process activity will proceed and eventually
Quoted 8 lines
reclaim enough pages for the
GFP_NOIOallocation to succeed. In a running system,GFP_NOIOcan stall for a period of time but your patch will cause the allocation to fail. While I expect callers return ENOMEM or handle the situation properly with a wait-and-retry loop, there will be operations that fail that used to succeed. This is why I'd prefer it was a suspend-specific fix unless we know there is a case where a machine livelocks due to aGFP_NOIOallocation looping forever and even then I'd wonder why kswapd was not helping.
I'm not that happy about your patch because it's going to the direction where the page allocator is special-casing for suspension. If you don't think it's a good idea to fix it for the general case (i.e. Colin's patch), why don't we fix it up in a way that suspension code passes sane GFP flags?
Pekka
Quoted 7 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDER
The oom killer is only called for __GFP_FS because we want to ensure that we don't inadvertently kill something if we didn't have a chance to at least make a good effort at direct reclaim. There's a very high liklihood that direct reclaim would succeed with __GFP_FS, so we loop endlessly waiting for either kswapd to reclaim in the background even though it might not be able to because of filesystem locks or another allocation happens in a context that allows reclaim to succeed or oom killing.
For low-order allocations (those at or below PAGE_ALLOC_COSTLY_ORDER) where fragmentation isn't a huge issue, __GFP_WAIT && !__GFP_FS && !did_some_progress makes sense.
Quoted 4 lines
These conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.
This is the problem. All allocations now have no chance of ever having direct reclaim succeed nor the oom killer called. It seems like you would want pm_restrict_gfp_mask() to also include __GFP_NORETRY and ensure it can never be called for __GFP_NOFAIL.
Quoted 5 lines
mm/page_alloc.c +0
-0
mm/page_alloc.c rebalance: · line 2202
Quoted 10 lines
mm/page_alloc.c +4
-0@@ -2193,6 +2193,10 @@ rebalance: } goto restart; + }else { +/* If we aren't going to try the OOM killer, give up */ +if (!(gfp_mask & __GFP_NOFAIL)) + goto nopage; } }
Nack on this, it is going to cause many very verbose allocation failures (if !__GFP_NOWARN) when not using suspend because we're not in a context where we can do sensible reclaim or compaction and presently kswapd can either reclaim or another allocation will allow low-order amounts of memory to be reclaimed or the oom killer to free some memory. It would introduce a regression into page allocation.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Colin Cross
GFP_KERNELis__GFP_WAIT|__GFP_IO|__GFP_FS. Once driver suspend has started,gfp_allowed_maskis ~(__GFP_IO |GFP_FS), so any call to__alloc_pages_nodemask(GFP_KERNEL, ...)gets masked to effectively__alloc_pages_nodemask(__GFP_WAIT, ...).
Just passing __GFP_WAIT is the problem that you're trying to address, though. Why not include __GFP_NORETRY since you know the liklihood of allocation being successful on the second iteration is very slim since you're not in a context where you can force reclaim or oom killing?
Quoted 2 lines
The loop is in
__alloc_pages_slowpath, from the rebalance label toshould_alloc_retry.
The loop is by design and is activated because you're just passing __GFP_WAIT in this context for no sensible reason.
Quoted 5 lines · Mel Gorman
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)
__GFP_NOFAIL _should_ be optimized away in this case because all he's passing is __GFP_WAIT | __GFP_NOFAIL. That doesn't make any sense unless all you want to do is livelock.
__GFP_NOFAIL doesn't mean the page allocator would infinitely loop in all conditions. That's why GFP_ATOMIC | __GFP_NOFAIL actually fails, and I would argue that __GFP_WAIT | __GFP_NOFAIL should fail as well since it's the exact same condition except doesn't have access to the extra memory reserves.
Suspend needs to either set __GFP_NORETRY to avoid the livelock if it's going to disable all means of memory reclaiming or freeing in the page allocator. Or, better yet, just make it GFP_NOWAIT.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · David Rientjes
Quoted 5 lines · Mel Gorman
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)
__GFP_NOFAIL_should_ be optimized away in this case because all he's passing is__GFP_WAIT|__GFP_NOFAIL. That doesn't make any sense unless all you want to do is livelock.
__GFP_NOFAIL is not set in the case that I care about. If my change is hit, no forward progress has been made, so I agree it should not honor __GFP_NOFAIL.
Quoted 10 lines
__GFP_NOFAILdoesn't mean the page allocator would infinitely loop in all conditions. That's whyGFP_ATOMIC|__GFP_NOFAILactually fails, and I would argue that__GFP_WAIT|__GFP_NOFAILshould fail as well since it's the exact same condition except doesn't have access to the extra memory reserves.Suspend needs to either set
__GFP_NORETRYto avoid the livelock if it's going to disable all means of memory reclaiming or freeing in the page allocator. Or, better yet, just make itGFP_NOWAIT.
It would be nice to give compaction and the slab shrinker a chance to recover a few pages, both methods will work fine in suspend. GFP_NOWAIT will prevent them from ever running, and __GFP_NORETRY will give up even if they are making progress but haven't recovered enough pages.
Converting suspend to GFP_NOWAIT would simply be ~GFP_KERNEL instead of ~GFP_IOFS in pm_restrict_gfp_mask().
Quoted 8 lines · Colin Cross
Quoted 8 lines · Mel Gorman
Quoted 6 lines
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)
Quoted 8 lines
Quoted 3 lines
__GFP_NOFAIL_should_ be optimized away in this case because all he's passing is__GFP_WAIT|__GFP_NOFAIL. That doesn't make any sense unless all you want to do is livelock.
__GFP_NOFAILis not set in the case that I care about. If my change is hit, no forward progress has been made, so I agree it should not honor__GFP_NOFAIL.
I was responding to Mel's comment, not your case.
Quoted 6 lines
Quoted 6 lines
__GFP_NOFAILdoesn't mean the page allocator would infinitely loop in all conditions. That's whyGFP_ATOMIC|__GFP_NOFAILactually fails, and I would argue that__GFP_WAIT|__GFP_NOFAILshould fail as well since it's the exact same condition except doesn't have access to the extra memory reserves.
Quoted 7 lines
Quoted 4 lines
Suspend needs to either set
__GFP_NORETRYto avoid the livelock if it's going to disable all means of memory reclaiming or freeing in the page allocator. Or, better yet, just make itGFP_NOWAIT.It would be nice to give compaction and the slab shrinker a chance to recover a few pages, both methods will work fine in suspend.
Ok, so __GFP_NORETRY it is. Just make sure that when pm_restrict_gfp_mask() masks off __GFP_IO and __GFP_FS that it also sets __GFP_NORETRY even though the name of the function no longer seems appropriate anymore.
Quoted 4 lines
GFP_NOWAITwill prevent them from ever running, and__GFP_NORETRYwill give up even if they are making progress but haven't recovered enough pages.
These are all order-3 or smaller allocations where fragmentation isn't a big issue. If a call into direct compaction or reclaim fails to reclaim that small amount of contiguous memory, what makes you believe that a second call will?
Quoted 5 lines · David Rientjes
Ok, so
__GFP_NORETRYit is. Just make sure that whenpm_restrict_gfp_mask()masks off__GFP_IOand__GFP_FSthat it also sets__GFP_NORETRYeven though the name of the function no longer seems appropriate anymore.
Or, rather, when pm_restrict_gfp_mask() clears __GFP_IO and __GFP_FS that it also has the same behavior as __GFP_NORETRY in should_alloc_retry() by setting a variable in file scope.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · David Rientjes
Quoted 5 lines · David Rientjes
Ok, so
__GFP_NORETRYit is. Just make sure that whenpm_restrict_gfp_mask()masks off__GFP_IOand__GFP_FSthat it also sets__GFP_NORETRYeven though the name of the function no longer seems appropriate anymore.
Quoted 4 lines
Or, rather, when
pm_restrict_gfp_mask()clears__GFP_IOand__GFP_FSthat it also has the same behavior as__GFP_NORETRYinshould_alloc_retry()by setting a variable in file scope.
Why do you prefer that over adding a gfp_required_mask?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Colin Cross
Quoted 4 lines
Or, rather, when
pm_restrict_gfp_mask()clears__GFP_IOand__GFP_FSthat it also has the same behavior as__GFP_NORETRYinshould_alloc_retry()by setting a variable in file scope.Why do you prefer that over adding a
gfp_required_mask?
Because it avoids an unnecessary OR in the page and slab allocator fastpaths which are red hot :)
Quoted 7 lines · David Rientjes
Quoted 5 lines · Colin Cross
Quoted 4 lines
Or, rather, when
pm_restrict_gfp_mask()clears__GFP_IOand__GFP_FSthat it also has the same behavior as__GFP_NORETRYinshould_alloc_retry()by setting a variable in file scope.
Quoted 6 lines
Quoted 2 lines
Why do you prefer that over adding a
gfp_required_mask?Because it avoids an unnecessary OR in the page and slab allocator fastpaths which are red hot :)
Makes sense. What about this? Official patch to follow.
mm/page_alloc.c +7 -0
@@ -1786,6 +1786,13 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order,return 0 ;/* +* If PM has disabled I/O, OOM is disabled and reclaim is unlikely +* to make any progress. To prevent a livelock, don't retry. +*/ +if (!(gfp_allowed_mask & __GFP_FS)) +return 0 ; + +/* * In this implementation, order <= PAGE_ALLOC_COSTLY_ORDER * means __GFP_NOFAIL, but that may not be true in other * implementations.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Colin Cross
Makes sense. What about this? Official patch to follow.
mm/page_alloc.c +0
-0@@ -1786,6 +1786,13 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order,return 0 ;/*
mm/page_alloc.c should_alloc_retry(gfp_t gfp_mask, unsigned int order, · line 1798
Quoted 10 lines
mm/page_alloc.c +7
-0+* If PM has disabled I/O, OOM is disabled and reclaim is unlikely +* to make any progress. To prevent a livelock, don't retry. +*/ +if (!(gfp_allowed_mask & __GFP_FS)) +return 0 ; + +/* * In this implementation, order <= PAGE_ALLOC_COSTLY_ORDER * means __GFP_NOFAIL, but that may not be true in other * implementations.
Eek, this is precisely what we don't want and is functionally the same as what you initially proposed except it doesn't care about __GFP_NOFAIL.
You're trying to address a suspend issue where nothing on the system can logically make progress because __GFP_FS seriously restricts the ability of reclaim to do anything useful if it doesn't succeed the first time and kswapd isn't effective. That's why I suggested a hook into pm_restrict_gfp_mask() to set a variable and then treat it exactly as __GFP_NORETRY in should_alloc_retry().
Consider if nobody is using suspend and they are allocating with GFP_NOFS. There's potentially a lot of candidates:
$ grep -r GFP_NOFS * | wc -l 1016
and now we've just introduced a regression where the allocation would eventually succeed because of either kswapd, a backing device that is no longer congested, or an allocation on another cpu in a context where direct reclaim can be more aggressive or the oom killer can at least free some memory.
So you definitely want to localize your change to only suspend and pm_restrict_gfp_mask() is a very easy way to do it. So I'd suggest adding a static bool that can be tested in should_alloc_retry() and identify such situations and tag it as __read_mostly.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · David Rientjes
Quoted 9 lines · Colin Cross
Makes sense. What about this? Official patch to follow.
mm/page_alloc.c +0
-0@@ -1786,6 +1786,13 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order, return 0;
Quoted 14 lines
mm/page_alloc.c should_alloc_retry(gfp_t gfp_mask, unsigned int order, · line 1798
Quoted 11 lines
mm/page_alloc.c +7
-0/* + * If PM has disabled I/O, OOM is disabled and reclaim is unlikely + * to make any progress. To prevent a livelock, don't retry. + */ + if (!(gfp_allowed_mask & __GFP_FS)) + return 0; + + /** In this implementation, order <= PAGE_ALLOC_COSTLY_ORDER * means __GFP_NOFAIL, but that may not be true in other * implementations. Eek, this is precisely what we don't want and is functionally the same as what you initially proposed except it doesn't care about
__GFP_NOFAIL.
This is checking against gfp_allowed_mask, not gfp_mask.
Quoted 24 lines
You're trying to address a suspend issue where nothing on the system can logically make progress because
__GFP_FSseriously restricts the ability of reclaim to do anything useful if it doesn't succeed the first time and kswapd isn't effective. That's why I suggested a hook intopm_restrict_gfp_mask()to set a variable and then treat it exactly as__GFP_NORETRYinshould_alloc_retry().Consider if nobody is using suspend and they are allocating with
GFP_NOFS. There's potentially a lot of candidates:$ grep -r GFP_NOFS * | wc -l 1016and now we've just introduced a regression where the allocation would eventually succeed because of either kswapd, a backing device that is no longer congested, or an allocation on another cpu in a context where direct reclaim can be more aggressive or the oom killer can at least free some memory.
So you definitely want to localize your change to only suspend and
pm_restrict_gfp_mask()is a very easy way to do it. So I'd suggest adding a static bool that can be tested inshould_alloc_retry()and identify such situations and tag it as__read_mostly.
Quoted 22 lines · Colin Cross
Quoted 7 lines
Quoted 7 lines
mm/page_alloc.c +0
-0@@ -1786,6 +1786,13 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order, return 0;Quoted 14 lines
mm/page_alloc.c should_alloc_retry(gfp_t gfp_mask, unsigned int order, · line 1798
Quoted 11 lines
mm/page_alloc.c +7
-0/* + * If PM has disabled I/O, OOM is disabled and reclaim is unlikely + * to make any progress. To prevent a livelock, don't retry. + */ + if (!(gfp_allowed_mask & __GFP_FS)) + return 0; + + /** In this implementation, order <= PAGE_ALLOC_COSTLY_ORDER * means __GFP_NOFAIL, but that may not be true in other * implementations. Eek, this is precisely what we don't want and is functionally the same as what you initially proposed except it doesn't care about
__GFP_NOFAIL.
Quoted 2 lines
This is checking against
gfp_allowed_mask, notgfp_mask.
gfp_allowed_mask is initialized to GFP_BOOT_MASK to start so that __GFP_FS is never allowed before the slab allocator is completely initialized, so you've now implicitly made all early boot allocations to be __GFP_NORETRY even though they may not pass it.
Quoted 24 lines · David Rientjes
Quoted 22 lines · Colin Cross
Quoted 21 lines
Quoted 8 lines
mm/page_alloc.c +0
-0@@ -1786,6 +1786,13 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order, return 0; /*mm/page_alloc.c should_alloc_retry(gfp_t gfp_mask, unsigned int order, · line 1798
Quoted 10 lines
mm/page_alloc.c +7
-0+* If PM has disabled I/O, OOM is disabled and reclaim is unlikely +* to make any progress. To prevent a livelock, don't retry. +*/ + if (!(gfp_allowed_mask & __GFP_FS)) + return 0; + + /** In this implementation, order <= PAGE_ALLOC_COSTLY_ORDER * means __GFP_NOFAIL, but that may not be true in other * implementations. Eek, this is precisely what we don't want and is functionally the same as what you initially proposed except it doesn't care about
__GFP_NOFAIL.
Quoted 7 lines
Quoted 2 lines
This is checking against
gfp_allowed_mask, notgfp_mask.
gfp_allowed_maskis initialized toGFP_BOOT_MASKto start so that__GFP_FSis never allowed before the slab allocator is completely initialized, so you've now implicitly made all early boot allocations to be__GFP_NORETRYeven though they may not pass it.
Only before interrupts are enabled, and then isn't it vulnerable to the same livelock? Interrupts are off, single cpu, kswapd can't run. If an allocation ever failed, which seems unlikely, why would retrying help?
Quoted 10 lines · Colin Cross
Quoted 4 lines
gfp_allowed_maskis initialized toGFP_BOOT_MASKto start so that__GFP_FSis never allowed before the slab allocator is completely initialized, so you've now implicitly made all early boot allocations to be__GFP_NORETRYeven though they may not pass it.Only before interrupts are enabled, and then isn't it vulnerable to the same livelock? Interrupts are off, single cpu, kswapd can't run. If an allocation ever failed, which seems unlikely, why would retrying help?
If you want to claim gfp_allowed_mask as a pm-only entity, then I see no problem with this approach. However, if gfp_allowed_mask would be allowed to temporarily change after init for another purpose then it would make sense to retry because another allocation with __GFP_FS on another cpu or kswapd could start making progress could allow for future memory freeing.
The suggestion to add a hook directly into a pm-interface was so that we could isolate it only to suspend and, to me, is the most maintainable solution.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · David Rientjes
Quoted 10 lines · Colin Cross
Quoted 4 lines
gfp_allowed_maskis initialized toGFP_BOOT_MASKto start so that__GFP_FSis never allowed before the slab allocator is completely initialized, so you've now implicitly made all early boot allocations to be__GFP_NORETRYeven though they may not pass it.Only before interrupts are enabled, and then isn't it vulnerable to the same livelock? Interrupts are off, single cpu, kswapd can't run. If an allocation ever failed, which seems unlikely, why would retrying help?
If you want to claim
gfp_allowed_maskas a pm-only entity, then I see no problem with this approach. However, ifgfp_allowed_maskwould be allowed to temporarily change after init for another purpose then it would make sense to retry because another allocation with__GFP_FSon another cpu or kswapd could start making progress could allow for future memory freeing.
Quoted 4 lines
The suggestion to add a hook directly into a pm-interface was so that we could isolate it only to suspend and, to me, is the most maintainable solution.
pm_restrict_gfp_mask seems to claim gfp_allowed_mask as owned by pm at runtime:
"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"
I think we've wrapped around to Mel's original patch, which adds a pm_suspending() helper that is implemented next to pm_restrict_gfp_mask. His patch puts the check inside !did_some_progress instead of should_alloc_retry, which I prefer as it at least keeps trying until reclaim isn't working. Pekka was trying to avoid adding pm-specific checks into the allocator, which is why I stuck to the symptom (__GFP_FS is clear) rather than the cause (PM).
Quoted 56 lines · Colin Cross
Quoted 41 lines · Mel Gorman
Quoted 30 lines · Colin Cross
Quoted 29 lines · Mel Gorman
Quoted 10 lines · Colin Cross
Under the following conditions,
__alloc_pages_slowpathcan loop forever:gfp_mask&__GFP_WAITis truegfp_mask&__GFP_FSis false
reclaim and compaction make no progress
order <=PAGE_ALLOC_COSTLY_ORDERThese conditions happen very often during suspend and resume, when
pm_restrict_gfp_mask()effectively converts allGFP_KERNELallocations into__GFP_WAIT.b>
Quoted 9 lines
The oom killer is not run because
gfp_mask&__GFP_FSis false, butshould_alloc_retrywill always return true when order is less thanPAGE_ALLOC_COSTLY_ORDER.Fix
__alloc_pages_slowpathto skip retrying when oom killer is not allowed by the GFP flags, the same way it would skip if the oom killer was allowed but disabled.Signed-off-by Colin Cross <[email protected]>Hi Colin,
Your patch functionally seems fine. I see the problem and we certainly do not want to have the OOM killer firing during suspend. I would prefer that the IO devices would not be suspended until reclaim was completed but I imagine that would be a lot harder.
Quoted 9 lines
Quoted 4 lines
That said, it will be difficult to remember why checking
__GFP_NOFAILin this case is necessary and someone might "optimitise" it away later. It would be preferable if it was self-documenting. Maybe something like this? (This is totally untested)This issue is not limited to suspend, any
GFP_NOIOallocation could end up in the same loop. Suspend is the most likely case, because it effectively converts allGFP_KERNELallocations intoGFP_NOIO.Quoted 13 lines
I see what you mean with
GFP_NOIObut there is an important difference betweenGFP_NOIOand suspend. AGFP_NOIOlow-order allocation currently implies__GFP_NOFAILas commented on inshould_alloc_retry(). If no progress is made, we callwait_iff_congested()and sleep for a bit. As the system is running, kswapd and other process activity will proceed and eventually reclaim enough pages for theGFP_NOIOallocation to succeed. In a running system,GFP_NOIOcan stall for a period of time but your patch will cause the allocation to fail. While I expect callers return ENOMEM or handle the situation properly with a wait-and-retry loop, there will be operations that fail that used to succeed. This is why I'd prefer it was a suspend-specific fix unless we know there is a case where a machine livelocks due to aGFP_NOIOallocation looping forever and even then I'd wonder why kswapd was not helping.
Quoted 2 lines
OK, I see the change in behavior you are trying to avoid. With your patch
GFP_NOIOallocations can still fail during suspend, is that OK?
What is the alternative? We are not making forward progress. This might mean that the suspend operation fails but I'm not seeing a better alternative.
Quoted 4 lines
I'm also worried about
GFP_NOIOallocations looping forever when swap is not enabled, but I've never seen it happen, and it would probably recover eventually when another tried tried aGFP_KERNELallocation and oom killed something.
Or when dirty pages backed by the filesystem are cleaned and reclaimed.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 17 lines · Pekka Enberg
Hi Mel,
Quoted 5 lines · Mel Gorman
I see what you mean with
GFP_NOIObut there is an important difference betweenGFP_NOIOand suspend. AGFP_NOIOlow-order allocation currently implies__GFP_NOFAILas commented on inshould_alloc_retry(). If no progress is made, we callwait_iff_congested()and sleep for a bit. As the system is running, kswapd and other process activity will proceed and eventuallyQuoted 8 lines
reclaim enough pages for the
GFP_NOIOallocation to succeed. In a running system,GFP_NOIOcan stall for a period of time but your patch will cause the allocation to fail. While I expect callers return ENOMEM or handle the situation properly with a wait-and-retry loop, there will be operations that fail that used to succeed. This is why I'd prefer it was a suspend-specific fix unless we know there is a case where a machine livelocks due to aGFP_NOIOallocation looping forever and even then I'd wonder why kswapd was not helping.
Quoted 2 lines
I'm not that happy about your patch because it's going to the direction where the page allocator is special-casing for suspension.
Suspend really is a special case. While I'd prefer to avoid special casing it like this, I prefer it a *lot* more than failing GFP_NOIO allocations that used to succeed.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 30 lines · Colin Cross
Quoted 19 lines · David Rientjes
Quoted 10 lines · Colin Cross
Quoted 4 lines
gfp_allowed_maskis initialized toGFP_BOOT_MASKto start so that__GFP_FSis never allowed before the slab allocator is completely initialized, so you've now implicitly made all early boot allocations to be__GFP_NORETRYeven though they may not pass it.Only before interrupts are enabled, and then isn't it vulnerable to the same livelock? Interrupts are off, single cpu, kswapd can't run. If an allocation ever failed, which seems unlikely, why would retrying help?
If you want to claim
gfp_allowed_maskas a pm-only entity, then I see no problem with this approach. However, ifgfp_allowed_maskwould be allowed to temporarily change after init for another purpose then it would make sense to retry because another allocation with__GFP_FSon another cpu or kswapd could start making progress could allow for future memory freeing.Quoted 4 lines
The suggestion to add a hook directly into a pm-interface was so that we could isolate it only to suspend and, to me, is the most maintainable solution.
pm_restrict_gfp_maskseems to claimgfp_allowed_maskas owned by pm at runtime:
"gfp_allowed_maskalso should only be modified withpm_mutexheld, unless the suspend/hibernate code is guaranteed not to run in parallel with that modification"
Quoted 8 lines
I think we've wrapped around to Mel's original patch, which adds a
pm_suspending()helper that is implemented next topm_restrict_gfp_mask. His patch puts the check inside !did_some_progress instead ofshould_alloc_retry, which I prefer as it at least keeps trying until reclaim isn't working. Pekka was trying to avoid adding pm-specific checks into the allocator, which is why I stuck to the symptom (__GFP_FSis clear) rather than the cause (PM).
Right now, I'm still no seeing a problem with the pm_suspending() check as it's made for a corner-case situation in a very slow path that is self-documenting. This thread has died somewhat and there is still no fix merged. Is someone cooking up a patch they would prefer as an alternative? If not, I'm going to resubmit the fix based on pm_suspending.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>