Skip to contentSkip to conversation

GFP_NOFAIL cleanups

PATCH NAK Michal Hocko 3 participants 18 messages Dec 1, 2016 – Dec 14, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover GFP_NOFAIL cleanups

Hi,
I have posted this as an RFC previously [1] as there was no fundamental disagreement I would like to ask for inclusion.

Tetsuo has noticed [2] that recent changes have changed GFP_NOFAIL semantic for costly order requests. I believe that the primary reason why this happened is that our GFP_NOFAIL checks are too scattered and it is really easy to forget about adding one. That's why I am proposing patch 1 which consolidates all the nofail handling at a single place. This should help to make this code better maintainable.

Patch 2 on top is a further attempt to make GFP_NOFAIL semantic less surprising. As things stand currently GFP_NOFAIL overrides the oom killer prevention code which is both subtle and not really needed. The patch 2 has more details about issues this might cause.

I would consider both patches more a cleanup than anything else. Any feedback is highly appreciated.

[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/1479387004-5998-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/2 mm: consolidate GFP_NOFAIL checks in the allocator slowpath

From: Michal Hocko <[email protected]>

Tetsuo Handa has pointed out that 0a0337e0d1d1 ("mm, oom: rework oom detection") has subtly changed semantic for costly high order requests with __GFP_NOFAIL and withtout __GFP_REPEAT and those can fail right now. My code inspection didn't reveal any such users in the tree but it is true that this might lead to unexpected allocation failures and subsequent OOPs.

__alloc_pages_slowpath wrt. GFP_NOFAIL is hard to follow currently. There are few special cases but we are lacking a catch all place to be sure we will not miss any case where the non failing allocation might fail. This patch reorganizes the code a bit and puts all those special cases under nopage label which is the generic go-to-fail path. Non failing allocations are retried or those that cannot retry like non-sleeping allocation go to the failure point directly. This should make the code flow much easier to follow and make it less error prone for future changes.

While we are there we have to move the stall check up to catch potentially looping non-failing allocations.

---
 mm/page_alloc.c | 68 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 27 deletions(-)
mm/page_alloc.c +41 -27
index 0fbfead6aa7d..76c0b6bb0baf 100644
@@ -3627,32 +3627,23 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 		goto got_pg;
 
 	/* Caller is not willing to reclaim, we can't balance anything */
-	if (!can_direct_reclaim) {
-		/*
-		 * All existing users of the __GFP_NOFAIL are blockable, so warn
-		 * of any new users that actually allow this type of allocation
-		 * to fail.
-		 */
-		WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL);
+	if (!can_direct_reclaim)
 		goto nopage;
+
+	/* Make sure we know about allocations which stall for too long */
+	if (time_after(jiffies, alloc_start + stall_timeout)) {
+		warn_alloc(gfp_mask,
+			"page alloction stalls for %ums, order:%u",
+			jiffies_to_msecs(jiffies-alloc_start), order);
+		stall_timeout += 10 * HZ;
 	}
 
 	/* Avoid recursion of direct reclaim */
-	if (current->flags & PF_MEMALLOC) {
-		/*
-		 * __GFP_NOFAIL request from this context is rather bizarre
-		 * because we cannot reclaim anything and only can loop waiting
-		 * for somebody to do a work for us.
-		 */
-		if (WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) {
-			cond_resched();
-			goto retry;
-		}
+	if (current->flags & PF_MEMALLOC)
 		goto nopage;
-	}
 
 	/* Avoid allocations with no watermarks from looping endlessly */
-	if (test_thread_flag(TIF_MEMDIE) && !(gfp_mask & __GFP_NOFAIL))
+	if (test_thread_flag(TIF_MEMDIE))
 		goto nopage;
 
 
@@ -3679,14 +3670,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_REPEAT))
 		goto nopage;
 
-	/* Make sure we know about allocations which stall for too long */
-	if (time_after(jiffies, alloc_start + stall_timeout)) {
-		warn_alloc(gfp_mask,
-			"page alloction stalls for %ums, order:%u",
-			jiffies_to_msecs(jiffies-alloc_start), order);
-		stall_timeout += 10 * HZ;
-	}
-
 	if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
 				 did_some_progress > 0, &no_progress_loops))
 		goto retry;
@@ -3715,6 +3698,37 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	}
 
 nopage:
+	/*
+	 * Make sure that __GFP_NOFAIL request doesn't leak out and make sure
+	 * we always retry
+	 */
+	if (gfp_mask & __GFP_NOFAIL) {
+		/*
+		 * All existing users of the __GFP_NOFAIL are blockable, so warn
+		 * of any new users that actually require GFP_NOWAIT
+		 */
+		if (WARN_ON_ONCE(!can_direct_reclaim))
+			goto fail;
+
+		/*
+		 * PF_MEMALLOC request from this context is rather bizarre
+		 * because we cannot reclaim anything and only can loop waiting
+		 * for somebody to do a work for us
+		 */
+		WARN_ON_ONCE(current->flags & PF_MEMALLOC);
+
+		/*
+		 * non failing costly orders are a hard requirement which we
+		 * are not prepared for much so let's warn about these users
+		 * so that we can identify them and convert them to something
+		 * else.
+		 */
+		WARN_ON_ONCE(order > PAGE_ALLOC_COSTLY_ORDER);
+
+		cond_resched();
+		goto retry;
+	}
+fail:
 	warn_alloc(gfp_mask,
 			"page allocation failure: order:%u", order);
 got_pg:
Signature · 7 lines
2.10.2

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH 2/2 mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Michal Hocko

From: Michal Hocko <[email protected]>

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

This patch simply removes the __GFP_NOFAIL special case in order to have a more clear semantic without surprising side effects. Instead we do allow nofail requests to access memory reserves to move forward in both cases when the OOM killer is invoked and when it should be supressed. __alloc_pages_nowmark helper has been introduced for that purpose.

---
 mm/oom_kill.c   |  2 +-
 mm/page_alloc.c | 95 +++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 59 insertions(+), 38 deletions(-)
mm/oom_kill.c +1 -1
index ec9f11d4f094..12a6fce85f61 100644
@@ -1013,7 +1013,7 @@ bool out_of_memory(struct oom_control *oc)
 	 * make sure exclude 0 mask - all other users should have at least
 	 * ___GFP_DIRECT_RECLAIM to get here.
 	 */
-	if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_NOFAIL)))
+	if (oc->gfp_mask && !(oc->gfp_mask & __GFP_FS))
 		return true;
 
 	/*
mm/page_alloc.c +58 -37

117 lines not on this page · raw message

Signature · 7 lines
2.10.2

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 26 lines · Michal Hocko

From: Michal Hocko <[email protected]>

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

Quoted 7 lines

This patch simply removes the __GFP_NOFAIL special case in order to have a more clear semantic without surprising side effects. Instead we do allow nofail requests to access memory reserves to move forward in both cases when the OOM killer is invoked and when it should be supressed. __alloc_pages_nowmark helper has been introduced for that purpose.

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Michal Hocko
Quoted 11 lines · Michal Hocko

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

Quoted 12 lines

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

I disagree. I believe that panic caused by OOM killer is much much better than a locked up system. I hate to add new locations that can lockup inside page allocator. This is __GFP_NOFAIL and reclaim has failed. Administrator has to go in front of console and press SysRq-f until locked up situation gets resolved is silly.

If there is a nasty driver asking for order-9 page with __GFP_NOFAIL, fix that driver.

Quoted 8 lines

This patch simply removes the __GFP_NOFAIL special case in order to have a more clear semantic without surprising side effects. Instead we do allow nofail requests to access memory reserves to move forward in both cases when the OOM killer is invoked and when it should be supressed. __alloc_pages_nowmark helper has been introduced for that purpose.

#5 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 25 lines · Tetsuo Handa
Quoted 11 lines · Michal Hocko

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

Quoted 12 lines

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

Quoted 3 lines

I disagree. I believe that panic caused by OOM killer is much much better than a locked up system. I hate to add new locations that can lockup inside page allocator. This is __GFP_NOFAIL and reclaim has failed.

As a matter of fact any __GFP_NOFAIL can lockup inside the allocator. Full stop. There is no guaranteed way to make a forward progress with the current page allocator implementation.

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} (page = alloc_page(GFP_NOFS));
vs.
	page = alloc_page(GFP_NOFS | __GFP_NOFAIL);

the first one doesn't invoke OOM killer while the later does. This discrepancy just cannot make any sense... The same is true for

alloc_page(GFP_DMA) vs alloc_page(GFP_DMA|__GFP_NOFAIL)

Now we can discuss whether it is a _good_ idea to not invoke OOM killer for those exceptions but whatever we do __GFP_NOFAIL is not a way to give such a subtle side effect. Or do you disagree even with that?

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

On Mon 05-12-16 15:10:09, Michal Hocko wrote:
[...]

Quoted 9 lines

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} (page = alloc_page(GFP_NOFS));

This should have been while (!(page = alloc_page(GFP_NOFS))) of course...

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Michal Hocko
Quoted 26 lines · Michal Hocko
Quoted 25 lines · Tetsuo Handa
Quoted 23 lines · Michal Hocko

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

Quoted 5 lines
Quoted 3 lines

I disagree. I believe that panic caused by OOM killer is much much better than a locked up system. I hate to add new locations that can lockup inside page allocator. This is __GFP_NOFAIL and reclaim has failed.

As a matter of fact any __GFP_NOFAIL can lockup inside the allocator.

You are trying to increase possible locations of lockups by changing default behavior of __GFP_NOFAIL.

Quoted 2 lines

Full stop. There is no guaranteed way to make a forward progress with the current page allocator implementation.

Then, will you accept kmallocwd until page allocator implementation can provide a guaranteed way to make a forward progress?

Quoted 13 lines

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} while (!(page = alloc_page(GFP_NOFS)));
vs.
	page = alloc_page(GFP_NOFS | __GFP_NOFAIL);
Quoted 8 lines

the first one doesn't invoke OOM killer while the later does. This discrepancy just cannot make any sense... The same is true for

alloc_page(GFP_DMA) vs alloc_page(GFP_DMA|__GFP_NOFAIL)

Now we can discuss whether it is a _good_ idea to not invoke OOM killer for those exceptions but whatever we do __GFP_NOFAIL is not a way to give such a subtle side effect. Or do you disagree even with that?

"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath" silently changes __GFP_NOFAIL vs. __GFP_NORETRY priority.

Currently, __GFP_NORETRY is stronger than __GFP_NOFAIL; __GFP_NOFAIL allocation requests fail without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

With [PATCH 1/2], __GFP_NOFAIL becomes stronger than __GFP_NORETRY; __GFP_NOFAIL allocation requests will loop forever without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

Those callers which prefer lockup over panic can specify both __GFP_NORETRY and __GFP_NOFAIL. You are trying to change behavior of __GFP_NOFAIL without asking whether existing __GFP_NOFAIL users want to invoke the OOM killer.

And the story is not specific to existing __GFP_NOFAIL users; it applies to existing GFP_NOFS users as well.

Quoting from http://lkml.kernel.org/r/[email protected] :

Quoted 8 lines
Quoted 6 lines

Will you look at http://marc.info/?t=120716967100004&r=1&w=2 which lead to commit a02fe13297af26c1 ("selinux: prevent rentry into the FS") and commit 869ab5147e1eead8 ("SELinux: more GFP_NOFS fixups to prevent selinux from re-entering the fs code") ? My understanding is that mkdir() system call caused memory allocation for inode creation and that memory allocation caused memory reclaim which had to be !__GFP_FS.

I will have a look later, thanks for the points.

What is your answer to this problem? For those who prefer panic over lockup, please provide a mean to invoke the OOM killer (e.g. __GFP_WANT_OOM_KILLER).

If you provide __GFP_WANT_OOM_KILLER, you can change

-#define GFP_KERNEL      (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
+#define GFP_KERNEL      (__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_WANT_OOM_KILLER)

in gfp.h and add __GFP_WANT_OOM_KILLER to any existing __GFP_NOFAIL/GFP_NOFS users who prefer panic over lockup. Then, I think I'm fine with

- if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_NOFAIL)))
- return true;
+ if (oc->gfp_mask && !(oc->gfp_mask & __GFP_WANT_OOM_KILLER))
+ return false;

in out_of_memory().

As you know, quite few people are responding to discussions regarding almost OOM situation. Changing default behavior without asking existing users is annoying.

#8 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 16 lines · Tetsuo Handa
Quoted 16 lines

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} while (!(page = alloc_page(GFP_NOFS)));
vs.
	page = alloc_page(GFP_NOFS | __GFP_NOFAIL);

the first one doesn't invoke OOM killer while the later does. This discrepancy just cannot make any sense... The same is true for

Quoted 8 lines
Quoted 5 lines

alloc_page(GFP_DMA) vs alloc_page(GFP_DMA|__GFP_NOFAIL)

Now we can discuss whether it is a _good_ idea to not invoke OOM killer for those exceptions but whatever we do __GFP_NOFAIL is not a way to give such a subtle side effect. Or do you disagree even with that?

"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath" silently changes __GFP_NOFAIL vs. __GFP_NORETRY priority.

I guess that wasn't intended?

Quoted 7 lines

Currently, __GFP_NORETRY is stronger than __GFP_NOFAIL; __GFP_NOFAIL allocation requests fail without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

With [PATCH 1/2], __GFP_NOFAIL becomes stronger than __GFP_NORETRY; __GFP_NOFAIL allocation requests will loop forever without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

Does such combination of flag make sense? Should we warn about it, or even silently remove __GFP_NORETRY in such case?

Quoted 2 lines

Those callers which prefer lockup over panic can specify both __GFP_NORETRY and __GFP_NOFAIL.

What lockup exactly, if __GFP_NORETRY did lead to fail?

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Tetsuo Handa
Quoted 27 lines · Tetsuo Handa
Quoted 26 lines · Michal Hocko
Quoted 25 lines · Tetsuo Handa
Quoted 23 lines · Michal Hocko

__alloc_pages_may_oom makes sure to skip the OOM killer depending on the allocation request. This includes lowmem requests, costly high order requests and others. For a long time __GFP_NOFAIL acted as an override for all those rules. This is not documented and it can be quite surprising as well. E.g. GFP_NOFS requests are not invoking the OOM killer but GFP_NOFS|__GFP_NOFAIL does so if we try to convert some of the existing open coded loops around allocator to nofail request (and we have done that in the past) then such a change would have a non trivial side effect which is not obvious. Note that the primary motivation for skipping the OOM killer is to prevent from pre-mature invocation.

The exception has been added by 82553a937f12 ("oom: invoke oom killer for __GFP_NOFAIL"). The changelog points out that the oom killer has to be invoked otherwise the request would be looping for ever. But this argument is rather weak because the OOM killer doesn't really guarantee any forward progress for those exceptional cases - e.g. it will hardly help to form costly order - I believe we certainly do not want to kill all processes and eventually panic the system just because there is a nasty driver asking for order-9 page with GFP_NOFAIL not realizing all the consequences - it is much better this request would loop for ever than the massive system disruption, lowmem is also highly unlikely to be freed during OOM killer and GFP_NOFS request could trigger while there is still a lot of memory pinned by filesystems.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I disagree. I believe that panic caused by OOM killer is much much better than a locked up system. I hate to add new locations that can lockup inside page allocator. This is __GFP_NOFAIL and reclaim has failed.

As a matter of fact any __GFP_NOFAIL can lockup inside the allocator.

You are trying to increase possible locations of lockups by changing default behavior of __GFP_NOFAIL.

I disagree. I have tried to explain that it is much more important to have fewer silent side effects than optimize for the very worst case. I simply do not see __GFP_NOFAIL lockups so common to even care or tweak their semantic in a weird way. It seems you prefer to optimize for the absolute worst case and even for that case you cannot offer anything better than randomly OOM killing random processes until the system somehow resurrects or panics. I consider this a very bad design. So let's agree to disagree here.

Quoted 5 lines
Quoted 2 lines

Full stop. There is no guaranteed way to make a forward progress with the current page allocator implementation.

Then, will you accept kmallocwd until page allocator implementation can provide a guaranteed way to make a forward progress?

No, I find your kmallocwd too complex for the advantage it provides.

Quoted 21 lines
Quoted 12 lines

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} while (!(page = alloc_page(GFP_NOFS)));
vs.
	page = alloc_page(GFP_NOFS | __GFP_NOFAIL);
Quoted 8 lines

the first one doesn't invoke OOM killer while the later does. This discrepancy just cannot make any sense... The same is true for

alloc_page(GFP_DMA) vs alloc_page(GFP_DMA|__GFP_NOFAIL)

Now we can discuss whether it is a _good_ idea to not invoke OOM killer for those exceptions but whatever we do __GFP_NOFAIL is not a way to give such a subtle side effect. Or do you disagree even with that?

Quoted 6 lines

"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath" silently changes __GFP_NOFAIL vs. __GFP_NORETRY priority.

Currently, __GFP_NORETRY is stronger than __GFP_NOFAIL; __GFP_NOFAIL allocation requests fail without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

Sigh... __GFP_NORETRY | __GFP_NOFAIL _doesn't_ make _any_ sense what so ever.

Quoted 3 lines

With [PATCH 1/2], __GFP_NOFAIL becomes stronger than __GFP_NORETRY; __GFP_NOFAIL allocation requests will loop forever without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

So what? Strictly speaking __GFP_NOFAIL should be always stronger but I really fail to see why we should even consider __GFP_NORETRY in that context. I definitely do not want to complicate the page fault path for a nonsense combination of flags.

Quoted 2 lines

Those callers which prefer lockup over panic can specify both __GFP_NORETRY and __GFP_NOFAIL.

No! This combination just doesn't make any sense. The same way how __GFP_REPEAT | GFP_NOWAIT or __GFP_REPEAT | __GFP_NORETRY make no sense as well. Please use a common sense!

Quoted 3 lines

You are trying to change behavior of
__GFP_NOFAIL without asking whether existing __GFP_NOFAIL users want to invoke the OOM killer.

Invoking or not invoking the oom killer is the page allocator internal business. No code outside of the MM is to talk about those decisions. The fact that we provide a lightweight allocation mode which doesn't invoke the OOM killer is a mere implementation detail.

Quoted 11 lines

And the story is not specific to existing __GFP_NOFAIL users; it applies to existing GFP_NOFS users as well.

Quoting from http://lkml.kernel.org/r/[email protected] :

Quoted 7 lines
Quoted 6 lines

Will you look at http://marc.info/?t=120716967100004&r=1&w=2 which lead to commit a02fe13297af26c1 ("selinux: prevent rentry into the FS") and commit 869ab5147e1eead8 ("SELinux: more GFP_NOFS fixups to prevent selinux from re-entering the fs code") ? My understanding is that mkdir() system call caused memory allocation for inode creation and that memory allocation caused memory reclaim which had to be !__GFP_FS.

Quoted 4 lines
Quoted 1 line

I will have a look later, thanks for the points.

What is your answer to this problem? For those who prefer panic over lockup, please provide a mean to invoke the OOM killer (e.g. __GFP_WANT_OOM_KILLER).

Please stop shifting discussion off the scope of the discussed patch. This just distracts from the main point. I really think that at least patch 1 is a good clean up and the second one makes a lot of sense as well from the semantic point of view. Now you constantly push to the extreme with very strong statements without any actual data point. This is not really helpful!

If you believe that my argumentation is incorrect then you are free to nak the patch with your reasoning. But please stop this nit picking on nonsense combination of flags.

Thanks!

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Vlastimil Babka
Quoted 19 lines · Vlastimil Babka
Quoted 18 lines · Tetsuo Handa
Quoted 18 lines

So we are somewhere in the middle between pre-mature and pointless system disruption (GFP_NOFS with a lots of metadata or lowmem request) where the OOM killer even might not help and potential lockup which is inevitable with the current design. Dunno about you but I would rather go with the first option. To be honest I really fail to understand your line of argumentation. We have this

	do {
		cond_resched();
	} while (!(page = alloc_page(GFP_NOFS)));
vs.
	page = alloc_page(GFP_NOFS | __GFP_NOFAIL);

the first one doesn't invoke OOM killer while the later does. This discrepancy just cannot make any sense... The same is true for

alloc_page(GFP_DMA) vs alloc_page(GFP_DMA|__GFP_NOFAIL)

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Now we can discuss whether it is a _good_ idea to not invoke OOM killer for those exceptions but whatever we do __GFP_NOFAIL is not a way to give such a subtle side effect. Or do you disagree even with that?

"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath" silently changes __GFP_NOFAIL vs. __GFP_NORETRY priority.

I guess that wasn't intended?

I even didn't think about that possibility because it just doesn't make any sense.

Quoted 10 lines
Quoted 7 lines

Currently, __GFP_NORETRY is stronger than __GFP_NOFAIL; __GFP_NOFAIL allocation requests fail without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

With [PATCH 1/2], __GFP_NOFAIL becomes stronger than __GFP_NORETRY; __GFP_NOFAIL allocation requests will loop forever without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

Does such combination of flag make sense? Should we warn about it, or even silently remove __GFP_NORETRY in such case?

No this combination doesn't make any sense. I seriously doubt we should even care about it and simply following the stronger requirement makes more sense from a semantic point of view.

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Nacked-by NAK
#11 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Michal Hocko
Quoted 4 lines · Michal Hocko
Quoted 2 lines · Tetsuo Handa

You are trying to increase possible locations of lockups by changing default behavior of __GFP_NOFAIL.

Quoted 8 lines

I disagree. I have tried to explain that it is much more important to have fewer silent side effects than optimize for the very worst case. I simply do not see __GFP_NOFAIL lockups so common to even care or tweak their semantic in a weird way. It seems you prefer to optimize for the absolute worst case and even for that case you cannot offer anything better than randomly OOM killing random processes until the system somehow resurrects or panics. I consider this a very bad design. So let's agree to disagree here.

You think that invoking the OOM killer with __GFP_NOFAIL is worse than locking up with __GFP_NOFAIL. But I think that locking up with __GFP_NOFAIL is worse than invoking the OOM killer with __GFP_NOFAIL. If we could agree with calling __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given, we can avoid locking up while minimizing possibility of invoking the OOM killer...

I suggest "when you change something, ask users who are affected by your change" because patch 2 has values-based conflict.

Quoted 19 lines
Quoted 6 lines

"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath" silently changes __GFP_NOFAIL vs. __GFP_NORETRY priority.

Currently, __GFP_NORETRY is stronger than __GFP_NOFAIL; __GFP_NOFAIL allocation requests fail without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

Sigh... __GFP_NORETRY | __GFP_NOFAIL _doesn't_ make _any_ sense what so ever.

Quoted 3 lines

With [PATCH 1/2], __GFP_NOFAIL becomes stronger than __GFP_NORETRY; __GFP_NOFAIL allocation requests will loop forever without invoking the OOM killer when both __GFP_NORETRY and __GFP_NOFAIL are given.

So what? Strictly speaking __GFP_NOFAIL should be always stronger but I really fail to see why we should even consider __GFP_NORETRY in that context. I definitely do not want to complicate the page fault path for a nonsense combination of flags.

Quoted 6 lines
Quoted 2 lines

Those callers which prefer lockup over panic can specify both __GFP_NORETRY and __GFP_NOFAIL.

No! This combination just doesn't make any sense. The same way how __GFP_REPEAT | GFP_NOWAIT or __GFP_REPEAT | __GFP_NORETRY make no sense as well. Please use a common sense!

I wonder why I'm accused so much. I mentioned that patch 2 might be a garbage because patch 1 alone unexpectedly provided a mean to retry forever without invoking the OOM killer. You are not describing that fact in the description. You are not describing what combinations are valid and which flag is stronger requirement in gfp.h (e.g. __GFP_NOFAIL v.s. __GFP_NORETRY).

Quoted 4 lines

Invoking or not invoking the oom killer is the page allocator internal business. No code outside of the MM is to talk about those decisions. The fact that we provide a lightweight allocation mode which doesn't invoke the OOM killer is a mere implementation detail.

__GFP_NOFAIL allocation requests for e.g. fs writeback is considered as code inside the MM because they are operations for reclaiming memory. Such __GFP_NOFAIL allocation requests should be given a chance to choose which one (possibility of lockup by not invoking the OOM killer or possibility of panic by invoking the OOM killer) they prefer.

Therefore,

Quoted 3 lines

If you believe that my argumentation is incorrect then you are free to nak the patch with your reasoning. But please stop this nit picking on nonsense combination of flags.

on patch 2 unless "you explain these patches to __GFP_NOFAIL users and provide a mean to invoke the OOM killer if someone chose possibility of panic" or "you accept kmallocwd".

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Full stop. There is no guaranteed way to make a forward progress with the current page allocator implementation.

Then, will you accept kmallocwd until page allocator implementation can provide a guaranteed way to make a forward progress?

No, I find your kmallocwd too complex for the advantage it provides.

My kmallocwd provides us two advantages.

One is that, if the cause of lockup is not memory allocation request, kmallocwd gives us a proof that you are doing well. You seriously tend to ignore corner cases with your wish that the absolute worst case won't happen; that makes me seriously explorer corner cases as a secure coder for proactive protection; that irritates you further.
You say that I constantly push to the extreme with very strong statements without any actual data point, but I say that you constantly reject without any proof just because you have never heard. The reality is that we can hardly expect people to have knowledge/skills for reporting corner cases.

The other is that, synchronous mechanism (like warn_alloc()) is prone to corner cases. We won't be able to catch all corner cases before people are trapped by them. If the cause of lockup is memory allocation request, kmallocwd gives us a trigger to take actions. This keeps me away from exploring corner cases which you think unlikely happen. This helps you to choose whatever semantic/logic you prefer.

Since I'm not a __GFP_NOFAIL user, I don't care as long as lockups are detected and reported using a catch-all approach (i.e. asynchronous mechanism). Instead of cruelly rejecting kmallocwd with "too complex", will you explain why you feel complex (as a reply to kmallocwd thread)? I have my goal for written as such, but there would be room for reducing complexity if you explain details.

#12 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 14 lines · Tetsuo Handa
Quoted 4 lines · Michal Hocko
Quoted 2 lines · Tetsuo Handa

You are trying to increase possible locations of lockups by changing default behavior of __GFP_NOFAIL.

Quoted 8 lines

I disagree. I have tried to explain that it is much more important to have fewer silent side effects than optimize for the very worst case. I simply do not see __GFP_NOFAIL lockups so common to even care or tweak their semantic in a weird way. It seems you prefer to optimize for the absolute worst case and even for that case you cannot offer anything better than randomly OOM killing random processes until the system somehow resurrects or panics. I consider this a very bad design. So let's agree to disagree here.

Quoted 2 lines

You think that invoking the OOM killer with __GFP_NOFAIL is worse than locking up with __GFP_NOFAIL.

Yes and I have explained why.

Quoted 2 lines

But I think that locking up with __GFP_NOFAIL is worse than invoking the OOM killer with __GFP_NOFAIL.

Without any actual arguments based just on handwaving.

Quoted 4 lines

If we could agree
with calling __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given, we can avoid locking up while minimizing possibility of invoking the OOM killer...

I do not understand. We do __alloc_pages_nowmark even when oom is called for GFP_NOFAIL.

Quoted 3 lines

I suggest "when you change something, ask users who are affected by your change" because patch 2 has values-based conflict.

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

Those callers which prefer lockup over panic can specify both __GFP_NORETRY and __GFP_NOFAIL.

No! This combination just doesn't make any sense. The same way how __GFP_REPEAT | GFP_NOWAIT or __GFP_REPEAT | __GFP_NORETRY make no sense as well. Please use a common sense!

I wonder why I'm accused so much. I mentioned that patch 2 might be a garbage because patch 1 alone unexpectedly provided a mean to retry forever without invoking the OOM killer.

Which is the whole point of the patch and the changelog is vocal about that. Even explaining why it is desirable to not override decisions when the oom killer is not invoked. Please reread that and object if the argument is not correct.

Quoted 4 lines

You are not describing that fact in the
description. You are not describing what combinations are valid and which flag is stronger requirement in gfp.h (e.g. __GFP_NOFAIL v.s. __GFP_NORETRY).

Sigh... I really fail to see why I should describe an impossible gfp mask combination which is _not_ used in the kernel. Please stop this strawman, I am really tired of it.

Quoted 10 lines
Quoted 4 lines

Invoking or not invoking the oom killer is the page allocator internal business. No code outside of the MM is to talk about those decisions. The fact that we provide a lightweight allocation mode which doesn't invoke the OOM killer is a mere implementation detail.

__GFP_NOFAIL allocation requests for e.g. fs writeback is considered as code inside the MM because they are operations for reclaiming memory. Such __GFP_NOFAIL allocation requests should be given a chance to choose which one (possibility of lockup by not invoking the OOM killer or possibility of panic by invoking the OOM killer) they prefer.

Please be more specific. How and why they should choose that. Which allocation are we talking about and why do you believe that the current implementation with access to memory reserves is not sufficient.

Quoted 11 lines

Therefore,

Quoted 3 lines

If you believe that my argumentation is incorrect then you are free to nak the patch with your reasoning. But please stop this nit picking on nonsense combination of flags.

on patch 2 unless "you explain these patches to __GFP_NOFAIL users and provide a mean to invoke the OOM killer if someone chose possibility of panic"

I believe that the changelog contains my reasonining and so far I haven't heard any _argument_ from you why they are wrong. You just managed to nitpick on an impossible and pointless gfp_mask combination and some handwaving on possible lockups without any backing arguments. This is not something I would consider as a basis for a serious nack. So if you really hate this patch then do please start being reasonable and put some real arguments into your review without any off topics and/or strawman arguments without any relevance.

Quoted 1 line

or "you accept kmallocwd".

Are you serious? Are you really suggesting that your patch has to be accepted in order to have this one in?

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Nacked-by NAK
#13 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 8 lines · Michal Hocko
Quoted 4 lines · Tetsuo Handa

If we could agree
with calling __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given, we can avoid locking up while minimizing possibility of invoking the OOM killer...

I do not understand. We do __alloc_pages_nowmark even when oom is called for GFP_NOFAIL.

Where is that? I can find __alloc_pages_nowmark() after out_of_memory() if __GFP_NOFAIL is given, but I can't find __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given.

What I mean is below patch folded into
"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath".

mm/page_alloc.c +33 -14
@@ -3057,6 +3057,25 @@ void warn_alloc(gfp_t gfp_mask, const char *fmt, ...)
 }
 
 static inline struct page *
+__alloc_pages_nowmark(gfp_t gfp_mask, unsigned int order,
+                        const struct alloc_context *ac)
+{
+    struct page *page;
+
+    page = get_page_from_freelist(gfp_mask, order,
+            ALLOC_NO_WATERMARKS|ALLOC_CPUSET, ac);
+    /*
+     * fallback to ignore cpuset restriction if our nodes
+     * are depleted
+     */
+    if (!page)
+        page = get_page_from_freelist(gfp_mask, order,
+                ALLOC_NO_WATERMARKS, ac);
+
+    return page;
+}
+
+static inline struct page *
 __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
     const struct alloc_context *ac, unsigned long *did_some_progress)
 {
@@ -3118,21 +3137,8 @@ void warn_alloc(gfp_t gfp_mask, const char *fmt, ...)
             goto out;
     }
     /* Exhausted what can be done so it's blamo time */
