pids.current with invalid value for hours [5.0.0 rc3 git]
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20190117122535.njcbqhlmzozdkncw@mikami
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 26 lines · Arkadiusz Miśkiewicz
Quoted 25 lines · Arkadiusz Miśkiewicz
Quoted 5 lines · Aleksa Sarai
Quoted 4 lines · Arkadiusz Miśkiewicz
Using kernel 4.19.13.
For one cgroup I noticed weird behaviour:
Quoted 9 lines
Quoted 4 lines
# cat pids.current 60 # cat cgroup.procs #Are there any zombies in the cgroup? pids.current is linked up directly to
__put_task_struct(so exit(2) won't decrease it, only thetask_structactually being freed will decrease it).There are no zombie processes.
In mean time the problem shows on multiple servers and so far saw it only in cgroups that were OOMed.
What has changed on these servers (yesterday) is turning on memory.oom.group=1 for all cgroups and changing memory.high from 1G to "max" (leaving memory.max=2G limit only).
Quoted 8 lines
Quoted 2 lines
Previously there was no such problem.
I'm attaching reproducer. This time tried on different distribution kernel (arch linux).
After 60s pids.current still shows 37 processes even if there are no processes running (according to ps aux).
The same test on 5.0.0-rc3-00104-gc04e2a780caf and it's easy to reproduce bug. No processes in cgroup but pids.current reports 91.
memory.oom.group=0 - everything works fine, pids are counted properly memory.oom.group=1 - bug becomes visible
[root@xps test]# python3 cg.py
Created cgroup: /sys/fs/cgroup/test_5277
Start: pids.current: 0
Start: cgroup.procs:
0: pids.current: 103
0: cgroup.procs:
1: pids.current: 91
1: cgroup.procs:
2: pids.current: 91
2: cgroup.procs:
3: pids.current: 91
3: cgroup.procs:
4: pids.current: 91
4: cgroup.procs:
5: pids.current: 91
5: cgroup.procs:
6: pids.current: 91
6: cgroup.procs:
7: pids.current: 91
7: cgroup.procs:
8: pids.current: 91
8: cgroup.procs:
9: pids.current: 91
9: cgroup.procs:
10: pids.current: 91
10: cgroup.procs:
11: pids.current: 91
11: cgroup.procs:
[root@xps test]# uname -a
Linux xps 5.0.0-rc3-00104-gc04e2a780caf #288 SMP PREEMPT Thu Jan 24 19:00:32 CET 2019 x86_64 Intel(R)_Core(TM)_i9-8950HK_CPU_@_2.90GHz PLD Linux
cc relevant people
script is here: https://www.spinics.net/lists/cgroups/msg21330.html
Quoted 33 lines
[root@warm ~]# uname -a
Linux warm 4.20.3-arch1-1-ARCH #1 SMP PREEMPT Wed Jan 16 22:38:58 UTC 2019x86_64GNU/Linux
[root@warm ~]# python3cg.py
Created cgroup:/sys/fs/cgroup/test_26207
Start: pids.current: 0
Start: cgroup.procs:
0: pids.current: 62
0: cgroup.procs:
1: pids.current: 37
1: cgroup.procs:
2: pids.current: 37
2: cgroup.procs:
3: pids.current: 37
3: cgroup.procs:
4: pids.current: 37
4: cgroup.procs:
5: pids.current: 37
5: cgroup.procs:
6: pids.current: 37
6: cgroup.procs:
7: pids.current: 37
7: cgroup.procs:
8: pids.current: 37
8: cgroup.procs:
9: pids.current: 37
9: cgroup.procs:
10: pids.current: 37
10: cgroup.procs:
11: pids.current: 37
11: cgroup.procs:
Signature · 1 line
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )
Tejun Heo
maintainerQuoted 33 lines · Arkadiusz Miśkiewicz
Quoted 32 lines · Arkadiusz Miśkiewicz
Quoted 18 lines · Arkadiusz Miśkiewicz
Quoted 5 lines · Aleksa Sarai
Quoted 4 lines · Arkadiusz Miśkiewicz
Using kernel 4.19.13.
For one cgroup I noticed weird behaviour:
Quoted 9 lines
Quoted 4 lines
# cat pids.current 60 # cat cgroup.procs #Are there any zombies in the cgroup? pids.current is linked up directly to
__put_task_struct(so exit(2) won't decrease it, only thetask_structactually being freed will decrease it).There are no zombie processes.
Quoted 9 lines
In mean time the problem shows on multiple servers and so far saw it only in cgroups that were OOMed.
What has changed on these servers (yesterday) is turning on memory.oom.group=1 for all cgroups and changing memory.high from 1G to "max" (leaving memory.max=2G limit only).
Previously there was no such problem.
I'm attaching reproducer. This time tried on different distribution kernel (arch linux).
Quoted 6 lines
Quoted 2 lines
After 60s pids.current still shows 37 processes even if there are no processes running (according to ps aux).
The same test on 5.0.0-rc3-00104-gc04e2a780caf and it's easy to reproduce bug. No processes in cgroup but pids.current reports 91.
Can you please see whether the problem can be reproduced on the current linux-next?
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
Thanks.
Signature · 1 line
tejun
Quoted 38 lines · Tejun Heo
Quoted 37 lines · Arkadiusz Miśkiewicz
Quoted 34 lines · Arkadiusz Miśkiewicz
Quoted 18 lines · Arkadiusz Miśkiewicz
Quoted 5 lines · Aleksa Sarai
Quoted 4 lines · Arkadiusz Miśkiewicz
Using kernel 4.19.13.
For one cgroup I noticed weird behaviour:
Quoted 9 lines
Quoted 4 lines
# cat pids.current 60 # cat cgroup.procs #Are there any zombies in the cgroup? pids.current is linked up directly to
__put_task_struct(so exit(2) won't decrease it, only thetask_structactually being freed will decrease it).There are no zombie processes.
Quoted 9 lines
In mean time the problem shows on multiple servers and so far saw it only in cgroups that were OOMed.
What has changed on these servers (yesterday) is turning on memory.oom.group=1 for all cgroups and changing memory.high from 1G to "max" (leaving memory.max=2G limit only).
Previously there was no such problem.
I'm attaching reproducer. This time tried on different distribution kernel (arch linux).
After 60s pids.current still shows 37 processes even if there are no processes running (according to ps aux).
Quoted 7 lines
Quoted 2 lines
The same test on 5.0.0-rc3-00104-gc04e2a780caf and it's easy to reproduce bug. No processes in cgroup but pids.current reports 91.
Can you please see whether the problem can be reproduced on the current linux-next?
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
I can reproduce on next (5.0.0-rc3-next-20190125), too:
[root@xps test]# python3 cg.py
Created cgroup: /sys/fs/cgroup/test_2501
Start: pids.current: 0
Start: cgroup.procs:
0: pids.current: 65
0: cgroup.procs:
1: pids.current: 44
1: cgroup.procs:
2: pids.current: 44
2: cgroup.procs:
3: pids.current: 44
3: cgroup.procs:
4: pids.current: 44
4: cgroup.procs:
5: pids.current: 44
5: cgroup.procs:
6: pids.current: 44
6: cgroup.procs:
7: pids.current: 44
7: cgroup.procs:
8: pids.current: 44
8: cgroup.procs:
9: pids.current: 44
9: cgroup.procs:
10: pids.current: 44
10: cgroup.procs:
11: pids.current: 44
11: cgroup.procs:
[root@xps test]# uname -a
Linux xps 5.0.0-rc3-next-20190125 #2 SMP PREEMPT Fri Jan 25 19:11:40 CET 2019 x86_64 Intel(R)_Core(TM)_i9-8950HK_CPU_@_2.90GHz PLD Linux [root@xps test]# mount |grep cgroup2
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime)
I'm booting kernel with cgroup_no_v1=all
Signature · 1 line
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )
Tetsuo Handa
Acked-by Michal HockoQuoted 7 lines · Arkadiusz MiÅ›kiewicz
Quoted 4 lines
Can you please see whether the problem can be reproduced on the current linux-next?
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gitI can reproduce on next (5.0.0-rc3-next-20190125), too:
Please try this patch.
Subject: [PATCH v2] memcg: killed threads should not invoke memcg OOM killer
From: Tetsuo Handa <[email protected]>
To: Andrew Morton <[email protected]>,
Johannes Weiner <[email protected]>, David Rientjes <[email protected]>
Cc: Michal Hocko <[email protected]>, [email protected],
Kirill Tkhai <[email protected]>,
Linus Torvalds <[email protected]>
Message-ID: <[email protected]>
Date: Tue, 15 Jan 2019 19:17:27 +0900
If $N > $M, a single process with $N threads in a memcg group can easily kill all $M processes in that memcg group, for mem_cgroup_out_of_memory() does not check if current thread needs to invoke the memcg OOM killer.
T1@P1 |T2...$N@P1|P2...$M |OOM reaper
----------+----------+----------+----------
# all sleeping
try_charge()
mem_cgroup_out_of_memory()
mutex_lock(oom_lock)
try_charge()
mem_cgroup_out_of_memory()
mutex_lock(oom_lock)
out_of_memory()
select_bad_process()
oom_kill_process(P1)
wake_oom_reaper()
oom_reap_task() # ignores P1
mutex_unlock(oom_lock)
out_of_memory()
select_bad_process(P2...$M)
# all killed by T2...$N@P1
wake_oom_reaper()
oom_reap_task() # ignores P2...$M
mutex_unlock(oom_lock)We don't need to invoke the memcg OOM killer if current thread was killed when waiting for oom_lock, for mem_cgroup_oom_synchronize(true) can count on try_charge() when mem_cgroup_oom_synchronize(true) can not make forward progress because try_charge() allows already killed/exiting threads to make forward progress, and memory_max_write() can bail out upon signals.
At first Michal thought that fatal signal check is racy compared to tsk_is_oom_victim() check. But an experiment showed that trying to call mark_oom_victim() on all killed thread groups is more racy than fatal signal check due to task_will_free_mem(current) path in out_of_memory().
Therefore, this patch changes mem_cgroup_out_of_memory() to bail out upon should_force_charge() == T rather than upon fatal_signal_pending() == T, for should_force_charge() == T && signal_pending(current) == F at memory_max_write() can't happen because current thread won't call memory_max_write() after getting PF_EXITING.
--- mm/memcontrol.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
mm/memcontrol.c +14 -5
@@ -248,6 +248,12 @@ enum res_type { iter !=NULL ; \ iter = mem_cgroup_iter(NULL, iter, NULL)) +static inline bool should_force_charge (void ) +{ +return tsk_is_oom_victim (current) ||fatal_signal_pending (current) || + (current->flags &PF_EXITING ); +} +/* Some nice accessors for the vmpressure. */ struct vmpressure *memcg_to_vmpressure (struct mem_cgroup *memcg) {
@@ -1389,8 +1395,13 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, };bool ret; -mutex_lock (&oom_lock); - ret =out_of_memory (&oc); +if (mutex_lock_killable (&oom_lock)) +return true; +/* +* A few threads which were not waiting at mutex_lock_killable() can +* fail to bail out. Therefore, check again after holding oom_lock. +*/ + ret =should_force_charge () ||out_of_memory (&oc);mutex_unlock (&oom_lock);return ret; }
@@ -2209,9 +2220,7 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,* bypass the last charges so that they can exit quickly and * free their memory. */ -if (unlikely (tsk_is_oom_victim (current) || -fatal_signal_pending (current) || - current->flags &PF_EXITING )) +if (unlikely (should_force_charge ())) goto force;/*
Signature · 1 line
1.8.3.1
Quoted 10 lines · Tetsuo Handa
Quoted 7 lines · Arkadiusz Miśkiewicz
Quoted 4 lines
Can you please see whether the problem can be reproduced on the current linux-next?
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gitI can reproduce on next (5.0.0-rc3-next-20190125), too:
Please try this patch.
Doesn't help:
[root@xps test]# python3 cg.py
Created cgroup: /sys/fs/cgroup/test_2149
Start: pids.current: 0
Start: cgroup.procs:
0: pids.current: 97
0: cgroup.procs:
1: pids.current: 14
1: cgroup.procs:
2: pids.current: 14
2: cgroup.procs:
3: pids.current: 14
3: cgroup.procs:
4: pids.current: 14
4: cgroup.procs:
5: pids.current: 14
5: cgroup.procs:
6: pids.current: 14
6: cgroup.procs:
7: pids.current: 14
7: cgroup.procs:
8: pids.current: 14
8: cgroup.procs:
9: pids.current: 14
9: cgroup.procs:
10: pids.current: 14
10: cgroup.procs:
11: pids.current: 14
11: cgroup.procs:
[root@xps test]# ps aux|grep python
root 3160 0.0 0.0 234048 2160 pts/2 S+ 03:34 0:00 grep python
[root@xps test]# uname -a
Linux xps 5.0.0-rc3-00104-gc04e2a780caf-dirty #289 SMP PREEMPT Sat Jan 26 03:29:45 CET 2019 x86_64 Intel(R)_Core(TM)_i9-8950HK_CPU_@_2.90GHz PLD Linux
kernel config:
http://ixion.pld-linux.org/~arekm/cgroup-oom-kernelconf-2.txt
dmesg:
http://ixion.pld-linux.org/~arekm/cgroup-oom-2.txt
Quoted 108 lines
Subject: [PATCH v2] memcg: killed threads should not invoke memcg OOM killer
From: Tetsuo Handa <[email protected]>
To: Andrew Morton <[email protected]>,
Johannes Weiner <[email protected]>, David Rientjes <[email protected]>
Cc: Michal Hocko <[email protected]>, [email protected],
Kirill Tkhai <[email protected]>,
Linus Torvalds <[email protected]>
Message-ID: <[email protected]>
Date: Tue, 15 Jan 2019 19:17:27 +0900If $N > $M, a single process with $N threads in a memcg group can easily kill all $M processes in that memcg group, for
mem_cgroup_out_of_memory()does not check if current thread needs to invoke the memcg OOM killer.T1@P1 |T2...$N@P1|P2...$M |OOM reaper
----------+----------+----------+----------# all sleeping try_charge() mem_cgroup_out_of_memory() mutex_lock(oom_lock) try_charge() mem_cgroup_out_of_memory() mutex_lock(oom_lock) out_of_memory() select_bad_process() oom_kill_process(P1) wake_oom_reaper() oom_reap_task() # ignores P1 mutex_unlock(oom_lock) out_of_memory() select_bad_process(P2...$M) # all killed by T2...$N@P1 wake_oom_reaper() oom_reap_task() # ignores P2...$M mutex_unlock(oom_lock)We don't need to invoke the memcg OOM killer if current thread was killed when waiting for
oom_lock, formem_cgroup_oom_synchronize(true)can count ontry_charge()whenmem_cgroup_oom_synchronize(true)can not make forward progress becausetry_charge()allows already killed/exiting threads to make forward progress, andmemory_max_write()can bail out upon signals.At first Michal thought that fatal signal check is racy compared to
tsk_is_oom_victim()check. But an experiment showed that trying to callmark_oom_victim()on all killed thread groups is more racy than fatal signal check due totask_will_free_mem(current)path inout_of_memory().Therefore, this patch changes
mem_cgroup_out_of_memory()to bail out uponshould_force_charge()== T rather than uponfatal_signal_pending()== T, forshould_force_charge()== T &&signal_pending(current)== F atmemory_max_write()can't happen because current thread won't callmemory_max_write()after gettingPF_EXITING.Signed-off-by Tetsuo Handa <[email protected]>Acked-by Michal Hocko <[email protected]>Fixes 29ef680ae7c2 ("memcg, oom: move out_of_memory back to the charge path")Fixes 3100dab2aa09 ("mm: memcontrol: print proper OOM header when no eligible victim left")Cc [email protected] # 4.19+--- mm/memcontrol.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)mm/memcontrol.c +14
-5@@ -248,6 +248,12 @@ enum res_type { iter !=NULL ; \ iter = mem_cgroup_iter(NULL, iter, NULL)) +static inline bool should_force_charge (void ) +{ +return tsk_is_oom_victim (current) ||fatal_signal_pending (current) || + (current->flags &PF_EXITING ); +} +/* Some nice accessors for the vmpressure. */ struct vmpressure *memcg_to_vmpressure (struct mem_cgroup *memcg) {@@ -1389,8 +1395,13 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, };bool ret; -mutex_lock (&oom_lock); - ret =out_of_memory (&oc); +if (mutex_lock_killable (&oom_lock)) +return true; +/* +* A few threads which were not waiting at mutex_lock_killable() can +* fail to bail out. Therefore, check again after holding oom_lock. +*/ + ret =should_force_charge () ||out_of_memory (&oc);mutex_unlock (&oom_lock);return ret; }@@ -2209,9 +2220,7 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,* bypass the last charges so that they can exit quickly and * free their memory. */ -if (unlikely (tsk_is_oom_victim (current) || -fatal_signal_pending (current) || - current->flags &PF_EXITING )) +if (unlikely (should_force_charge ())) goto force;/*
Signature · 1 line
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )
Quoted 2 lines · Arkadiusz MiÅ›kiewicz
What is wrong with this output? It seems to me that the OOM killer is killing processes as soon as python 3 fork()s one. Although "potentially unexpected fatal signal 7." messages due to handling SIGBUS at get_signal() after the OOM reaper reclaimed the OOM victim's memory is a bit noisy, I don't think that something is wrong.
Jan 26 03:33:49 xps kernel: python3 invoked oom-killer: gfp_mask=0x6000c0(GFP_KERNEL), order=0, oom_score_adj=0 Jan 26 03:33:52 xps kernel: potentially unexpected fatal signal 7.
You seem to be monitoring cgroup statistic values for only 1 minute, but since the fork bombs might take longer than 1 minute, I'm not sure that the statistic values after terminating cg.py and waited for a while (e.g. 1 minute) is still showing unexpected values.
Quoted 3 lines · Tetsuo Handa
Quoted 2 lines · Arkadiusz MiÅ›kiewicz
OK. There is a refcount leak bug in wake_oom_reaper() which became visible by enabling oom_group setting.
static void wake_oom_reaper(struct task_struct *tsk)
{
/* tsk is already queued? */
if (tsk == oom_reaper_list || tsk->oom_reaper_list)
return;
get_task_struct(tsk);
spin_lock(&oom_reaper_lock);
tsk->oom_reaper_list = oom_reaper_list;
oom_reaper_list = tsk;
spin_unlock(&oom_reaper_lock);
trace_wake_reaper(tsk->pid);
wake_up(&oom_reaper_wait);
}(1) oom_reaper_list and tsk(*)->oom_reaper_list are initially NULL.
(2) Since tsk(2160) != oom_reaper_list && tsk(2160)->oom_reaper_list == NULL,
get_task_struct(tsk(2160)) is called.
(3) tsk(2160)->oom_reaper_list = oom_reaper_list (which is NULL).
(4) oom_reaper_list = tsk(2160) (which is not NULL).
(5) Since tsk(2150) != oom_reaper_list (which is tsk(2160)) && tsk(2150)->oom_reaper_list == NULL,
get_task_struct(tsk(2150)) is called.(6) Step (5) repeats on tsk(2153, 2164. 2166, 2163, 2159, 2161, 2154).
(7) Since tsk(2160) != oom_reaper_list (which is tsk(2154)) && tsk(2160)->oom_reaper_list == NULL (because it was NULL as of (2)), get_task_struct(tsk(2160)) is called again.
(8) oom_reap_task() calls put_task_struct(tsk(2160)) for only once because tsk(2160) appears on the oom_reaper_list for only once; leaking refcount.
Jan 26 03:33:49 xps kernel: Memory cgroup out of memory: Kill process 2160 (python3) score 66 or sacrifice child Jan 26 03:33:49 xps kernel: Killed process 2160 (python3) total-vm:272176kB, anon-rss:31668kB, file-rss:3248kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Tasks in /test_2149 are going to be killed due to memory.oom.group set Jan 26 03:33:49 xps kernel: Killed process 2150 (python3) total-vm:272176kB, anon-rss:27572kB, file-rss:3248kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2153 (python3) total-vm:261936kB, anon-rss:17396kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2164 (python3) total-vm:272176kB, anon-rss:27572kB, file-rss:3248kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2166 (python3) total-vm:261936kB, anon-rss:15088kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2163 (python3) total-vm:261936kB, anon-rss:21496kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2159 (python3) total-vm:282420kB, anon-rss:23944kB, file-rss:3128kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2161 (python3) total-vm:251692kB, anon-rss:11172kB, file-rss:3060kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2154 (python3) total-vm:261936kB, anon-rss:15084kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2160 (python3) total-vm:272176kB, anon-rss:31668kB, file-rss:3248kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2155 (python3) total-vm:261936kB, anon-rss:17364kB, file-rss:3056kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2168 (python3) total-vm:272176kB, anon-rss:29620kB, file-rss:3108kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2156 (python3) total-vm:251692kB, anon-rss:11204kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2157 (python3) total-vm:251692kB, anon-rss:11172kB, file-rss:3088kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2169 (python3) total-vm:261936kB, anon-rss:19448kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2158 (python3) total-vm:272176kB, anon-rss:23944kB, file-rss:3192kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2170 (python3) total-vm:251692kB, anon-rss:13252kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2171 (python3) total-vm:261936kB, anon-rss:17396kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2173 (python3) total-vm:251692kB, anon-rss:11204kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2152 (python3) total-vm:261936kB, anon-rss:13724kB, file-rss:3100kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2174 (python3) total-vm:251692kB, anon-rss:11160kB, file-rss:3120kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2172 (python3) total-vm:251692kB, anon-rss:9128kB, file-rss:3116kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2187 (python3) total-vm:261936kB, anon-rss:23516kB, file-rss:3116kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2184 (python3) total-vm:251692kB, anon-rss:13500kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2151 (python3) total-vm:251692kB, anon-rss:9108kB, file-rss:3096kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2182 (python3) total-vm:251692kB, anon-rss:12196kB, file-rss:3140kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2175 (python3) total-vm:261936kB, anon-rss:13996kB, file-rss:3124kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2183 (python3) total-vm:251692kB, anon-rss:9124kB, file-rss:3112kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2177 (python3) total-vm:251692kB, anon-rss:9148kB, file-rss:3140kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2186 (python3) total-vm:261936kB, anon-rss:15336kB, file-rss:3152kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2189 (python3) total-vm:251692kB, anon-rss:9156kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2178 (python3) total-vm:251692kB, anon-rss:11204kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2185 (python3) total-vm:261936kB, anon-rss:15084kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2190 (python3) total-vm:251692kB, anon-rss:11204kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2179 (python3) total-vm:251692kB, anon-rss:9156kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2180 (python3) total-vm:251692kB, anon-rss:5060kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2181 (python3) total-vm:261936kB, anon-rss:21492kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2176 (python3) total-vm:261936kB, anon-rss:15348kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2188 (python3) total-vm:251692kB, anon-rss:7108kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2191 (python3) total-vm:261936kB, anon-rss:14556kB, file-rss:3188kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: Killed process 2192 (python3) total-vm:241448kB, anon-rss:3456kB, file-rss:2712kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2163 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2192 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2191 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2188 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2176 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2181 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2180 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2179 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2190 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2185 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2178 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2189 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2186 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2177 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2175 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2182 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2151 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2184 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2187 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2172 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2174 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2173 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2171 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2158 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2169 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2157 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2156 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2168 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2155 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2160 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2154 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:49 xps kernel: oom_reaper: reaped process 2161 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB Jan 26 03:33:50 xps kernel: python3 invoked oom-killer: gfp_mask=0x6000c0(GFP_KERNEL), order=0, oom_score_adj=0 Jan 26 03:33:50 xps kernel: CPU: 1 PID: 2217 Comm: python3 Tainted: G E T 5.0.0-rc3-00104-gc04e2a780caf-dirty #289
Since we assumed that wake_oom_reaper() is called for only once for one out_of_memory() request,
/* tsk is already queued? */ if (tsk == oom_reaper_list || tsk->oom_reaper_list) return;
no longer works.
Arkadiusz, will you try this patch?
From 48744b6339cf649a69b55997e138c17df1ecc897 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sat, 26 Jan 2019 20:00:51 +0900
Subject: [PATCH] oom, oom_reaper: do not enqueue same task twice
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in wake_oom_reaper() which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.
This bug existed since the OOM reaper became invokable from task_will_free_mem(current) path in out_of_memory() in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by calling wake_oom_reaper() on the same task from one out_of_memory() request.
Fix this bug using an approach used by commit 855b018325737f76 ("oom, oom_reaper: disable oom_reaper for oom_kill_allocating_task"). Since task_will_free_mem(p) == false if p->mm == NULL, we can assume that p->mm != NULL when wake_oom_reaper() is called from task_will_free_mem() paths. As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory via task_will_free_mem(current) path.
--- mm/oom_kill.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
mm/oom_kill.c +13 -15
@@ -505,14 +505,6 @@ bool __oom_reap_task_mm(struct mm_struct *mm)struct vm_area_struct *vma;bool ret = true; -/* -* Tell all users of get_user/copy_from_user etc... that the content -* is no longer stable. No barriers really needed because unmapping -* should imply barriers already and the reader would hit a page fault -* if it stumbled over a reaped memory. -*/ -set_bit (MMF_UNSTABLE , &mm->flags); -for (vma = mm->mmap ; vma; vma = vma->vm_next) {if (!can_madv_dontneed_vma (vma))continue ;
@@ -645,10 +637,15 @@ static int oom_reaper(void *unused)return 0 ; } -static void wake_oom_reaper (struct task_struct *tsk) +static void wake_oom_reaper (struct task_struct *tsk,struct mm_struct *mm) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* +* Tell all users of get_user/copy_from_user etc... that the content +* is no longer stable. No barriers really needed because unmapping +* should imply barriers already and the reader would hit a page fault +* if it stumbled over a reaped memory. +*/ +if (test_and_set_bit (MMF_UNSTABLE , &mm->flags))return ;get_task_struct (tsk);
@@ -668,7 +665,8 @@ static int __init oom_init(void) } subsys_initcall(oom_init)#else -static inline void wake_oom_reaper (struct task_struct *tsk) +static inline void wake_oom_reaper (struct task_struct *tsk, +struct mm_struct *mm) { }#endif /* CONFIG_MMU */
@@ -915,7 +913,7 @@ static void __oom_kill_process(struct task_struct *victim)rcu_read_unlock ();if (can_oom_reap) -wake_oom_reaper (victim); +wake_oom_reaper (victim, mm);mmdrop (mm);put_task_struct (victim);
@@ -955,7 +953,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)task_lock (p);if (task_will_free_mem (p)) {mark_oom_victim (p); -wake_oom_reaper (p); +wake_oom_reaper (p, p->mm);task_unlock (p);put_task_struct (p);return ;
@@ -1085,7 +1083,7 @@ bool out_of_memory(struct oom_control *oc)*/ if (task_will_free_mem (current)) {mark_oom_victim (current); -wake_oom_reaper (current); +wake_oom_reaper (current, current->mm);return true; }
Signature · 1 line
1.8.3.1
Arkadiusz Miśkiewicz
Tested-byQuoted 1 line · Tetsuo Handa
Arkadiusz, will you try this patch?
Works. Several tries and always getting 0 pids.current after ~1s.
Please use
(using gmail for transport only since vger postmasters aren't reasonable)
And also
Testing was done on:
5.0.0-rc3-00104-gc04e2a780caf-dirty
Thanks!
Quoted 109 lines
From
48744b6339cf649a69b55997e138c17df1ecc897Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sat, 26 Jan 2019 20:00:51 +0900
Subject: [PATCH] oom,oom_reaper: do not enqueue same task twiceArkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). Sincetask_will_free_mem(p)== false ifp->mm== NULL, we can assume thatp->mm!= NULL whenwake_oom_reaper()is called fromtask_will_free_mem()paths. As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.Signed-off-by Tetsuo Handa <[email protected]>Reported-by Arkadiusz Miśkiewicz <[email protected]>Fixes af8e15cc85a25315 ("oom, oom_reaper: do not enqueue task if it is on the oom_reaper_list head")--- mm/oom_kill.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)mm/oom_kill.c +13
-15@@ -505,14 +505,6 @@ bool __oom_reap_task_mm(struct mm_struct *mm)struct vm_area_struct *vma;bool ret = true; -/* -* Tell all users of get_user/copy_from_user etc... that the content -* is no longer stable. No barriers really needed because unmapping -* should imply barriers already and the reader would hit a page fault -* if it stumbled over a reaped memory. -*/ -set_bit (MMF_UNSTABLE , &mm->flags); -for (vma = mm->mmap ; vma; vma = vma->vm_next) {if (!can_madv_dontneed_vma (vma))continue ;@@ -645,10 +637,15 @@ static int oom_reaper(void *unused)return 0 ; } -static void wake_oom_reaper (struct task_struct *tsk) +static void wake_oom_reaper (struct task_struct *tsk,struct mm_struct *mm) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* +* Tell all users of get_user/copy_from_user etc... that the content +* is no longer stable. No barriers really needed because unmapping +* should imply barriers already and the reader would hit a page fault +* if it stumbled over a reaped memory. +*/ +if (test_and_set_bit (MMF_UNSTABLE , &mm->flags))return ;get_task_struct (tsk);@@ -668,7 +665,8 @@ static int __init oom_init(void) } subsys_initcall(oom_init)#else -static inline void wake_oom_reaper (struct task_struct *tsk) +static inline void wake_oom_reaper (struct task_struct *tsk, +struct mm_struct *mm) { }#endif /* CONFIG_MMU */ @@ -915,7 +913,7 @@ static void __oom_kill_process(struct task_struct *victim)rcu_read_unlock ();if (can_oom_reap) -wake_oom_reaper (victim); +wake_oom_reaper (victim, mm);mmdrop (mm);put_task_struct (victim);@@ -955,7 +953,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)task_lock (p);if (task_will_free_mem (p)) {mark_oom_victim (p); -wake_oom_reaper (p); +wake_oom_reaper (p, p->mm);task_unlock (p);put_task_struct (p);return ;@@ -1085,7 +1083,7 @@ bool out_of_memory(struct oom_control *oc)*/ if (task_will_free_mem (current)) {mark_oom_victim (current); -wake_oom_reaper (current); +wake_oom_reaper (current, current->mm);return true; }
Signature · 1 line
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )
PATCH v2 1/1 oom, oom_reaper: do not enqueue same task twice
Quoted 6 lines · Arkadiusz Miśkiewicz
Quoted 1 line · Tetsuo Handa
Arkadiusz, will you try this patch?
Works. Several tries and always getting 0 pids.current after ~1s.
Thank you for testing.
I updated this patch to use tsk->signal->oom_mm (a snapshot of tsk->mm saved by mark_oom_victim(tsk)) rather than raw tsk->mm so that we don't need to worry about possibility of changing tsk->mm across multiple wake_oom_reaper(tsk) calls.
From 9c9e935fc038342c48461aabca666f1b544e32b1 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sat, 26 Jan 2019 21:57:25 +0900
Subject: [PATCH v2] oom, oom_reaper: do not enqueue same task twice
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in wake_oom_reaper() which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.
This bug existed since the OOM reaper became invokable from task_will_free_mem(current) path in out_of_memory() in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by calling wake_oom_reaper() on the same task from one out_of_memory() request.
Fix this bug using an approach used by commit 855b018325737f76 ("oom, oom_reaper: disable oom_reaper for oom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory via task_will_free_mem(current) path.
--- mm/oom_kill.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
mm/oom_kill.c +7 -10
@@ -505,14 +505,6 @@ bool __oom_reap_task_mm(struct mm_struct *mm)struct vm_area_struct *vma;bool ret = true; -/* -* Tell all users of get_user/copy_from_user etc... that the content -* is no longer stable. No barriers really needed because unmapping -* should imply barriers already and the reader would hit a page fault -* if it stumbled over a reaped memory. -*/ -set_bit (MMF_UNSTABLE , &mm->flags); -for (vma = mm->mmap ; vma; vma = vma->vm_next) {if (!can_madv_dontneed_vma (vma))continue ;
@@ -647,8 +639,13 @@ static int oom_reaper(void *unused)static void wake_oom_reaper (struct task_struct *tsk) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* +* Tell all users of get_user/copy_from_user etc... that the content +* is no longer stable. No barriers really needed because unmapping +* should imply barriers already and the reader would hit a page fault +* if it stumbled over a reaped memory. +*/ +if (test_and_set_bit (MMF_UNSTABLE , &tsk->signal->oom_mm->flags))return ;get_task_struct (tsk);
Signature · 1 line
1.8.3.1
Michal Hocko
maintainerRe: [PATCH v2] oom, oom_reaper: do not enqueue same task twice
On Sat 26-01-19 22:10:52, Tetsuo Handa wrote:
[...]
Quoted 18 lines
Quoted 1 line
From
9c9e935fc038342c48461aabca666f1b544e32b1Mon Sep 17 00:00:00 2001From: Tetsuo Handa <[email protected]>
Date: Sat, 26 Jan 2019 21:57:25 +0900
Subject: [PATCH v2] oom,oom_reaper: do not enqueue same task twiceArkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.
Quoted 4 lines
Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.
Thanks for the analysis and the patch. This should work, I believe but I am not really thrilled to overload the meaning of the MMF_UNSTABLE. The flag is meant to signal accessing address space is not stable and it is not aimed to synchronize oom reaper with the oom path.
Can we make use mark_oom_victim directly? I didn't get to think that through right now so I might be missing something but this should prevent repeating queueing as well.
mm/oom_kill.c +8 -6
@@ -690,7 +690,7 @@ static void mark_oom_victim(struct task_struct *tsk)WARN_ON (oom_killer_disabled);/* OOM killer might race with memcg OOM */ if (test_and_set_tsk_thread_flag (tsk,TIF_MEMDIE )) -return ; +return false;/* oom_mm is bound to the signal struct life time. */ if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) {
@@ -707,6 +707,8 @@ static void mark_oom_victim(struct task_struct *tsk)__thaw_task (tsk);atomic_inc (&oom_victims);trace_mark_victim (tsk->pid); + +return true; }/**
@@ -873,7 +875,7 @@ static void __oom_kill_process(struct task_struct *victim)* reserves from the user space under its control. */ do_send_sig_info (SIGKILL ,SEND_SIG_PRIV , victim,PIDTYPE_TGID ); -mark_oom_victim (victim); + can_oom_reap =mark_oom_victim (victim); pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n", task_pid_nr(victim), victim->comm, K(victim->mm->total_vm), K(get_mm_counter(victim->mm, MM_ANONPAGES)),
@@ -954,8 +956,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)*/ task_lock (p);if (task_will_free_mem (p)) { -mark_oom_victim (p); -wake_oom_reaper (p); + if (mark_oom_victim(p) +wake_oom_reaper (p);task_unlock (p);put_task_struct (p);return ;
@@ -1084,8 +1086,8 @@ bool out_of_memory(struct oom_control *oc)* quickly exit and free its memory. */ if (task_will_free_mem (current)) { -mark_oom_victim (current); -wake_oom_reaper (current); +if (mark_oom_victim (current)) +wake_oom_reaper (current);return true; }
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v2] oom, oom_reaper: do not enqueue same task twice
Quoted 8 lines · Michal Hocko
Thanks for the analysis and the patch. This should work, I believe but I am not really thrilled to overload the meaning of the
MMF_UNSTABLE. The flag is meant to signal accessing address space is not stable and it is not aimed to synchronize oom reaper with the oom path.Can we make use
mark_oom_victimdirectly? I didn't get to think that through right now so I might be missing something but this should prevent repeating queueing as well.
Yes, TIF_MEMDIE would work. But you are planning to remove TIF_MEMDIE. Also, TIF_MEMDIE can't avoid enqueuing many threads sharing mm_struct to the OOM reaper. There is no need to enqueue many threads sharing mm_struct because the OOM reaper acts on mm_struct rather than task_struct. Thus, enqueuing based on per mm_struct flag sounds better, but MMF_OOM_VICTIM cannot be set from wake_oom_reaper(victim) because victim's mm might be already inside exit_mmap() when wake_oom_reaper(victim) is called after task_unlock(victim).
We could reintroduce MMF_OOM_KILLED in commit 855b018325737f76 ("oom, oom_reaper: disable oom_reaper for oom_kill_allocating_task") if you don't like overloading the meaning of the MMF_UNSTABLE. But since MMF_UNSTABLE is available in Linux 4.9+ kernels (which covers all LTS stable versions with the OOM reaper support), we can temporarily use MMF_UNSTABLE for ease of backporting.
Michal Hocko
maintainerRe: [PATCH v2] oom, oom_reaper: do not enqueue same task twice
Quoted 18 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
Thanks for the analysis and the patch. This should work, I believe but I am not really thrilled to overload the meaning of the
MMF_UNSTABLE. The flag is meant to signal accessing address space is not stable and it is not aimed to synchronize oom reaper with the oom path.Can we make use
mark_oom_victimdirectly? I didn't get to think that through right now so I might be missing something but this should prevent repeating queueing as well.Yes,
TIF_MEMDIEwould work. But you are planning to removeTIF_MEMDIE. Also,TIF_MEMDIEcan't avoid enqueuing many threads sharingmm_structto the OOM reaper. There is no need to enqueue many threads sharingmm_structbecause the OOM reaper acts onmm_structrather thantask_struct. Thus, enqueuing based on permm_structflag sounds better, butMMF_OOM_VICTIMcannot be set fromwake_oom_reaper(victim)because victim's mm might be already insideexit_mmap()whenwake_oom_reaper(victim)is called aftertask_unlock(victim).
Quoted 6 lines
We could reintroduce
MMF_OOM_KILLEDin commit855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task") if you don't like overloading the meaning of theMMF_UNSTABLE. But sinceMMF_UNSTABLEis available in Linux 4.9+ kernels (which covers all LTS stable versions with the OOM reaper support), we can temporarily useMMF_UNSTABLEfor ease of backporting.
I agree that a per-mm state is more optimal but I would rather fix the issue in a clear way first and only then think about an optimization on top. Queueing based on mark_oom_victim (whatever that uses to guarantee the victim is marked atomically and only once) makes sense from the conceptual point of view and it makes a lot of sense to start from there. MMF_UNSTABLE has a completely different purpose. So unless you see a correctness issue with that then I would rather go that way.
Signature · 2 lines
Michal Hocko SUSE Labs
PATCH v3 1/1 oom, oom_reaper: do not enqueue same task twice
Quoted 26 lines · Michal Hocko
Quoted 18 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
Thanks for the analysis and the patch. This should work, I believe but I am not really thrilled to overload the meaning of the
MMF_UNSTABLE. The flag is meant to signal accessing address space is not stable and it is not aimed to synchronize oom reaper with the oom path.Can we make use
mark_oom_victimdirectly? I didn't get to think that through right now so I might be missing something but this should prevent repeating queueing as well.Yes,
TIF_MEMDIEwould work. But you are planning to removeTIF_MEMDIE. Also,TIF_MEMDIEcan't avoid enqueuing many threads sharingmm_structto the OOM reaper. There is no need to enqueue many threads sharingmm_structbecause the OOM reaper acts onmm_structrather thantask_struct. Thus, enqueuing based on permm_structflag sounds better, butMMF_OOM_VICTIMcannot be set fromwake_oom_reaper(victim)because victim's mm might be already insideexit_mmap()whenwake_oom_reaper(victim)is called aftertask_unlock(victim).Quoted 6 lines
We could reintroduce
MMF_OOM_KILLEDin commit855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task") if you don't like overloading the meaning of theMMF_UNSTABLE. But sinceMMF_UNSTABLEis available in Linux 4.9+ kernels (which covers all LTS stable versions with the OOM reaper support), we can temporarily useMMF_UNSTABLEfor ease of backporting.
Quoted 8 lines
I agree that a per-mm state is more optimal but I would rather fix the issue in a clear way first and only then think about an optimization on top. Queueing based on
mark_oom_victim(whatever that uses to guarantee the victim is marked atomically and only once) makes sense from the conceptual point of view and it makes a lot of sense to start from there.MMF_UNSTABLEhas a completely different purpose. So unless you see a correctness issue with that then I would rather go that way.
Then, adding a per mm_struct flag is better. I don't see the difference between reusing MMF_UNSTABLE as a flag for whether wake_oom_reaper() for that victim's memory was already called (what you think as an overload) and reusing TIF_MEMDIE as a flag for whether wake_oom_reaper() for that victim thread can be called (what I think as an overload). We want to remove TIF_MEMDIE, and we can actually remove TIF_MEMDIE if you stop whack-a-mole "can you observe it in real workload/program?" game. I don't see a correctness issue with TIF_MEMDIE but I don't want to go TIF_MEMDIE way.
From 9c9e935fc038342c48461aabca666f1b544e32b1 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sun, 27 Jan 2019 23:51:37 +0900
Subject: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in wake_oom_reaper() which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.
This bug existed since the OOM reaper became invokable from task_will_free_mem(current) path in out_of_memory() in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by calling wake_oom_reaper() on the same task from one out_of_memory() request.
Fix this bug using an approach used by commit 855b018325737f76 ("oom, oom_reaper: disable oom_reaper for oom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory via task_will_free_mem(current) path.
--- include/linux/sched/coredump.h | 1 + mm/oom_kill.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/sched/coredump.h +1 -0
@@ -71,6 +71,7 @@ static inline int get_dumpable(struct mm_struct *mm)#define MMF_HUGE_ZERO_PAGE 23/* mm has ever used the global huge zero page */ #define MMF_DISABLE_THP 24/* disable THP for all VMAs */ #define MMF_OOM_VICTIM 25/* mm is the oom victim */ +#define MMF_OOM_REAP_QUEUED 26/* mm was queued for oom_reaper */ #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
mm/oom_kill.c +2 -2
@@ -647,8 +647,8 @@ static int oom_reaper(void *unused)static void wake_oom_reaper (struct task_struct *tsk) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* mm is already queued? */ +if (test_and_set_bit (MMF_OOM_REAP_QUEUED , &tsk->signal->oom_mm->flags))return ;get_task_struct (tsk);
Signature · 1 line
1.8.3.1
Re: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
On Sun 27-01-19 23:57:38, Tetsuo Handa wrote:
[...]
Quoted 23 lines
Quoted 1 line
From
9c9e935fc038342c48461aabca666f1b544e32b1Mon Sep 17 00:00:00 2001From: Tetsuo Handa <[email protected]>
Date: Sun, 27 Jan 2019 23:51:37 +0900
Subject: [PATCH v3] oom,oom_reaper: do not enqueue same task twiceArkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.
Quoted 4 lines
Signed-off-by Tetsuo Handa <[email protected]>Reported-by Arkadiusz Miśkiewicz <[email protected]>Tested-by Arkadiusz Miśkiewicz <[email protected]>Fixes af8e15cc85a25315 ("oom, oom_reaper: do not enqueue task if it is on the oom_reaper_list head")
Quoted 34 lines
--- include/linux/sched/coredump.h | 1 + mm/oom_kill.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)include/linux/sched/coredump.h +1
-0@@ -71,6 +71,7 @@ static inline int get_dumpable(struct mm_struct *mm)#define MMF_HUGE_ZERO_PAGE 23/* mm has ever used the global huge zero page */ #define MMF_DISABLE_THP 24/* disable THP for all VMAs */ #define MMF_OOM_VICTIM 25/* mm is the oom victim */ +#define MMF_OOM_REAP_QUEUED 26/* mm was queued for oom_reaper */ #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\mm/oom_kill.c +2
-2@@ -647,8 +647,8 @@ static int oom_reaper(void *unused)static void wake_oom_reaper (struct task_struct *tsk) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* mm is already queued? */ +if (test_and_set_bit (MMF_OOM_REAP_QUEUED , &tsk->signal->oom_mm->flags))return ;get_task_struct (tsk);Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
In reply to Tetsuo HandaQuoted 71 lines · Tetsuo Handa
Quoted 26 lines · Michal Hocko
Quoted 18 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
Thanks for the analysis and the patch. This should work, I believe but I am not really thrilled to overload the meaning of the
MMF_UNSTABLE. The flag is meant to signal accessing address space is not stable and it is not aimed to synchronize oom reaper with the oom path.Can we make use
mark_oom_victimdirectly? I didn't get to think that through right now so I might be missing something but this should prevent repeating queueing as well.Yes,
TIF_MEMDIEwould work. But you are planning to removeTIF_MEMDIE. Also,TIF_MEMDIEcan't avoid enqueuing many threads sharingmm_structto the OOM reaper. There is no need to enqueue many threads sharingmm_structbecause the OOM reaper acts onmm_structrather thantask_struct. Thus, enqueuing based on permm_structflag sounds better, butMMF_OOM_VICTIMcannot be set fromwake_oom_reaper(victim)because victim's mm might be already insideexit_mmap()whenwake_oom_reaper(victim)is called aftertask_unlock(victim).Quoted 6 lines
We could reintroduce
MMF_OOM_KILLEDin commit855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task") if you don't like overloading the meaning of theMMF_UNSTABLE. But sinceMMF_UNSTABLEis available in Linux 4.9+ kernels (which covers all LTS stable versions with the OOM reaper support), we can temporarily useMMF_UNSTABLEfor ease of backporting.Quoted 8 lines
I agree that a per-mm state is more optimal but I would rather fix the issue in a clear way first and only then think about an optimization on top. Queueing based on
mark_oom_victim(whatever that uses to guarantee the victim is marked atomically and only once) makes sense from the conceptual point of view and it makes a lot of sense to start from there.MMF_UNSTABLEhas a completely different purpose. So unless you see a correctness issue with that then I would rather go that way.Then, adding a per
mm_structflag is better. I don't see the difference between reusingMMF_UNSTABLEas a flag for whetherwake_oom_reaper()for that victim's memory was already called (what you think as an overload) and reusingTIF_MEMDIEas a flag for whetherwake_oom_reaper()for that victim thread can be called (what I think as an overload). We want to removeTIF_MEMDIE, and we can actually removeTIF_MEMDIEif you stop whack-a-mole "can you observe it in real workload/program?" game. I don't see a correctness issue withTIF_MEMDIEbut I don't want to goTIF_MEMDIEway.From
9c9e935fc038342c48461aabca666f1b544e32b1Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sun, 27 Jan 2019 23:51:37 +0900
Subject: [PATCH v3] oom,oom_reaper: do not enqueue same task twiceArkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.
Quoted 4 lines
Signed-off-by Tetsuo Handa <[email protected]>Reported-by Arkadiusz Miśkiewicz <[email protected]>Tested-by Arkadiusz Miśkiewicz <[email protected]>Fixes af8e15cc85a25315 ("oom, oom_reaper: do not enqueue task if it is on the oom_reaper_list head")
Thank you, Tetsuo!
Andrew Morton
maintainerRe: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
In reply to Tetsuo HandaQuoted 13 lines · On Sun, 27 Jan 2019 23:57:38 +0900 Tetsuo Handa…
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.
Quoted 5 lines
Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.
Do we think this is serious enough to warrant a -stable backport?
Michal Hocko
maintainerRe: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
Quoted 15 lines · Andrew Morton
Quoted 13 lines · On Sun, 27 Jan 2019 23:57:38 +0900 Tetsuo Handa…
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.
Quoted 7 lines
Quoted 5 lines
Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.Do we think this is serious enough to warrant a -stable backport?
Yes, I would go with stable backport.
Signature · 2 lines
Michal Hocko SUSE Labs
Johannes Weiner
maintainerRe: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
In reply to Tetsuo HandaHi Tetsuo,
Quoted 12 lines · Tetsuo Handa
From
9c9e935fc038342c48461aabca666f1b544e32b1Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Sun, 27 Jan 2019 23:51:37 +0900
Subject: [PATCH v3] oom,oom_reaper: do not enqueue same task twiceArkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in
wake_oom_reaper()which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.
Quoted 5 lines
This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.
This changelog seems a little terse compared to how tricky this is.
Can you please include an explanation here *how* this bug is possible? I.e. the race condition that causes the function te be entered twice and the existing re-entrance check in there to fail.
Quoted 4 lines
Fix this bug using an approach used by commit
855b018325737f76("oom,oom_reaper: disableoom_reaperforoom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory viatask_will_free_mem(current)path.
Re: [PATCH v3] oom, oom_reaper: do not enqueue same task twice
Quoted 7 lines · Johannes Weiner
Quoted 5 lines · Tetsuo Handa
This bug existed since the OOM reaper became invokable from
task_will_free_mem(current)path inout_of_memory()in Linux 4.7, but memcg's group oom killing made it easier to trigger this bug by callingwake_oom_reaper()on the same task from oneout_of_memory()request.
Quoted 5 lines
This changelog seems a little terse compared to how tricky this is.
Can you please include an explanation here *how* this bug is possible? I.e. the race condition that causes the function te be entered twice and the existing re-entrance check in there to fail.
OK. Here is an updated patch. Only changelog part has changed. I hope this will provide enough information to stable kernel maintainers.
----------
From: Tetsuo Handa <[email protected]>
Subject: oom, oom_reaper: do not enqueue same task twice
Arkadiusz reported that enabling memcg's group oom killing causes strange memcg statistics where there is no task in a memcg despite the number of tasks in that memcg is not 0. It turned out that there is a bug in wake_oom_reaper() which allows enqueuing same task twice which makes impossible to decrease the number of tasks in that memcg due to a refcount leak.
This bug existed since the OOM reaper became invokable from task_will_free_mem(current) path in out_of_memory() in Linux 4.7,
T1@P1 |T2@P1 |T3@P1 |OOM reaper
----------+----------+----------+------------
# Processing an OOM victim in a different memcg domain.
try_charge()
mem_cgroup_out_of_memory()
mutex_lock(&oom_lock)
try_charge()
mem_cgroup_out_of_memory()
mutex_lock(&oom_lock)
try_charge()
mem_cgroup_out_of_memory()
mutex_lock(&oom_lock)
out_of_memory()
oom_kill_process(P1)
do_send_sig_info(SIGKILL, @P1)
mark_oom_victim(T1@P1)
wake_oom_reaper(T1@P1) # T1@P1 is enqueued.
mutex_unlock(&oom_lock)
out_of_memory()
mark_oom_victim(T2@P1)
wake_oom_reaper(T2@P1) # T2@P1 is enqueued.
mutex_unlock(&oom_lock)
out_of_memory()
mark_oom_victim(T1@P1)
wake_oom_reaper(T1@P1) # T1@P1 is enqueued again due to oom_reaper_list == T2@P1 && T1@P1->oom_reaper_list == NULL.
mutex_unlock(&oom_lock)
# Completed processing an OOM victim in a different memcg domain.
spin_lock(&oom_reaper_lock)
# T1P1 is dequeued.
spin_unlock(&oom_reaper_lock)but memcg's group oom killing made it easier to trigger this bug by calling wake_oom_reaper() on the same task from one out_of_memory() request.
Fix this bug using an approach used by commit 855b018325737f76 ("oom,oom_reaper: disable oom_reaper for oom_kill_allocating_task"). As a side effect of this patch, this patch also avoids enqueuing multiple threads sharing memory via task_will_free_mem(current) path.
--- include/linux/sched/coredump.h | 1 + mm/oom_kill.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/sched/coredump.h +1 -0
@@ -71,6 +71,7 @@ static inline int get_dumpable(struct mm_struct *mm)#define MMF_HUGE_ZERO_PAGE 23/* mm has ever used the global huge zero page */ #define MMF_DISABLE_THP 24/* disable THP for all VMAs */ #define MMF_OOM_VICTIM 25/* mm is the oom victim */ +#define MMF_OOM_REAP_QUEUED 26/* mm was queued for oom_reaper */ #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
mm/oom_kill.c +2 -2
@@ -647,8 +647,8 @@ static int oom_reaper(void *unused)static void wake_oom_reaper (struct task_struct *tsk) { -/* tsk is already queued? */ -if (tsk == oom_reaper_list || tsk->oom_reaper_list) +/* mm is already queued? */ +if (test_and_set_bit (MMF_OOM_REAP_QUEUED , &tsk->signal->oom_mm->flags))return ;get_task_struct (tsk);
Signature · 1 line
1.8.3.1
Quoted 42 lines · Arkadiusz Miśkiewicz
Quoted 41 lines · Tejun Heo
Quoted 39 lines · Arkadiusz Miśkiewicz
Quoted 26 lines · Arkadiusz Miśkiewicz
Quoted 25 lines · Arkadiusz Miśkiewicz
Quoted 5 lines · Aleksa Sarai
Quoted 4 lines · Arkadiusz Miśkiewicz
Using kernel 4.19.13.
For one cgroup I noticed weird behaviour:
Quoted 9 lines
Quoted 4 lines
# cat pids.current 60 # cat cgroup.procs #Are there any zombies in the cgroup? pids.current is linked up directly to
__put_task_struct(so exit(2) won't decrease it, only thetask_structactually being freed will decrease it).There are no zombie processes.
In mean time the problem shows on multiple servers and so far saw it only in cgroups that were OOMed.
What has changed on these servers (yesterday) is turning on memory.oom.group=1 for all cgroups and changing memory.high from 1G to "max" (leaving memory.max=2G limit only).
Quoted 8 lines
Quoted 2 lines
Previously there was no such problem.
I'm attaching reproducer. This time tried on different distribution kernel (arch linux).
After 60s pids.current still shows 37 processes even if there are no processes running (according to ps aux).
The same test on 5.0.0-rc3-00104-gc04e2a780caf and it's easy to reproduce bug. No processes in cgroup but pids.current reports 91.
Quoted 6 lines
Quoted 4 lines
Can you please see whether the problem can be reproduced on the current linux-next?
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gitI can reproduce on next (5.0.0-rc3-next-20190125), too:
How reliably you can reproduce it? I've tried to run your reproducer several times with different parameters, but wasn't lucky so far. What's yours cpu number and total ram size?
Can you, please, provide the corresponding dmesg output?
I've checked the code again, and my wild guess is that these missing tasks are waiting (maybe hopelessly) for the OOM reaper. Dmesg output might be very useful here.
Thanks!
Quoted 46 lines · Roman Gushchin
Quoted 45 lines · Arkadiusz Miśkiewicz
Quoted 44 lines · Tejun Heo
Quoted 33 lines · Arkadiusz Miśkiewicz
Quoted 32 lines · Arkadiusz Miśkiewicz
Quoted 18 lines · Arkadiusz Miśkiewicz
Quoted 5 lines · Aleksa Sarai
Quoted 4 lines · Arkadiusz Miśkiewicz
Using kernel 4.19.13.
For one cgroup I noticed weird behaviour:
Quoted 9 lines
Quoted 4 lines
# cat pids.current 60 # cat cgroup.procs #Are there any zombies in the cgroup? pids.current is linked up directly to
__put_task_struct(so exit(2) won't decrease it, only thetask_structactually being freed will decrease it).There are no zombie processes.
Quoted 9 lines
In mean time the problem shows on multiple servers and so far saw it only in cgroups that were OOMed.
What has changed on these servers (yesterday) is turning on memory.oom.group=1 for all cgroups and changing memory.high from 1G to "max" (leaving memory.max=2G limit only).
Previously there was no such problem.
I'm attaching reproducer. This time tried on different distribution kernel (arch linux).
Quoted 6 lines
Quoted 2 lines
After 60s pids.current still shows 37 processes even if there are no processes running (according to ps aux).
The same test on 5.0.0-rc3-00104-gc04e2a780caf and it's easy to reproduce bug. No processes in cgroup but pids.current reports 91.
Can you please see whether the problem can be reproduced on the current linux-next?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gitI can reproduce on next (5.0.0-rc3-next-20190125), too:
How reliably you can reproduce it? I've tried to run your reproducer several times with different parameters, but wasn't lucky so far.
Hmm, I'm able to reproduce each time using that python3 script.
Quoted 1 line
What's yours cpu number and total ram size?
On different machines:
1) old pc, 1 x intel E6600, 4GB of ram (arch linux 4.20.3 distro kernel), using python script
2) virtualbox vm, 1 cpu with 2 cores, 8GB of ram (pld kernel and custom built kernels like 5.0rc3 and 5.0rc3 next), using python script
3) server with 2 x intel E5405, 32GB of ram (4.19.13), with real life scenario
4) server with 1 x intel E5-2630 v2, 64GB of ram (4.19.15), with real life scenario
Quoted 2 lines
Can you, please, provide the corresponding dmesg output?
From my virtualbox vm, after 60s pids.current reports 7 despite no processes:
http://ixion.pld-linux.org/~arekm/cgroup-oom-1.txt
kernel config:
http://ixion.pld-linux.org/~arekm/cgroup-oom-kernelconf-1.txt
Using 5.0.0-rc3-next-20190125 on that vm.
Quoted 9 lines
I've checked the code again, and my wild guess is that these missing tasks are waiting (maybe hopelessly) for the OOM reaper. Dmesg output might be very useful here.
Thanks!
Signature · 1 line
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )