Skip to contentSkip to conversation

memcg: enable memcg oom-kill for __GFP_NOFAIL

PATCH Applied Shakeel Butt 4 participants 4 messages Feb 23, 2021 – Feb 25, 2021

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

PATCH 1/1 memcg: enable memcg oom-kill for __GFP_NOFAIL

In the era of async memcg oom-killer, the commit a0d8b00a3381 ("mm:
memcg: do not declare OOM from __GFP_NOFAIL allocations") added the code to skip memcg oom-killer for __GFP_NOFAIL allocations. The reason was that the __GFP_NOFAIL callers will not enter aync oom synchronization path and will keep the task marked as in memcg oom. At that time the tasks marked in memcg oom can bypass the memcg limits and the oom synchronization would have happened later in the later userspace triggered page fault. Thus letting the task marked as under memcg oom bypass the memcg limit for arbitrary time.

With the synchronous memcg oom-killer (commit 29ef680ae7c21 ("memcg,
oom: move out_of_memory back to the charge path")) and not letting the task marked under memcg oom to bypass the memcg limits (commit 1f14c1ac19aa4 ("mm: memcg: do not allow task about to OOM kill to bypass the limit")), we can again allow __GFP_NOFAIL allocations to trigger memcg oom-kill. This will make memcg oom behavior closer to page allocator oom behavior.

---
 mm/memcontrol.c | 3 ---
 1 file changed, 3 deletions(-)
mm/memcontrol.c +0 -3
index 2db2aeac8a9e..dcb5665aeb69 100644
@@ -2797,9 +2797,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
 	if (gfp_mask & __GFP_RETRY_MAYFAIL)
 		goto nomem;
 
-	if (gfp_mask & __GFP_NOFAIL)
-		goto force;
-
 	if (fatal_signal_pending(current))
 		goto force;
 
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Shakeel Butt

In the era of async memcg oom-killer, the commit a0d8b00a3381 ("mm:
memcg: do not declare OOM from __GFP_NOFAIL allocations") added the code to skip memcg oom-killer for __GFP_NOFAIL allocations. The reason was that the __GFP_NOFAIL callers will not enter aync oom synchronization path and will keep the task marked as in memcg oom. At that time the tasks marked in memcg oom can bypass the memcg limits and the oom synchronization would have happened later in the later userspace triggered page fault. Thus letting the task marked as under memcg oom bypass the memcg limit for arbitrary time.

Quoted 7 lines

With the synchronous memcg oom-killer (commit 29ef680ae7c21 ("memcg,
oom: move out_of_memory back to the charge path")) and not letting the task marked under memcg oom to bypass the memcg limits (commit 1f14c1ac19aa4 ("mm: memcg: do not allow task about to OOM kill to bypass the limit")), we can again allow __GFP_NOFAIL allocations to trigger memcg oom-kill. This will make memcg oom behavior closer to page allocator oom behavior.

The patch is correct, I just do follow why 1f14c1ac19aa4 is really relevant here. There nomem label wouldn't make any difference for __GFP_NOFAIL requests. The code has has changed quite a lot since then.

Quoted 1 line

This is a clear overlook when I moved the oom handling back to the charge path. Thanks for the fixup.

Quoted 20 lines
---
 mm/memcontrol.c | 3 ---
 1 file changed, 3 deletions(-)
mm/memcontrol.c +0 -3
index 2db2aeac8a9e..dcb5665aeb69 100644
@@ -2797,9 +2797,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
 	if (gfp_mask & __GFP_RETRY_MAYFAIL)
 		goto nomem;
 
-	if (gfp_mask & __GFP_NOFAIL)
-		goto force;
-
 	if (fatal_signal_pending(current))
 		goto force;
 
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
Signature · 2 lines
Michal Hocko
SUSE Labs
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Shakeel Butt
Quoted 18 lines · Shakeel Butt

In the era of async memcg oom-killer, the commit a0d8b00a3381 ("mm:
memcg: do not declare OOM from __GFP_NOFAIL allocations") added the code to skip memcg oom-killer for __GFP_NOFAIL allocations. The reason was that the __GFP_NOFAIL callers will not enter aync oom synchronization path and will keep the task marked as in memcg oom. At that time the tasks marked in memcg oom can bypass the memcg limits and the oom synchronization would have happened later in the later userspace triggered page fault. Thus letting the task marked as under memcg oom bypass the memcg limit for arbitrary time.

With the synchronous memcg oom-killer (commit 29ef680ae7c21 ("memcg,
oom: move out_of_memory back to the charge path")) and not letting the task marked under memcg oom to bypass the memcg limits (commit 1f14c1ac19aa4 ("mm: memcg: do not allow task about to OOM kill to bypass the limit")), we can again allow __GFP_NOFAIL allocations to trigger memcg oom-kill. This will make memcg oom behavior closer to page allocator oom behavior.

Quoted 1 line
Acked-by on v1 1/1
#3 lore raw
In reply to Shakeel Butt
Quoted 18 lines · Shakeel Butt

In the era of async memcg oom-killer, the commit a0d8b00a3381 ("mm:
memcg: do not declare OOM from __GFP_NOFAIL allocations") added the code to skip memcg oom-killer for __GFP_NOFAIL allocations. The reason was that the __GFP_NOFAIL callers will not enter aync oom synchronization path and will keep the task marked as in memcg oom. At that time the tasks marked in memcg oom can bypass the memcg limits and the oom synchronization would have happened later in the later userspace triggered page fault. Thus letting the task marked as under memcg oom bypass the memcg limit for arbitrary time.

With the synchronous memcg oom-killer (commit 29ef680ae7c21 ("memcg,
oom: move out_of_memory back to the charge path")) and not letting the task marked under memcg oom to bypass the memcg limits (commit 1f14c1ac19aa4 ("mm: memcg: do not allow task about to OOM kill to bypass the limit")), we can again allow __GFP_NOFAIL allocations to trigger memcg oom-kill. This will make memcg oom behavior closer to page allocator oom behavior.

Quoted 1 line