-    if (out_of_memory(&oc) || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) {
+    if (out_of_memory(&oc))
         *did_some_progress = 1;
-
-        if (gfp_mask & __GFP_NOFAIL) {
-            page = get_page_from_freelist(gfp_mask, order,
-                    ALLOC_NO_WATERMARKS|ALLOC_CPUSET, ac);
-            /*
-             * fallback to ignore cpuset restriction if our nodes
-             * are depleted
-             */
-            if (!page)
-                page = get_page_from_freelist(gfp_mask, order,
-                    ALLOC_NO_WATERMARKS, ac);
-        }
-    }
 out:
     mutex_unlock(&oom_lock);
     return page;
@@ -3738,6 +3744,19 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
          */
         WARN_ON_ONCE(order > PAGE_ALLOC_COSTLY_ORDER);
 
+        /*
+         * Help non-failing allocations by giving them access to memory
+         * reserves
+         */
+        page = __alloc_pages_nowmark(gfp_mask, order, ac);
+        if (page)
+            goto got_pg;
+
+        /* Memory reserves did not help. Start killing things. */
+        page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress);
+        if (page)
+            goto got_pg;
+
         cond_resched();
         goto retry;
     }
Quoted 12 lines
Quoted 11 lines

Therefore,

Quoted 3 lines

If you believe that my argumentation is incorrect then you are free to nak the patch with your reasoning. But please stop this nit picking on nonsense combination of flags.

on patch 2 unless "you explain these patches to __GFP_NOFAIL users and provide a mean to invoke the OOM killer if someone chose possibility of panic"

Quoted 9 lines

I believe that the changelog contains my reasoning and so far I haven't heard any _argument_ from you why they are wrong. You just managed to nitpick on an impossible and pointless gfp_mask combination and some handwaving on possible lockups without any backing arguments. This is not something I would consider as a basis for a serious nack. So if you really hate this patch then do please start being reasonable and put some real arguments into your review without any off topics and/or strawman arguments without any relevance.

Are you aware that I'm not objecting to "change __GFP_NOFAIL not to invoke the OOM killer". What I'm objecting is that you are trying to change !__GFP_FS && !__GFP_NOFAIL allocation requests without offering transition plan like below.

mm/oom_kill.c +1 -1
@@ -1013,7 +1013,7 @@ bool out_of_memory(struct oom_control *oc)
      * make sure exclude 0 mask - all other users should have at least
      * ___GFP_DIRECT_RECLAIM to get here.
      */
-    if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_NOFAIL)))
+    if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_WANT_OOM_KILLER))
         return true;
 
     /*

If you do want to push

mm/oom_kill.c +1 -1
@@ -1013,7 +1013,7 @@ bool out_of_memory(struct oom_control *oc)
      * make sure exclude 0 mask - all other users should have at least
      * ___GFP_DIRECT_RECLAIM to get here.
      */
-    if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_NOFAIL)))
+    if (oc->gfp_mask && !(oc->gfp_mask & __GFP_FS))
         return true;
 
     /*

change, ask existing __GFP_NOFAIL users with explanations like below

I believe that __GFP_NOFAIL should not imply invocation of the OOM killer. Therefore, I want to change __GFP_NOFAIL not to invoke the OOM killer. But since currently the OOM killer is not invoked unless either __GFP_FS or __GFP_NOFAIL is specified, changing __GFP_NOFAIL not to invoke the OOM killer introduces e.g. GFP_NOFS | __GFP_NOFAIL users a risk of livelocking by not invoking the OOM killer. Although I can't prove that this change never causes livelock, I don't want to provide an alternative flag like __GFP_WANT_OOM_KILLER. Therefore, all existing __GFP_NOFAIL users must agree with accepting the risk introduced by this change.

and confirm that all existing __GFP_NOFAIL users are willing to accept the risk of livelocking by not invoking the OOM killer.

Unless you do this procedure, I continue:

Quoted 4 lines
Quoted 1 line

or "you accept kmallocwd".

Are you serious? Are you really suggesting that your patch has to be accepted in order to have this one in?

I'm surprised you think my kmallocwd as a choice for applying this patch, for I was assuming that you choose the procedure above which is super straightforward.

#14 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

Quoted 10 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
Quoted 4 lines · Tetsuo Handa

If we could agree
with calling __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given, we can avoid locking up while minimizing possibility of invoking the OOM killer...

I do not understand. We do __alloc_pages_nowmark even when oom is called for GFP_NOFAIL.

Quoted 7 lines

Where is that? I can find __alloc_pages_nowmark() after out_of_memory() if __GFP_NOFAIL is given, but I can't find __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given.

What I mean is below patch folded into
"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath".

Oops, I wrongly implemented "__alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given." case. Updated version is shown below.

mm/page_alloc.c +23 -14
@@ -3116,23 +3116,27 @@ void warn_alloc(gfp_t gfp_mask, const char *fmt, ...)
 		/* The OOM killer may not free memory on a specific node */
 		if (gfp_mask & __GFP_THISNODE)
 			goto out;
+	} else {
+		/*
+		 * Help non-failing allocations by giving them access to memory
+		 * reserves
+		 */
+		page = get_page_from_freelist(gfp_mask, order,
+					      ALLOC_NO_WATERMARKS|ALLOC_CPUSET, ac);
+		/*
+		 * fallback to ignore cpuset restriction if our nodes
+		 * are depleted
+		 */
+		if (!page)
+			page = get_page_from_freelist(gfp_mask, order,
+						      ALLOC_NO_WATERMARKS, ac);
+		if (page)
+			goto out;
 	}
+
 	/* Exhausted what can be done so it's blamo time */
-	if (out_of_memory(&oc) || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) {
+	if (out_of_memory(&oc))
 		*did_some_progress = 1;
-
-		if (gfp_mask & __GFP_NOFAIL) {
-			page = get_page_from_freelist(gfp_mask, order,
-					ALLOC_NO_WATERMARKS|ALLOC_CPUSET, ac);
-			/*
-			 * fallback to ignore cpuset restriction if our nodes
-			 * are depleted
-			 */
-			if (!page)
-				page = get_page_from_freelist(gfp_mask, order,
-					ALLOC_NO_WATERMARKS, ac);
-		}
-	}
 out:
 	mutex_unlock(&oom_lock);
 	return page;
@@ -3738,6 +3742,11 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 		 */
 		WARN_ON_ONCE(order > PAGE_ALLOC_COSTLY_ORDER);
 
+		/* Try memory reserves and then start killing things. */
+		page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress);
+		if (page)
+			goto got_pg;
+
 		cond_resched();
 		goto retry;
 	}

I'm calling __alloc_pages_may_oom() from nopage: because we reach without calling __alloc_pages_may_oom(), for PATCH 1/2 is not for stop enforcing the OOM killer for __GFP_NOFAIL.

#16 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Tetsuo Handa
Quoted 2 lines · Tetsuo Handa
Quoted 1 line · Michal Hocko

On Thu 08-12-16 21:53:44, Tetsuo Handa wrote:

[...]

Quoted 28 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

If you believe that my argumentation is incorrect then you are free to nak the patch with your reasoning. But please stop this nit picking on nonsense combination of flags.

on patch 2 unless "you explain these patches to __GFP_NOFAIL users and provide a mean to invoke the OOM killer if someone chose possibility of panic"

Quoted 9 lines

I believe that the changelog contains my reasoning and so far I haven't heard any _argument_ from you why they are wrong. You just managed to nitpick on an impossible and pointless gfp_mask combination and some handwaving on possible lockups without any backing arguments. This is not something I would consider as a basis for a serious nack. So if you really hate this patch then do please start being reasonable and put some real arguments into your review without any off topics and/or strawman arguments without any relevance.

Are you aware that I'm not objecting to "change __GFP_NOFAIL not to invoke the OOM killer". What I'm objecting is that you are trying to change !__GFP_FS && !__GFP_NOFAIL allocation requests without offering transition plan like below.

mm/oom_kill.c bool out_of_memory(struct oom_control *oc) · line 1017

Quoted 6 lines
mm/oom_kill.c +1 -1
@@ -1013,7 +1013,7 @@ bool out_of_memory(struct oom_control *oc)
      * make sure exclude 0 mask - all other users should have at least
      * ___GFP_DIRECT_RECLAIM to get here.
      */
-    if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_NOFAIL)))
+    if (oc->gfp_mask && !(oc->gfp_mask & (__GFP_FS|__GFP_WANT_OOM_KILLER))
         return true;

I have already asked that but let me ask again. _Who_ would use this flag and not risk the pre-mature OOM killer invocation?

[...]

Quoted 9 lines
mm/oom_kill.c +0 -0
  I believe that __GFP_NOFAIL should not imply invocation of the OOM killer.
  Therefore, I want to change __GFP_NOFAIL not to invoke the OOM killer.

But since currently the OOM killer is not invoked unless either __GFP_FS or __GFP_NOFAIL is specified, changing __GFP_NOFAIL not to invoke the OOM killer introduces e.g. GFP_NOFS | __GFP_NOFAIL users a risk of livelocking by not invoking the OOM killer. Although I can't prove that this change never causes livelock, I don't want to provide an alternative flag like __GFP_WANT_OOM_KILLER. Therefore, all existing __GFP_NOFAIL users must agree with accepting the risk introduced by this change.

I think you are seriously misled here. First of all, I have gone through GFP_NOFS | GFP_NOFAIL users and _none_ of them have added the nofail flag to enforce the OOM killer. Those users just want to express that an allocation failure is simply not acceptable. Most of them were simply conversions from the open-conded

	do { } while (! (page = page_alloc(GFP_NOFS));

loops. Which _does_ not invoke the OOM killer. And that is the most importatnt point here. Why the above open coded (and as you say lockup prone) loop is OK while GFP_NOFAIL varian should behave any differently?

Quoted 6 lines

and confirm that all existing __GFP_NOFAIL users are willing to accept the risk of livelocking by not invoking the OOM killer.

Unless you do this procedure, I continue:

I was hoping for some actual arguments but I am afraid this is circling in a loop. You are still handwaving with theoretical lockups without any actual proof they are real. While I am not saying the risk is not there I also say that there are other aspects to consider
- lockups will happen only if there are no other GFP_FS requests which trigger the OOM which is quite unlikely in most situations
- triggering oom for GFP_NOFS | GFP_NOFAIL has a non negligible risk of pre-mature OOM killer invocation for the same reason we do not trigger oom for GFP_NOFS. Even worse metadata heavy workloads are much harder to contain so this might be used as a DoS vector.
- one of the primary point of GFP_NOFAIL existence is to prevent from open coding endless loops in the code because the page allocator can handle most situations more gracefully (e.g. grant access to memory reserves). Having a completely different OOM killer behavior is both confusing and encourages abuse. If we have users who definitely need to control the OOM behavior then we should add a gfp flag for them. But this needs a strong use case and consider whether there are other options to go around that.

I can add the above to the changelog if you think this is helpful but I still maintain my position that your "this might cause lockups theoretically" is unfounded and not justified to block the patch. I will of course retract this patch if you can demonstrate the issue is real or that any of my argumentation in the changelog is not correct.

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Tetsuo Handa
Quoted 15 lines · Tetsuo Handa
Quoted 14 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
Quoted 4 lines · Tetsuo Handa

If we could agree
with calling __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given, we can avoid locking up while minimizing possibility of invoking the OOM killer...

I do not understand. We do __alloc_pages_nowmark even when oom is called for GFP_NOFAIL.

Where is that? I can find __alloc_pages_nowmark() after out_of_memory() if __GFP_NOFAIL is given, but I can't find __alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given.

Quoted 5 lines
Quoted 3 lines

What I mean is below patch folded into
"[PATCH 1/2] mm: consolidate GFP_NOFAIL checks in the allocator slowpath".

Oops, I wrongly implemented "__alloc_pages_nowmark() before out_of_memory() if __GFP_NOFAIL is given." case. Updated version is shown below.

If you want to introduce such a change then make sure to justify it properly in the changelog. I will not comment on this change here because I believe it is not directly needed for neither of the two patches.

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

Re: [PATCH 2/2] mm, oom: do not enfore OOM killer for __GFP_NOFAIL automatically

In reply to Michal Hocko
Quoted 1 line · Michal Hocko

On Sun 11-12-16 20:23:47, Tetsuo Handa wrote:

[...]

Quoted 49 lines
Quoted 9 lines

I believe that __GFP_NOFAIL should not imply invocation of the OOM killer. Therefore, I want to change __GFP_NOFAIL not to invoke the OOM killer. But since currently the OOM killer is not invoked unless either __GFP_FS or __GFP_NOFAIL is specified, changing __GFP_NOFAIL not to invoke the OOM killer introduces e.g. GFP_NOFS | __GFP_NOFAIL users a risk of livelocking by not invoking the OOM killer. Although I can't prove that this change never causes livelock, I don't want to provide an alternative flag like __GFP_WANT_OOM_KILLER. Therefore, all existing __GFP_NOFAIL users must agree with accepting the risk introduced by this change.

I think you are seriously misled here. First of all, I have gone through GFP_NOFS | GFP_NOFAIL users and _none_ of them have added the nofail flag to enforce the OOM killer. Those users just want to express that an allocation failure is simply not acceptable. Most of them were simply conversions from the open-conded

	do { } while (! (page = page_alloc(GFP_NOFS));

loops. Which _does_ not invoke the OOM killer. And that is the most importatnt point here. Why the above open coded (and as you say lockup prone) loop is OK while GFP_NOFAIL varian should behave any differently?

Quoted 6 lines

and confirm that all existing __GFP_NOFAIL users are willing to accept the risk of livelocking by not invoking the OOM killer.

Unless you do this procedure, I continue:

I was hoping for some actual arguments but I am afraid this is circling in a loop. You are still handwaving with theoretical lockups without any actual proof they are real. While I am not saying the risk is not there I also say that there are other aspects to consider
- lockups will happen only if there are no other GFP_FS requests which trigger the OOM which is quite unlikely in most situations
- triggering oom for GFP_NOFS | GFP_NOFAIL has a non negligible risk of pre-mature OOM killer invocation for the same reason we do not trigger oom for GFP_NOFS. Even worse metadata heavy workloads are much harder to contain so this might be used as a DoS vector.
- one of the primary point of GFP_NOFAIL existence is to prevent from open coding endless loops in the code because the page allocator can handle most situations more gracefully (e.g. grant access to memory reserves). Having a completely different OOM killer behavior is both confusing and encourages abuse. If we have users who definitely need to control the OOM behavior then we should add a gfp flag for them. But this needs a strong use case and consider whether there are other options to go around that.

Quoted 5 lines

I can add the above to the changelog if you think this is helpful but I still maintain my position that your "this might cause lockups theoretically" is unfounded and not justified to block the patch. I will of course retract this patch if you can demonstrate the issue is real or that any of my argumentation in the changelog is not correct.

I was thinking about this some more and realized that there is a different risk which this patch would introduce and have to be considered. Heavy GFP_NOFS | __GFP_NOFAIL users might actually deplete memory reserves. This was less of a problem with the current code because we invoke the oom killer and so at least _some_ memory might be freed. I will think about it some more but I guess I will just allow a partial access in the no-oom case. I will post the patch 1 in the meantime because I believe this is a reasonable cleanup.

Signature · 8 lines
Michal Hocko
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>