mm, oom: get rid of TIF_MEMDIE
Subsystems (25)
Michal Hocko
maintainercover mm, oom: get rid of TIF_MEMDIE
Hi,
this is an early RFC to see whether the approach I've taken is acceptable. The series is on top of the current mmotm tree (2016-08-31-16-06). I didn't get to test it so it might be completely broken.
The primary point of this series is to get rid of TIF_MEMDIE finally. Recent changes in the oom proper allows for that finally, I believe. Now that all the oom victims are reapable we are no longer depending on ALLOC_NO_WATERMARKS because the memory held by the victim is reclaimed asynchronously. A partial access to memory reserves should be sufficient just to guarantee that the oom victim is not starved due to other memory consumers. This also means that we do not have to pretend to be conservative and give access to memory reserves only to one thread from the process at the time. This is patch 1.
Patch 2 is a simple cleanup which turns TIF_MEMDIE users to tsk_is_oom_victim which is process rather than thread centric. None of those callers really requires to be thread aware AFAICS.
The tricky part then is exit_oom_victim vs. oom_killer_disable because TIF_MEMDIE acted as a token there so we had a way to count threads from the process. It didn't work 100% reliably and had it own issues but we have to replace it with something which doesn't rely on counting threads but rather find a moment when all threads have reached steady state in do_exit. This is what patch 3 does and I would really appreciate if Oleg could double check my thinking there. I am also CCing Al on that one because I am moving exit_io_context up in do_exit right before exit_notify.
The last patch just removes TIF_MEMDIE from the arch code because it is no longer needed anywhere.
I would give it some more testing but I am leaving for couple of days and I wanted to check whether this is a sound way to go before that.
I really appreciate any feedback.
Michal Hocko (4):
mm, oom: do not rely on TIF_MEMDIE for memory reserves access
mm: replace TIF_MEMDIE checks by tsk_is_oom_victim mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
arch: get rid of TIF_MEMDIE
The diffstat looks quite promissing to me
arch/alpha/include/asm/thread_info.h | 1 - arch/arc/include/asm/thread_info.h | 2 -- arch/arm/include/asm/thread_info.h | 1 - arch/arm64/include/asm/thread_info.h | 1 - arch/avr32/include/asm/thread_info.h | 2 -- arch/blackfin/include/asm/thread_info.h | 1 - arch/c6x/include/asm/thread_info.h | 1 - arch/cris/include/asm/thread_info.h | 1 - arch/frv/include/asm/thread_info.h | 1 - arch/h8300/include/asm/thread_info.h | 1 - arch/hexagon/include/asm/thread_info.h | 1 - arch/ia64/include/asm/thread_info.h | 1 - arch/m32r/include/asm/thread_info.h | 1 - arch/m68k/include/asm/thread_info.h | 1 - arch/metag/include/asm/thread_info.h | 1 - arch/microblaze/include/asm/thread_info.h | 1 - arch/mips/include/asm/thread_info.h | 1 - arch/mn10300/include/asm/thread_info.h | 1 - arch/nios2/include/asm/thread_info.h | 1 - arch/openrisc/include/asm/thread_info.h | 1 - arch/parisc/include/asm/thread_info.h | 1 - arch/powerpc/include/asm/thread_info.h | 1 - arch/s390/include/asm/thread_info.h | 1 - arch/score/include/asm/thread_info.h | 1 - arch/sh/include/asm/thread_info.h | 1 - arch/sparc/include/asm/thread_info_32.h | 1 - arch/sparc/include/asm/thread_info_64.h | 1 - arch/tile/include/asm/thread_info.h | 2 -- arch/um/include/asm/thread_info.h | 2 -- arch/unicore32/include/asm/thread_info.h | 1 - arch/x86/include/asm/thread_info.h | 1 - arch/xtensa/include/asm/thread_info.h | 1 - include/linux/sched.h | 2 +- kernel/cpuset.c | 9 ++--- kernel/exit.c | 38 +++++++++++++++------ kernel/freezer.c | 3 +- mm/internal.h | 11 ++++++ mm/memcontrol.c | 2 +- mm/oom_kill.c | 42 +++++++++++++---------- mm/page_alloc.c | 57 +++++++++++++++++++++++++------ 40 files changed, 118 insertions(+), 82 deletions(-)
--
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>
Michal Hocko
maintainerRFC 1/4 mm, oom: do not rely on TIF_MEMDIE for memory reserves access
From: Michal Hocko <[email protected]>
For ages we have been relying on TIF_MEMDIE thread flag to mark OOM victims and then, among other things, to give these threads full access to memory reserves. There are few shortcomings of this implementation, though.
First of all and the most serious one is that the full access to memory reserves is quite dangerous because we leave no safety room for the system to operate and potentially do last emergency steps to move on.
Secondly this flag is per task_struct while the OOM killer operates on mm_struct granularity so all processes sharing the given mm are killed. Giving the full access to all these task_structs could leave to a quick memory reserves depletion. We have tried to reduce this risk by giving TIF_MEMDIE only to the main thread and the currently allocating task but that doesn't really solve this problem while it surely opens up a room for corner cases - e.g. GFP_NO{FS,IO} requests might loop inside the allocator without access to memory reserves because a particular thread was not the group leader.
Now that we have the oom reaper and that all oom victims are reapable (after "oom, oom_reaper: allow to reap mm shared by the kthreads") we can be more conservative and grant only partial access to memory reserves because there are reasonable chances of the parallel memory freeing. We still want some access to reserves because we do not want other consumers to eat up the victim's freed memory. oom victims will still contend with __GFP_HIGH users but those shouldn't be so aggressive to starve oom victims completely.
Introduce ALLOC_OOM flag and give all tsk_is_oom_victim tasks access to the half of the reserves. This makes the access to reserves independent on which task has passed through mark_oom_victim. Also drop any usage of TIF_MEMDIE from the page allocator proper and replace it by tsk_is_oom_victim as well which will make page_alloc.c completely TIF_MEMDIE free finally.
CONFIG_MMU=n doesn't have oom reaper so let's stick to the original ALLOC_NO_WATERMARKS approach but be careful because they still might deplete all the memory reserves so keep the semantic as close to the original implementation as possible and give them access to memory reserves only up to exit_mm (when tsk->mm is cleared) rather than while tsk_is_oom_victim which is until signal struct is gone.
--- mm/internal.h | 11 +++++++++++ mm/oom_kill.c | 9 +++++---- mm/page_alloc.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 62 insertions(+), 15 deletions(-)
mm/internal.h +11 -0
@@ -460,6 +460,17 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,/* Mask to get the watermark bits */ #define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1) +/* +* Only MMU archs have async oom victim reclaim - aka oom_reaper so we +* cannot assume a reduced access to memory reserves is sufficient for +* !MMU +*/ +#ifdef CONFIG_MMU +#define ALLOC_OOM 0x08 +#else +#define ALLOC_OOM ALLOC_NO_WATERMARKS +#endif +#define ALLOC_HARDER 0x10/* try to alloc harder */ #define ALLOC_HIGH 0x20/* __GFP_HIGH set */ #define ALLOC_CPUSET 0x40/* check for correct cpuset */
mm/oom_kill.c +5 -4
@@ -816,7 +816,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)/* * If the task is already exiting, don't alarm the sysadmin or kill -* its children or threads, just set TIF_MEMDIE so it can die quickly +* its children or threads, just give it access to memory reserves +* so it can die quickly */ task_lock (p);if (task_will_free_mem (p)) {
@@ -876,9 +877,9 @@ static void oom_kill_process(struct oom_control *oc, const char *message) mm = victim->mm;atomic_inc (&mm->mm_count);/* -* We should send SIGKILL before setting TIF_MEMDIE in order to prevent -* the OOM victim from depleting the memory reserves from the user -* space under its control. +* We should send SIGKILL before granting access to memory reserves +* in order to prevent the OOM victim from depleting the memory +* reserves from the user space under its control. */ do_send_sig_info (SIGKILL ,SEND_SIG_FORCED , victim, true);mark_oom_victim (victim);
mm/page_alloc.c +46 -11
112 lines not on this page · raw message
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
maintainerRFC 2/4 mm: replace TIF_MEMDIE checks by tsk_is_oom_victim
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
TIF_MEMDIE is set only to the tasks whick were either directly selected by the OOM killer or passed through mark_oom_victim from the allocator path. tsk_is_oom_victim is more generic and allows to identify all tasks (threads) which share the mm with the oom victim.
--- kernel/cpuset.c | 9 +++++---- mm/memcontrol.c | 2 +- mm/oom_kill.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-)
kernel/cpuset.c +5 -4
@@ -54,6 +54,7 @@#include <linux/time64.h> #include <linux/backing-dev.h> #include <linux/sort.h> +#include <linux/oom.h> #include <asm/uaccess.h> #include <linux/atomic.h>
@@ -2487,12 +2488,12 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs)* If we're in interrupt, yes, we can always allocate. If @node is set in * current's mems_allowed, yes. If it's not a __GFP_HARDWALL request and this * node is set in the nearest hardwalled cpuset ancestor to current's cpuset, -* yes. If current has access to memory reserves due to TIF_MEMDIE, yes. +* yes. If current has access to memory reserves as an oom victim, yes. * Otherwise, no. * * GFP_USER allocations are marked with the __GFP_HARDWALL bit, * and do not allow allocations outside the current tasks cpuset -* unless the task has been OOM killed as is marked TIF_MEMDIE. +* unless the task has been OOM killed. * GFP_KERNEL allocations are not so marked, so can escape to the * nearest enclosing hardwalled ancestor cpuset. *
@@ -2515,7 +2516,7 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs)* affect that: * in_interrupt - any node ok (current task context irrelevant) * GFP_ATOMIC - any node ok -* TIF_MEMDIE - any node ok +* tsk_is_oom_victim - any node ok * GFP_KERNEL - any node in enclosing hardwalled cpuset ok * GFP_USER - only nodes in current tasks mems allowed ok. */
@@ -2533,7 +2534,7 @@ bool __cpuset_node_allowed(int node, gfp_t gfp_mask)* Allow tasks that have access to memory reserves because they have * been OOM killed to get memory anywhere. */ -if (unlikely (test_thread_flag (TIF_MEMDIE ))) +if (unlikely (tsk_is_oom_victim (current)))return true;if (gfp_mask & __GFP_HARDWALL)/* If hardwall request, stop here */ return false;
mm/memcontrol.c +1 -1
@@ -1899,7 +1899,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 (test_thread_flag (TIF_MEMDIE ) || +if (unlikely (tsk_is_oom_victim (current) ||fatal_signal_pending (current) || current->flags &PF_EXITING )) goto force;
mm/oom_kill.c +2 -2
@@ -477,7 +477,7 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)* [...] * out_of_memory * select_bad_process -* # no TIF_MEMDIE task selects new victim +* # no oom victim, selects new victim * unmap_page_range # frees some memory */ mutex_lock (&oom_lock);
@@ -1078,7 +1078,7 @@ void pagefault_out_of_memory(void)* be a racing OOM victim for which oom_killer_disable() * is waiting for. */ -WARN_ON (test_thread_flag (TIF_MEMDIE )); +WARN_ON (tsk_is_oom_victim (current)); }mutex_unlock (&oom_lock);
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
maintainerRFC 3/4 mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
mark_oom_victim and exit_oom_victim are used for oom_killer_disable which should block as long as there any any oom victims alive. Up to now we have relied on TIF_MEMDIE task flag to count how many oom victim we have. This is not optimal because only one thread receives this flag at the time while the whole process (thread group) is killed and should die. As a result we do not thaw the whole thread group and so a multi threaded process can leave some threads behind in the fridge. We really want to thaw all the threads.
This is not all that easy because there is no reliable way to count threads in the process as the oom killer might race with copy_process. So marking all threads with TIF_MEMDIE and increment oom_victims accordingly is not safe. Also TIF_MEMDIE flag should just die so we should better come up with a different approach.
All we need to guarantee is that exit_oom_victim is called at the time when no further access to (possibly suspended) devices or generate other IO (which would clobber suspended image and only once per process) is possible. It seems we can rely on exit_notify for that because we already have to detect the last thread to do a cleanup. Let's propagate that information up to do_exit and only call exit_oom_victim for such a thread. With this in place we can safely increment oom_victims only once per thread group and thaw all the threads from the process. freezing_slow_path can also rely on tsk_is_oom_victim as well now.
exit_io_context is currently called after exit_notify but it seems it is safe to call it right before exit_notify because that is passed exit_files.
--- include/linux/sched.h | 2 +- kernel/exit.c | 38 ++++++++++++++++++++++++++++---------- kernel/freezer.c | 3 ++- mm/oom_kill.c | 29 +++++++++++++++++------------ 4 files changed, 48 insertions(+), 24 deletions(-)
include/linux/sched.h +1 -1
@@ -2660,7 +2660,7 @@ static inline void kernel_signal_stop(void)schedule (); } -extern void release_task (struct task_struct * p); +extern bool release_task (struct task_struct * p);extern int send_sig_info (int ,struct siginfo *,struct task_struct *);extern int force_sigsegv (int ,struct task_struct *);extern int force_sig_info (int ,struct siginfo *,struct task_struct *);
kernel/exit.c +28 -10
@@ -165,10 +165,11 @@ static void delayed_put_task_struct(struct rcu_head *rhp) } -void release_task (struct task_struct *p) +bool release_task (struct task_struct *p) {struct task_struct *leader;int zap_leader; +bool last = false; repeat:/* don't need to get the RCU readlock here - the process is dead and * can't be modifying its own credentials. But shut RCU-lockdep up */
@@ -197,8 +198,10 @@ void release_task(struct task_struct *p)* then we are the one who should release the leader. */ zap_leader =do_notify_parent (leader, leader->exit_signal); -if (zap_leader) +if (zap_leader) { leader->exit_state =EXIT_DEAD ; + last = true; + } }write_unlock_irq (&tasklist_lock);
@@ -208,6 +211,8 @@ void release_task(struct task_struct *p) p = leader;if (unlikely (zap_leader)) goto repeat; + +return last; }/*
@@ -434,8 +439,6 @@ static void exit_mm(struct task_struct *tsk)task_unlock (tsk);mm_update_next_owner (mm);mmput (mm); -if (test_thread_flag (TIF_MEMDIE )) -exit_oom_victim (); }static struct task_struct *find_alive_thread (struct task_struct *p)
@@ -584,12 +587,15 @@ static void forget_original_parent(struct task_struct *father,/* * Send signals to all our closest relatives so that they know * to properly mourn us.. +* +* Returns true if this is the last thread from the thread group */ -static void exit_notify (struct task_struct *tsk,int group_dead) +static bool exit_notify (struct task_struct *tsk,int group_dead) {bool autoreap;struct task_struct *p, *n;LIST_HEAD (dead); +bool last = false;write_lock_irq (&tasklist_lock);forget_original_parent (tsk, &dead);
@@ -606,6 +612,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead) }else if (thread_group_leader (tsk)) { autoreap =thread_group_empty (tsk) &&do_notify_parent (tsk, tsk->exit_signal); + last =thread_group_empty (tsk); }else { autoreap = true; }
@@ -621,8 +628,11 @@ static void exit_notify(struct task_struct *tsk, int group_dead)list_for_each_entry_safe (p, n, &dead, ptrace_entry) {list_del_init (&p->ptrace_entry); -release_task (p); +if (release_task (p) && p == tsk) + last = true; } + +return last; }#ifdef CONFIG_DEBUG_STACK_USAGE
@@ -766,7 +776,18 @@ void do_exit(long code)TASKS_RCU (preempt_disable ());TASKS_RCU (tasks_rcu_i =__srcu_read_lock (&tasks_rcu_exit_srcu));TASKS_RCU (preempt_enable ()); -exit_notify (tsk, group_dead); + +if (tsk->io_context) +exit_io_context (tsk); + +/* +* Notify oom_killer_disable that the last oom thread is exiting. +* We might have more threads running at this point but none of them +* will access any devices behind this point. +*/ +if (exit_notify (tsk, group_dead) &&tsk_is_oom_victim (current)) +exit_oom_victim (); +proc_exit_connector (tsk);mpol_put_task_policy (tsk);#ifdef CONFIG_FUTEX
@@ -784,9 +805,6 @@ void do_exit(long code)*/ tsk->flags |=PF_EXITPIDONE ; -if (tsk->io_context) -exit_io_context (tsk); -if (tsk->splice_pipe)free_pipe_info (tsk->splice_pipe);
kernel/freezer.c +2 -1
@@ -10,6 +10,7 @@#include <linux/syscalls.h> #include <linux/freezer.h> #include <linux/kthread.h> +#include <linux/oom.h> /* total number of freezing conditions in effect */ atomic_t system_freezing_cnt =ATOMIC_INIT (0 );
@@ -42,7 +43,7 @@ bool freezing_slow_path(struct task_struct *p)if (p->flags & (PF_NOFREEZE |PF_SUSPEND_TASK ))return false; -if (test_tsk_thread_flag (p,TIF_MEMDIE )) +if (tsk_is_oom_victim (p))return false;if (pm_nosig_freezing ||cgroup_freezing (p))
mm/oom_kill.c +17 -12
@@ -649,33 +649,38 @@ static inline void wake_oom_reaper(struct task_struct *tsk)static void mark_oom_victim (struct task_struct *tsk) {struct mm_struct *mm = tsk->mm; +struct task_struct *t;WARN_ON (oom_killer_disabled); -/* OOM killer might race with memcg OOM */ -if (test_and_set_tsk_thread_flag (tsk,TIF_MEMDIE )) -return ;/* oom_mm is bound to the signal struct life time. */ -if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) +if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) {atomic_inc (&tsk->signal->oom_mm->mm_count); +/* Only count thread groups */ +atomic_inc (&oom_victims); + } +/* -* Make sure that the task is woken up from uninterruptible sleep -* if it is frozen because OOM killer wouldn't be able to free -* any memory and livelock. freezing_slow_path will tell the freezer -* that TIF_MEMDIE tasks should be ignored. +* Make sure that the the whole thread groupd is woken up from +* uninterruptible sleep if it is frozen because the oom victim +* will free its memory completely only after exit. +* freezing_slow_path will tell the freezer that oom victims +* should be ignored. */ -__thaw_task (tsk); -atomic_inc (&oom_victims); +rcu_read_lock (); +for_each_thread (tsk, t) +__thaw_task (t); +rcu_read_unlock (); }/** * exit_oom_victim - note the exit of an OOM victim +* +* Has to be called only once per thread group. */ void exit_oom_victim (void ) { -clear_thread_flag (TIF_MEMDIE ); -if (!atomic_dec_return (&oom_victims))wake_up_all (&oom_victims_wait); }
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
maintainerRFC 4/4 arch: get rid of TIF_MEMDIE
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
nobody relies on the flag so make it go away.
--- arch/alpha/include/asm/thread_info.h | 1 - arch/arc/include/asm/thread_info.h | 2 -- arch/arm/include/asm/thread_info.h | 1 - arch/arm64/include/asm/thread_info.h | 1 - arch/avr32/include/asm/thread_info.h | 2 -- arch/blackfin/include/asm/thread_info.h | 1 - arch/c6x/include/asm/thread_info.h | 1 - arch/cris/include/asm/thread_info.h | 1 - arch/frv/include/asm/thread_info.h | 1 - arch/h8300/include/asm/thread_info.h | 1 - arch/hexagon/include/asm/thread_info.h | 1 - arch/ia64/include/asm/thread_info.h | 1 - arch/m32r/include/asm/thread_info.h | 1 - arch/m68k/include/asm/thread_info.h | 1 - arch/metag/include/asm/thread_info.h | 1 - arch/microblaze/include/asm/thread_info.h | 1 - arch/mips/include/asm/thread_info.h | 1 - arch/mn10300/include/asm/thread_info.h | 1 - arch/nios2/include/asm/thread_info.h | 1 - arch/openrisc/include/asm/thread_info.h | 1 - arch/parisc/include/asm/thread_info.h | 1 - arch/powerpc/include/asm/thread_info.h | 1 - arch/s390/include/asm/thread_info.h | 1 - arch/score/include/asm/thread_info.h | 1 - arch/sh/include/asm/thread_info.h | 1 - arch/sparc/include/asm/thread_info_32.h | 1 - arch/sparc/include/asm/thread_info_64.h | 1 - arch/tile/include/asm/thread_info.h | 2 -- arch/um/include/asm/thread_info.h | 2 -- arch/unicore32/include/asm/thread_info.h | 1 - arch/x86/include/asm/thread_info.h | 1 - arch/xtensa/include/asm/thread_info.h | 1 - 32 files changed, 36 deletions(-)
arch/alpha/include/asm/thread_info.h +0 -1
@@ -65,7 +65,6 @@ register struct thread_info *__current_thread_info __asm__("$8");#define TIF_NEED_RESCHED 3/* rescheduling necessary */ #define TIF_SYSCALL_AUDIT 4/* syscall audit active */ #define TIF_DIE_IF_KERNEL 9/* dik recursion lock */ -#define TIF_MEMDIE 13/* is terminating due to OOM killer */ #define TIF_POLLING_NRFLAG 14/* idle is polling for TIF_NEED_RESCHED */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
arch/arc/include/asm/thread_info.h +0 -2
@@ -88,14 +88,12 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)#define TIF_SYSCALL_TRACE 15/* syscall trace active */ /* true if poll_idle() is polling TIF_NEED_RESCHED */ -#define TIF_MEMDIE 16#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT) -#define _TIF_MEMDIE (1<<TIF_MEMDIE)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
arch/arm/include/asm/thread_info.h +0 -1
@@ -146,7 +146,6 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,#define TIF_NOHZ 12/* in adaptive nohz mode */ #define TIF_USING_IWMMXT 17 -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 20#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
arch/arm64/include/asm/thread_info.h +0 -1
@@ -114,7 +114,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SYSCALL_AUDIT 9#define TIF_SYSCALL_TRACEPOINT 10#define TIF_SECCOMP 11 -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define TIF_FREEZE 19#define TIF_RESTORE_SIGMASK 20#define TIF_SINGLESTEP 21
arch/avr32/include/asm/thread_info.h +0 -2
@@ -70,7 +70,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_BREAKPOINT 4/* enter monitor mode on return */ #define TIF_SINGLE_STEP 5/* single step in progress */ -#define TIF_MEMDIE 6/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 7/* restore signal mask in do_signal */ #define TIF_CPU_GOING_TO_SLEEP 8/* CPU is entering sleep 0 mode */ #define TIF_NOTIFY_RESUME 9/* callback before returning to user */
@@ -82,7 +81,6 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)#define _TIF_BREAKPOINT (1 << TIF_BREAKPOINT)#define _TIF_SINGLE_STEP (1 << TIF_SINGLE_STEP) -#define _TIF_MEMDIE (1 << TIF_MEMDIE)#define _TIF_CPU_GOING_TO_SLEEP (1 << TIF_CPU_GOING_TO_SLEEP)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
arch/blackfin/include/asm/thread_info.h +0 -1
@@ -79,7 +79,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SYSCALL_TRACE 0/* syscall trace active */ #define TIF_SIGPENDING 1/* signal pending */ #define TIF_NEED_RESCHED 2/* rescheduling necessary */ -#define TIF_MEMDIE 4/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 5/* restore signal mask in do_signal() */ #define TIF_IRQ_SYNC 7/* sync pipeline stage */ #define TIF_NOTIFY_RESUME 8/* callback before returning to user */
arch/c6x/include/asm/thread_info.h +0 -1
@@ -89,7 +89,6 @@ struct thread_info *current_thread_info(void)#define TIF_NEED_RESCHED 3/* rescheduling necessary */ #define TIF_RESTORE_SIGMASK 4/* restore signal mask in do_signal() */ -#define TIF_MEMDIE 17/* OOM killer killed process */ #define TIF_WORK_MASK 0x00007FFE/* work on irq/exception return */ #define TIF_ALLWORK_MASK 0x00007FFF/* work on any return to u-space */
arch/cris/include/asm/thread_info.h +0 -1
@@ -70,7 +70,6 @@ struct thread_info {#define TIF_SIGPENDING 2/* signal pending */ #define TIF_NEED_RESCHED 3/* rescheduling necessary */ #define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal() */ -#define TIF_MEMDIE 17/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
arch/frv/include/asm/thread_info.h +0 -1
@@ -86,7 +86,6 @@ register struct thread_info *__current_thread_info asm("gr15");#define TIF_NEED_RESCHED 3/* rescheduling necessary */ #define TIF_SINGLESTEP 4/* restore singlestep on return to user mode */ #define TIF_RESTORE_SIGMASK 5/* restore signal mask in do_signal() */ -#define TIF_MEMDIE 7/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
arch/h8300/include/asm/thread_info.h +0 -1
@@ -73,7 +73,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SIGPENDING 1/* signal pending */ #define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_SINGLESTEP 3/* singlestepping active */ -#define TIF_MEMDIE 4/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 5/* restore signal mask in do_signal() */ #define TIF_NOTIFY_RESUME 6/* callback before returning to user */ #define TIF_SYSCALL_AUDIT 7/* syscall auditing active */
arch/hexagon/include/asm/thread_info.h +0 -1
@@ -112,7 +112,6 @@ register struct thread_info *__current_thread_info asm(QUOTED_THREADINFO_REG);#define TIF_SINGLESTEP 4/* restore ss @ return to usr mode */ #define TIF_RESTORE_SIGMASK 6/* restore sig mask in do_signal() */ /* true if poll_idle() is polling TIF_NEED_RESCHED */ -#define TIF_MEMDIE 17/* OOM killer killed process */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
arch/ia64/include/asm/thread_info.h +0 -1
@@ -97,7 +97,6 @@ struct thread_info {#define TIF_SYSCALL_AUDIT 3/* syscall auditing active */ #define TIF_SINGLESTEP 4/* restore singlestep on return to user mode */ #define TIF_NOTIFY_RESUME 6/* resumption notification requested */ -#define TIF_MEMDIE 17/* is terminating due to OOM killer */ #define TIF_MCA_INIT 18/* this task is processing MCA or INIT */ #define TIF_DB_DISABLED 19/* debug trap disabled for fsyscall */ #define TIF_RESTORE_RSE 21/* user RBS is newer than kernel RBS */
arch/m32r/include/asm/thread_info.h +0 -1
@@ -102,7 +102,6 @@ static inline unsigned int get_thread_fault_code(void)#define TIF_NOTIFY_RESUME 5/* callback before returning to user */ #define TIF_RESTORE_SIGMASK 8/* restore signal mask in do_signal() */ #define TIF_USEDFPU 16/* FPU was used by this task this quantum (SMP) */ -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
arch/m68k/include/asm/thread_info.h +0 -1
@@ -68,7 +68,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_NEED_RESCHED 7/* rescheduling necessary */ #define TIF_DELAYED_TRACE 14/* single step a syscall */ #define TIF_SYSCALL_TRACE 15/* syscall trace active */ -#define TIF_MEMDIE 16/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 18/* restore signal mask in do_signal */ #endif /* _ASM_M68K_THREAD_INFO_H */
arch/metag/include/asm/thread_info.h +0 -1
@@ -111,7 +111,6 @@ static inline int kstack_end(void *addr)#define TIF_SECCOMP 5/* secure computing */ #define TIF_RESTORE_SIGMASK 6/* restore signal mask in do_signal() */ #define TIF_NOTIFY_RESUME 7/* callback before returning to user */ -#define TIF_MEMDIE 8/* is terminating due to OOM killer */ #define TIF_SYSCALL_TRACEPOINT 9/* syscall tracepoint instrumentation */
arch/microblaze/include/asm/thread_info.h +0 -1
@@ -113,7 +113,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_NEED_RESCHED 3/* rescheduling necessary */ /* restore singlestep on return to user mode */ #define TIF_SINGLESTEP 4 -#define TIF_MEMDIE 6/* is terminating due to OOM killer */ #define TIF_SYSCALL_AUDIT 9/* syscall auditing active */ #define TIF_SECCOMP 10/* secure computing */
arch/mips/include/asm/thread_info.h +0 -1
@@ -102,7 +102,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_UPROBE 6/* breakpointed or singlestepping */ #define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal() */ #define TIF_USEDFPU 16/* FPU was used by this task this quantum (SMP) */ -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define TIF_NOHZ 19/* in adaptive nohz mode */ #define TIF_FIXADE 20/* Fix address errors in software */ #define TIF_LOGADE 21/* Log address errors to syslog */
arch/mn10300/include/asm/thread_info.h +0 -1
@@ -145,7 +145,6 @@ void arch_release_thread_stack(unsigned long *stack);#define TIF_SINGLESTEP 4/* restore singlestep on return to user mode */ #define TIF_RESTORE_SIGMASK 5/* restore signal mask in do_signal() */ #define TIF_POLLING_NRFLAG 16/* true if poll_idle() is polling TIF_NEED_RESCHED */ -#define TIF_MEMDIE 17/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE +(1 << TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME +(1 << TIF_NOTIFY_RESUME)
arch/nios2/include/asm/thread_info.h +0 -1
@@ -86,7 +86,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_NOTIFY_RESUME 1/* resumption notification requested */ #define TIF_SIGPENDING 2/* signal pending */ #define TIF_NEED_RESCHED 3/* rescheduling necessary */ -#define TIF_MEMDIE 4/* is terminating due to OOM killer */ #define TIF_SECCOMP 5/* secure computing */ #define TIF_SYSCALL_AUDIT 6/* syscall auditing active */ #define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal() */
arch/openrisc/include/asm/thread_info.h +0 -1
@@ -108,7 +108,6 @@ register struct thread_info *current_thread_info_reg asm("r10");#define TIF_RESTORE_SIGMASK 9#define TIF_POLLING_NRFLAG 16/* true if poll_idle() is polling * TIF_NEED_RESCHED */ -#define TIF_MEMDIE 17#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
arch/parisc/include/asm/thread_info.h +0 -1
@@ -48,7 +48,6 @@ struct thread_info {#define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_POLLING_NRFLAG 3/* true if poll_idle() is polling TIF_NEED_RESCHED */ #define TIF_32BIT 4/* 32 bit binary */ -#define TIF_MEMDIE 5/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 6/* restore saved signal mask */ #define TIF_SYSCALL_AUDIT 7/* syscall auditing active */ #define TIF_NOTIFY_RESUME 8/* callback before returning to user */
arch/powerpc/include/asm/thread_info.h +0 -1
@@ -99,7 +99,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SYSCALL_TRACEPOINT 15/* syscall tracepoint instrumentation */ #define TIF_EMULATE_STACK_STORE 16/* Is an instruction emulation for stack store? */ -#define TIF_MEMDIE 17/* is terminating due to OOM killer */ #if defined(CONFIG_PPC64 )#define TIF_ELF2ABI 18/* function descriptors must die! */ #endif
arch/s390/include/asm/thread_info.h +0 -1
@@ -80,7 +80,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);#define TIF_SYSCALL_TRACEPOINT 6/* syscall tracepoint instrumentation */ #define TIF_UPROBE 7/* breakpointed or single-stepping */ #define TIF_31BIT 16/* 32bit process */ -#define TIF_MEMDIE 17/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 18/* restore signal mask in do_signal() */ #define TIF_SINGLE_STEP 19/* This task is single stepped */ #define TIF_BLOCK_STEP 20/* This task is block stepped */
arch/score/include/asm/thread_info.h +0 -1
@@ -78,7 +78,6 @@ register struct thread_info *__current_thread_info __asm__("r28");#define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_NOTIFY_RESUME 5/* callback before returning to user */ #define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal() */ -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
arch/sh/include/asm/thread_info.h +0 -1
@@ -117,7 +117,6 @@ extern void init_thread_xstate(void);#define TIF_NOTIFY_RESUME 7/* callback before returning to user */ #define TIF_SYSCALL_TRACEPOINT 8/* for ftrace syscall instrumentation */ #define TIF_POLLING_NRFLAG 17/* true if poll_idle() is polling TIF_NEED_RESCHED */ -#define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
arch/sparc/include/asm/thread_info_32.h +0 -1
@@ -110,7 +110,6 @@ register struct thread_info *current_thread_info_reg asm("g6");* this quantum (SMP) */ #define TIF_POLLING_NRFLAG 9/* true if poll_idle() is polling * TIF_NEED_RESCHED */ -#define TIF_MEMDIE 10/* is terminating due to OOM killer */ /* as above, but as bit values */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
arch/sparc/include/asm/thread_info_64.h +0 -1
@@ -191,7 +191,6 @@ register struct thread_info *current_thread_info_reg asm("g6");* an immediate value in instructions such as andcc. */ /* flag bit 12 is available */ -#define TIF_MEMDIE 13/* is terminating due to OOM killer */ #define TIF_POLLING_NRFLAG 14#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
arch/tile/include/asm/thread_info.h +0 -2
@@ -121,7 +121,6 @@ extern void _cpu_idle(void);#define TIF_SYSCALL_TRACE 4/* syscall trace active */ #define TIF_SYSCALL_AUDIT 5/* syscall auditing active */ #define TIF_SECCOMP 6/* secure computing */ -#define TIF_MEMDIE 7/* OOM killer at work */ #define TIF_NOTIFY_RESUME 8/* callback before returning to user */ #define TIF_SYSCALL_TRACEPOINT 9/* syscall tracepoint instrumentation */ #define TIF_POLLING_NRFLAG 10/* idle is polling for TIF_NEED_RESCHED */
@@ -134,7 +133,6 @@ extern void _cpu_idle(void);#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)#define _TIF_SECCOMP (1<<TIF_SECCOMP) -#define _TIF_MEMDIE (1<<TIF_MEMDIE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
arch/um/include/asm/thread_info.h +0 -2
@@ -58,7 +58,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SIGPENDING 1/* signal pending */ #define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_RESTART_BLOCK 4 -#define TIF_MEMDIE 5/* is terminating due to OOM killer */ #define TIF_SYSCALL_AUDIT 6#define TIF_RESTORE_SIGMASK 7#define TIF_NOTIFY_RESUME 8
@@ -67,7 +66,6 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) -#define _TIF_MEMDIE (1 << TIF_MEMDIE)#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)#define _TIF_SECCOMP (1 << TIF_SECCOMP)
arch/unicore32/include/asm/thread_info.h +0 -1
@@ -121,7 +121,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_NEED_RESCHED 1#define TIF_NOTIFY_RESUME 2/* callback before returning to user */ #define TIF_SYSCALL_TRACE 8 -#define TIF_MEMDIE 18#define TIF_RESTORE_SIGMASK 20#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
arch/x86/include/asm/thread_info.h +0 -1
@@ -97,7 +97,6 @@ struct thread_info {#define TIF_IA32 17/* IA32 compatibility process */ #define TIF_FORK 18/* ret_from_fork */ #define TIF_NOHZ 19/* in adaptive nohz mode */ -#define TIF_MEMDIE 20/* is terminating due to OOM killer */ #define TIF_POLLING_NRFLAG 21/* idle is polling for TIF_NEED_RESCHED */ #define TIF_IO_BITMAP 22/* uses I/O bitmap */ #define TIF_FORCED_TF 24/* true if TF in eflags artificially */
arch/xtensa/include/asm/thread_info.h +0 -1
@@ -108,7 +108,6 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SIGPENDING 1/* signal pending */ #define TIF_NEED_RESCHED 2/* rescheduling necessary */ #define TIF_SINGLESTEP 3/* restore singlestep on return to user mode */ -#define TIF_MEMDIE 5/* is terminating due to OOM killer */ #define TIF_RESTORE_SIGMASK 6/* restore signal mask in do_signal() */ #define TIF_NOTIFY_RESUME 7/* callback before returning to user */ #define TIF_DB_DISABLED 8/* debug trap disabled for syscall */
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 1/4] mm, oom: do not rely on TIF_MEMDIE for memory reserves access
In reply to Michal HockoQuoted 11 lines · Michal Hocko
mm/oom_kill.c +2
-1@@ -816,7 +816,8 @@ static void oom_kill_process(struct oom_control *oc, const char *message)/* * If the task is already exiting, don't alarm the sysadmin or kill -* its children or threads, just set TIF_MEMDIE so it can die quickly +* its children or threads, just give it access to memory reserves +* so it can die quickly */ task_lock (p);if (task_will_free_mem (p)) {
mm/oom_kill.c static void oom_kill_process(struct oom_control *oc, const char *message) · line 883
Quoted 10 lines
mm/oom_kill.c +3
-3@@ -876,9 +877,9 @@ static void oom_kill_process(struct oom_control *oc, const char *message) mm = victim->mm;atomic_inc (&mm->mm_count);/* -* We should send SIGKILL before setting TIF_MEMDIE in order to prevent -* the OOM victim from depleting the memory reserves from the user -* space under its control. +* We should send SIGKILL before granting access to memory reserves +* in order to prevent the OOM victim from depleting the memory +* reserves from the user space under its control. */
Removing TIF_MEMDIE usage inside comments can be done as a clean up before this series.
Quoted 10 lines
mm/page_alloc.c +6
-0@@ -3309,6 +3318,22 @@ gfp_to_alloc_flags(gfp_t gfp_mask)return alloc_flags; } +static bool oom_reserves_allowed (struct task_struct *tsk) +{ +if (!tsk_is_oom_victim (tsk)) +return false; + +/*
mm/page_alloc.c gfp_to_alloc_flags(gfp_t gfp_mask) · line 3336
Quoted 10 lines
mm/page_alloc.c +10
-0+* !MMU doesn't have oom reaper so we shouldn't risk the memory reserves +* depletion and shouldn't give access to memory reserves passed the +* exit_mm +*/ +if (!IS_ENABLED (CONFIG_MMU ) && !tsk->mm) +return false; + +return true; +} +
Are you aware that you are trying to make !MMU kernel's allocations not only after returning exit_mm() but also from __mmput() from mmput() from exit_mm() fail without allowing access to memory reserves? The comment says only after returning exit_mm(), but this change is not.
mm/page_alloc.c __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, · line 3598
Quoted 9 lines
mm/page_alloc.c +2
-2@@ -3558,8 +3593,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, goto nopage; } -/* Avoid allocations with no watermarks from looping endlessly */ -if (test_thread_flag (TIF_MEMDIE ) && !(gfp_mask & __GFP_NOFAIL)) +/* Avoid allocations for oom victims from looping endlessly */ +if (tsk_is_oom_victim (current) && !(gfp_mask & __GFP_NOFAIL)) goto nopage;
This change increases possibility of giving up without trying ALLOC_OOM (more allocation failure messages), for currently only one thread which remotely got TIF_MEMDIE when it was between gfp_to_alloc_flags() and test_thread_flag(TIF_MEMDIE) will give up without trying ALLOC_NO_WATERMARKS while all threads which remotely got current->signal->oom_mm when they were between gfp_to_alloc_flags() and test_thread_flag(TIF_MEMDIE) will give up without trying ALLOC_OOM. I think we should make sure that ALLOC_OOM is tried (by using a variable which remembers whether get_page_from_freelist(ALLOC_OOM) was tried).
We are currently allowing TIF_MEMDIE threads try ALLOC_NO_WATERMARKS for once and give up without invoking the OOM killer. This change makes current->signal->oom_mm threads try ALLOC_OOM for once and give up without invoking the OOM killer. This means that allocations for cleanly cleaning up by oom victims might fail prematurely, but we don't want to scatter around __GFP_NOFAIL. Since there are reasonable chances of the parallel memory freeing, we don't need to give up without invoking the OOM killer again. I think that
- /* Avoid allocations with no watermarks from looping endlessly */
- if (test_thread_flag(TIF_MEMDIE) && !(gfp_mask & __GFP_NOFAIL))
+#ifndef CONFIG_MMU
+ /* Avoid allocations for oom victims from looping endlessly */
+ if (tsk_is_oom_victim(current) && !(gfp_mask & __GFP_NOFAIL))
+ goto nopage;
+#endif
is possible.
--
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>
Re: [RFC 2/4] mm: replace TIF_MEMDIE checks by tsk_is_oom_victim
In reply to Michal Hockomm/memcontrol.c static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, · line 1905
Quoted 13 lines · Michal Hocko
mm/memcontrol.c +1
-1@@ -1899,7 +1899,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 (test_thread_flag (TIF_MEMDIE ) || +if (unlikely (tsk_is_oom_victim (current) ||fatal_signal_pending (current) || current->flags &PF_EXITING )) goto force;
Does this test_thread_flag(TIF_MEMDIE) (or tsk_is_oom_victim(current)) make sense?
If current thread is OOM-killed, SIGKILL must be pending before arriving at do_exit() and PF_EXITING must be set after arriving at do_exit(). But I can't find locations which do memory allocation between clearing SIGKILL and setting PF_EXITING.
When can test_thread_flag(TIF_MEMDIE) == T (or tsk_is_oom_victim(current) == T) && fatal_signal_pending(current) == F && (current->flags & PF_EXITING) == 0 happen?
mm/oom_kill.c void pagefault_out_of_memory(void) · line 1084
Quoted 13 lines
mm/oom_kill.c +1
-1@@ -1078,7 +1078,7 @@ void pagefault_out_of_memory(void)* be a racing OOM victim for which oom_killer_disable() * is waiting for. */ -WARN_ON (test_thread_flag (TIF_MEMDIE )); +WARN_ON (tsk_is_oom_victim (current)); }mutex_unlock (&oom_lock);
Does this WARN_ON() make sense?
When some user thread called oom_killer_disable(), there are running kernel threads but is no running user threads except the one which called oom_killer_disable(). Since oom_killer_disable() waits for oom_lock, out_of_memory() called from here shall not return false before oom_killer_disable() sets oom_killer_disabled = true. Thus, possible situation out_of_memory() called from here can return false are limited to
(a) the one which triggered pagefaults after returning from oom_killer_disable()
(b) An OOM victim which was thawed triggered pagefaults from do_exit() after the one which called oom_killer_disable() released oom_lock
(c) kernel threads which triggered pagefaults after use_mm()
. And since kernel threads are not subjected to mark_oom_victim(), test_thread_flag(TIF_MEMDIE) == F (or tsk_is_oom_victim(current) == F) for kernel threads. Thus, possible situation out_of_memory() called from here can return false and we hit this WARN_ON() is limited to (b).
Even if (a) or (b) is possible, does continuously emitting backtraces help? It seems to me that the system is under OOM livelock situation and we need to take a different action (e.g. try to allocate a page using ALLOC_NO_WATERMARKS in order to make the pagefault be solved, and panic() if failed) than emitting same backtraces forever.
--
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>
Re: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
In reply to Michal HockoQuoted 11 lines · Michal Hocko
mark_oom_victimandexit_oom_victimare used foroom_killer_disablewhich should block as long as there any any oom victims alive. Up to now we have relied onTIF_MEMDIEtask flag to count how many oom victim we have. This is not optimal because only one thread receives this flag at the time while the whole process (thread group) is killed and should die. As a result we do not thaw the whole thread group and so a multi threaded process can leave some threads behind in the fridge. We really want to thaw all the threads.This is not all that easy because there is no reliable way to count threads in the process as the oom killer might race with
copy_process.
What is wrong with racing with copy_process()? Threads doing copy_process() are not frozen and thus we don't need to thaw such threads. Also, being OOM-killed implies receiving SIGKILL. Thus, newly created thread will also enter do_exit().
Quoted 4 lines
So marking all threads with
TIF_MEMDIEand incrementoom_victimsaccordingly is not safe. AlsoTIF_MEMDIEflag should just die so we should better come up with a different approach.
Quoted 9 lines
All we need to guarantee is that
exit_oom_victimis called at the time when no further access to (possibly suspended) devices or generate other IO (which would clobber suspended image and only once per process) is possible. It seems we can rely onexit_notifyfor that because we already have to detect the last thread to do a cleanup. Let's propagate that information up todo_exitand only callexit_oom_victimfor such a thread. With this in place we can safely incrementoom_victimsonly once per thread group and thaw all the threads from the process.freezing_slow_pathcan also rely ontsk_is_oom_victimas well now.
If marking all threads which belong to tsk thread group with TIF_MEMDIE is not safe (due to possible race with copy_process()), how can
rcu_read_lock(); for_each_thread(tsk, t) __thaw_task(t); rcu_read_unlock();
in mark_oom_victim() guarantee that all threads which belong to tsk thread group are thawed?
Unless all threads which belong to tsk thread group in __refrigerator() are guaranteed to be thawed, they might fail to leave __refrigerator() in order to enter do_exit() which means that exit_oom_victim() won't be called.
Do we want to thaw OOM victims from the beginning? If the freezer depends on CONFIG_MMU=y , we don't need to thaw OOM victims.
--
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>
Michal Hocko
maintainerRe: [RFC 1/4] mm, oom: do not rely on TIF_MEMDIE for memory reserves access
In reply to Tetsuo HandaQuoted 1 line · Tetsuo Handa
Michal Hocko wrote:
[...]
Quoted 16 lines
Quoted 16 lines
mm/page_alloc.c +12
-0@@ -3309,6 +3318,22 @@ gfp_to_alloc_flags(gfp_t gfp_mask)return alloc_flags; } +static bool oom_reserves_allowed (struct task_struct *tsk) +{ +if (!tsk_is_oom_victim (tsk)) +return false; + +/* +* !MMU doesn't have oom reaper so we shouldn't risk the memory reserves +* depletion and shouldn't give access to memory reserves passed the +* exit_mm +*/ +if (!IS_ENABLED (CONFIG_MMU ) && !tsk->mm) +return false;
Quoted 8 lines
mm/page_alloc.c gfp_to_alloc_flags(gfp_t gfp_mask) · line 3336
Quoted 4 lines
mm/page_alloc.c +4
-0+ +return true; +} +Are you aware that you are trying to make !MMU kernel's allocations not only after returning
exit_mm()but also from__mmput()frommmput()fromexit_mm()fail without allowing access to memory reserves?
Do we allocate from that path in !mmu and would that be more broken than with the current code which clears TIF_MEMDIE after mmput even when __mmput is not called (aka somebody is holding a reference to mm - e.g. a proc file)?
Quoted 2 lines
The comment says only after returning
exit_mm(), but this change is not.
I can see that the comment is not ideal. Any suggestion how to make it better?
Quoted 4 lines
Quoted 4 lines
mm/page_alloc.c +0
-0@@ -3558,8 +3593,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, goto nopage; }
Quoted 15 lines
mm/page_alloc.c __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, · line 3598
Quoted 5 lines
mm/page_alloc.c +2
-2-/* Avoid allocations with no watermarks from looping endlessly */ -if (test_thread_flag (TIF_MEMDIE ) && !(gfp_mask & __GFP_NOFAIL)) +/* Avoid allocations for oom victims from looping endlessly */ +if (tsk_is_oom_victim (current) && !(gfp_mask & __GFP_NOFAIL)) goto nopage;This change increases possibility of giving up without trying
ALLOC_OOM(more allocation failure messages), for currently only one thread which remotely gotTIF_MEMDIEwhen it was betweengfp_to_alloc_flags()andtest_thread_flag(TIF_MEMDIE)will give up without tryingALLOC_NO_WATERMARKSwhile all threads which remotely gotcurrent->signal->oom_mmwhen they were betweengfp_to_alloc_flags()andtest_thread_flag(TIF_MEMDIE)will give up without tryingALLOC_OOM. I think we should make sure thatALLOC_OOMis tried (by using a variable which remembers whetherget_page_from_freelist(ALLOC_OOM)was tried).
Technically speaking you are right but I am not really sure that this matters all that much. This code as always been racy. If we ever consider the race harmfull we can reorganize the allo slow path in a way to guarantee at least one allocation attempt with ALLOC_OOM I am just not sure it is necessary right now. If this ever shows up as a problem we would see a flood of allocation failures followed by the OOM report so it would be quite easy to notice.
Quoted 17 lines
We are currently allowing
TIF_MEMDIEthreads tryALLOC_NO_WATERMARKSfor once and give up without invoking the OOM killer. This change makescurrent->signal->oom_mmthreads tryALLOC_OOMfor once and give up without invoking the OOM killer. This means that allocations for cleanly cleaning up by oom victims might fail prematurely, but we don't want to scatter around__GFP_NOFAIL. Since there are reasonable chances of the parallel memory freeing, we don't need to give up without invoking the OOM killer again. I think thatmm/page_alloc.c +5
-2-/* Avoid allocations with no watermarks from looping endlessly */ -if (test_thread_flag (TIF_MEMDIE ) && !(gfp_mask & __GFP_NOFAIL)) +#ifndef CONFIG_MMU +/* Avoid allocations for oom victims from looping endlessly */ +if (tsk_is_oom_victim (current) && !(gfp_mask & __GFP_NOFAIL)) + goto nopage; +#endif
Quoted 1 line
is possible.
I would prefer to not spread out MMU ifdefs all over the place.
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>
Michal Hocko
maintainerRe: [RFC 2/4] mm: replace TIF_MEMDIE checks by tsk_is_oom_victim
In reply to Tetsuo HandaQuoted 17 lines · Tetsuo Handa
mm/memcontrol.c static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, · line 1905
Quoted 13 lines · Michal Hocko
mm/memcontrol.c +1
-1@@ -1899,7 +1899,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 (test_thread_flag (TIF_MEMDIE ) || +if (unlikely (tsk_is_oom_victim (current) ||fatal_signal_pending (current) || current->flags &PF_EXITING )) goto force;Does this
test_thread_flag(TIF_MEMDIE)(ortsk_is_oom_victim(current)) make sense?
Quoted 7 lines
If current thread is OOM-killed, SIGKILL must be pending before arriving at
do_exit()andPF_EXITINGmust be set after arriving atdo_exit(). But I can't find locations which do memory allocation between clearing SIGKILL and settingPF_EXITING.When can
test_thread_flag(TIF_MEMDIE)== T (ortsk_is_oom_victim(current)== T) &&fatal_signal_pending(current)== F && (current->flags&PF_EXITING) == 0 happen?
Maybe you are right. I would have to double check. I am still drown in a pile of emails after vacation so it will take some time to do that. Anyway I believe this would be worth a separate patch. This one just mechanically replaces TIF_MEMDIE check by tsk_is_oom_victim.
Quoted 35 lines
mm/oom_kill.c void pagefault_out_of_memory(void) · line 1084
Quoted 13 lines
mm/oom_kill.c +1
-1@@ -1078,7 +1078,7 @@ void pagefault_out_of_memory(void)* be a racing OOM victim for which oom_killer_disable() * is waiting for. */ -WARN_ON (test_thread_flag (TIF_MEMDIE )); +WARN_ON (tsk_is_oom_victim (current)); }mutex_unlock (&oom_lock);Does this
WARN_ON()make sense?When some user thread called
oom_killer_disable(), there are running kernel threads but is no running user threads except the one which calledoom_killer_disable(). Sinceoom_killer_disable()waits foroom_lock,out_of_memory()called from here shall not return false beforeoom_killer_disable()setsoom_killer_disabled= true. Thus, possible situationout_of_memory()called from here can return false are limited to(a) the one which triggered pagefaults after returning from
oom_killer_disable()
(b) An OOM victim which was thawed triggered pagefaults fromdo_exit()after the one which calledoom_killer_disable()releasedoom_lock
(c) kernel threads which triggered pagefaults afteruse_mm(). And since kernel threads are not subjected to
mark_oom_victim(),test_thread_flag(TIF_MEMDIE)== F (ortsk_is_oom_victim(current)== F) for kernel threads. Thus, possible situationout_of_memory()called from here can return false and we hit thisWARN_ON()is limited to (b).
Quoted 5 lines
Even if (a) or (b) is possible, does continuously emitting backtraces help? It seems to me that the system is under OOM livelock situation and we need to take a different action (e.g. try to allocate a page using
ALLOC_NO_WATERMARKSin order to make the pagefault be solved, andpanic()if failed) than emitting same backtraces forever.
I have to think about this some more, so I cannot give it any answer right now. But again, this is just a mechanical change. If your concern is correct and the WARN_ON is really pointless it should be similarly pointless with the TIF_MEMDIE check unless I am missing something.
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>
Michal Hocko
maintainerRe: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
In reply to Tetsuo HandaQuoted 10 lines · Tetsuo Handa
Quoted 9 lines · Michal Hocko
mark_oom_victimandexit_oom_victimare used foroom_killer_disablewhich should block as long as there any any oom victims alive. Up to now we have relied onTIF_MEMDIEtask flag to count how many oom victim we have. This is not optimal because only one thread receives this flag at the time while the whole process (thread group) is killed and should die. As a result we do not thaw the whole thread group and so a multi threaded process can leave some threads behind in the fridge. We really want to thaw all the threads.
Quoted 7 lines
Quoted 2 lines
This is not all that easy because there is no reliable way to count threads in the process as the oom killer might race with
copy_process.What is wrong with racing with
copy_process()? Threads doingcopy_process()are not frozen and thus we don't need to thaw such threads. Also, being OOM-killed implies receiving SIGKILL. Thus, newly created thread will also enterdo_exit().
The problem is that we cannot rely on signal->nr_threads to know when the last one is passing exit to declare the whole group done and wake the waiter on the oom killer lock.
Quoted 17 lines
Quoted 4 lines
So marking all threads with
TIF_MEMDIEand incrementoom_victimsaccordingly is not safe. AlsoTIF_MEMDIEflag should just die so we should better come up with a different approach.Quoted 9 lines
All we need to guarantee is that
exit_oom_victimis called at the time when no further access to (possibly suspended) devices or generate other IO (which would clobber suspended image and only once per process) is possible. It seems we can rely onexit_notifyfor that because we already have to detect the last thread to do a cleanup. Let's propagate that information up todo_exitand only callexit_oom_victimfor such a thread. With this in place we can safely incrementoom_victimsonly once per thread group and thaw all the threads from the process.freezing_slow_pathcan also rely ontsk_is_oom_victimas well now.If marking all threads which belong to tsk thread group with
TIF_MEMDIEis not safe (due to possible race withcopy_process()), how can
Quoted 7 lines
rcu_read_lock(); for_each_thread(tsk, t) __thaw_task(t); rcu_read_unlock();in
mark_oom_victim()guarantee that all threads which belong to tsk thread group are thawed?
Because all the frozen thread already have to be hashed and those which are in the middle of copy process will be tsk_is_oom_victim and so the freezer will skip them.
Quoted 7 lines
Unless all threads which belong to tsk thread group in
__refrigerator()are guaranteed to be thawed, they might fail to leave__refrigerator()in order to enterdo_exit()which means thatexit_oom_victim()won't be called.Do we want to thaw OOM victims from the beginning? If the freezer depends on
CONFIG_MMU=y, we don't need to thaw OOM victims.
We want to thaw them, at least at this stage, because the task might be sitting on a memory which is not reclaimable by the oom reaper (e.g. different buffers of file descriptors etc.).
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>
Re: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
Quoted 14 lines · Michal Hocko
Quoted 13 lines · Tetsuo Handa
Quoted 11 lines · Michal Hocko
mark_oom_victimandexit_oom_victimare used foroom_killer_disablewhich should block as long as there any any oom victims alive. Up to now we have relied onTIF_MEMDIEtask flag to count how many oom victim we have. This is not optimal because only one thread receives this flag at the time while the whole process (thread group) is killed and should die. As a result we do not thaw the whole thread group and so a multi threaded process can leave some threads behind in the fridge. We really want to thaw all the threads.This is not all that easy because there is no reliable way to count threads in the process as the oom killer might race with
copy_process.
Quoted 8 lines
Quoted 4 lines
What is wrong with racing with
copy_process()? Threads doingcopy_process()are not frozen and thus we don't need to thaw such threads. Also, being OOM-killed implies receiving SIGKILL. Thus, newly created thread will also enterdo_exit().The problem is that we cannot rely on
signal->nr_threadsto know when the last one is passing exit to declare the whole group done and wake the waiter on the oom killer lock.
I don't think we need to rely on signal->nr_threads. Why can't we simply do something like below (like error reporting in try_to_freeze_tasks()) ?
mm/oom_kill.c +30 -19
@@ -419,12 +419,6 @@ static void dump_header(struct oom_control *oc, struct task_struct *p)dump_tasks (oc->memcg, oc->nodemask); } -/* -* Number of OOM victims in flight -*/ -static atomic_t oom_victims =ATOMIC_INIT (0 ); -static DECLARE_WAIT_QUEUE_HEAD (oom_victims_wait); -static bool oom_killer_disabled__read_mostly ;#define K (x) ((x) << (PAGE_SHIFT-10))
@@ -666,7 +660,6 @@ static void mark_oom_victim(struct task_struct *tsk)* that TIF_MEMDIE tasks should be ignored. */ __thaw_task (tsk); -atomic_inc (&oom_victims); }/**
@@ -675,9 +668,6 @@ static void mark_oom_victim(struct task_struct *tsk)void exit_oom_victim (void ) {clear_thread_flag (TIF_MEMDIE ); - -if (!atomic_dec_return (&oom_victims)) -wake_up_all (&oom_victims_wait); }/**
@@ -705,8 +695,6 @@ void oom_killer_enable(void)*/ bool oom_killer_disable (signed long timeout) { -signed long ret; -/* * Make sure to not race with an ongoing OOM killer. Check that the * current is not killed (possibly due to sharing the victim's memory).
@@ -716,14 +704,37 @@ bool oom_killer_disable(signed long timeout) oom_killer_disabled = true;mutex_unlock (&oom_lock); - ret =wait_event_interruptible_timeout (oom_victims_wait, - !atomic_read (&oom_victims), timeout); -if (ret <=0 ) { -oom_killer_enable (); -return false; - } +/* +* Wait until all thawed threads reach final schedule() in do_exit() +* in order to make sure that OOM victims no longer try to trigger I/O. +* +* Since freezing_slow_path(p) returns false if TIF_MEMDIE is set, we +* need to check TASK_DEAD if TIF_MEMDIE is set. +*/ +while (timeout >0 ) { +struct task_struct *g, *p; +bool busy = false; -return true; +read_lock (&tasklist_lock); +for_each_process_thread (g, p) { +if (freezer_should_skip (p) ||frozen (p) || p == current) +continue ; +if (freezing (p) || + (p->state !=TASK_DEAD && +test_tsk_thread_flag (p,TIF_MEMDIE ))) { + busy = true; + goto out; + } + } +out: +read_unlock (&tasklist_lock); +if (!busy) +return true; +schedule_timeout_killable (HZ /10 ); + timeout -=HZ /10 ; + } +oom_killer_enable (); +return false; }static inline bool __task_will_free_mem (struct task_struct *task)
Quoted 23 lines
Quoted 23 lines
Quoted 5 lines
So marking all threads with
TIF_MEMDIEand incrementoom_victimsaccordingly is not safe. AlsoTIF_MEMDIEflag should just die so we should better come up with a different approach.Quoted 9 lines
All we need to guarantee is that
exit_oom_victimis called at the time when no further access to (possibly suspended) devices or generate other IO (which would clobber suspended image and only once per process) is possible. It seems we can rely onexit_notifyfor that because we already have to detect the last thread to do a cleanup. Let's propagate that information up todo_exitand only callexit_oom_victimfor such a thread. With this in place we can safely incrementoom_victimsonly once per thread group and thaw all the threads from the process.freezing_slow_pathcan also rely ontsk_is_oom_victimas well now.If marking all threads which belong to tsk thread group with
TIF_MEMDIEis not safe (due to possible race withcopy_process()), how canrcu_read_lock(); for_each_thread(tsk, t) __thaw_task(t); rcu_read_unlock();
Quoted 6 lines
Quoted 2 lines
in
mark_oom_victim()guarantee that all threads which belong to tsk thread group are thawed?Because all the frozen thread already have to be hashed and those which are in the middle of copy process will be
tsk_is_oom_victimand so the freezer will skip them.
Is it true for clone(CLONE_VM && !CLONE_SIGHAND) case? tsk_is_oom_victim() is a per signal check but we don't call mark_oom_victim() on each thread group sharing the victim's memory.
Quoted 11 lines
Quoted 7 lines
Unless all threads which belong to tsk thread group in
__refrigerator()are guaranteed to be thawed, they might fail to leave__refrigerator()in order to enterdo_exit()which means thatexit_oom_victim()won't be called.Do we want to thaw OOM victims from the beginning? If the freezer depends on
CONFIG_MMU=y, we don't need to thaw OOM victims.We want to thaw them, at least at this stage, because the task might be sitting on a memory which is not reclaimable by the oom reaper (e.g. different buffers of file descriptors etc.).
If you worry about tasks which are sitting on a memory which is not reclaimable by the oom reaper, why you don't worry about tasks which share mm and do not share signal (i.e. clone(CLONE_VM && !CLONE_SIGHAND) tasks) ? Thawing only tasks which share signal is a halfway job.
--
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>
Re: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
Quoted 6 lines · Tetsuo Handa
Quoted 6 lines
Quoted 2 lines
Do we want to thaw OOM victims from the beginning? If the freezer depends on
CONFIG_MMU=y, we don't need to thaw OOM victims.We want to thaw them, at least at this stage, because the task might be sitting on a memory which is not reclaimable by the oom reaper (e.g. different buffers of file descriptors etc.).
I haven't heard an answer to the question whether the freezer depends on CONFIG_MMU=y. But I assume the answer is yes here.
Quoted 6 lines
If you worry about tasks which are sitting on a memory which is not reclaimable by the oom reaper, why you don't worry about tasks which share mm and do not share signal (i.e.
clone(CLONE_VM && !CLONE_SIGHAND)tasks) ? Thawing only tasks which share signal is a halfway job.
Here is a different approach which does not thaw tasks as of mark_oom_victim() but thaws tasks as of oom_killer_disable(). I think that we don't need to distinguish OOM victims and killed/exiting tasks when we disable the OOM killer, for trying to reclaim as much memory as possible is preferable for reducing the possibility of memory allocation failure after the OOM killer is disabled.
Compared to your approach
Quoted 5 lines
include/linux/sched.h | 2 +- kernel/exit.c | 38 ++++++++++++++++++++++++++++---------- kernel/freezer.c | 3 ++- mm/oom_kill.c | 29 +++++++++++++++++------------ 4 files changed, 48 insertions(+), 24 deletions(-)
, my approach does not touch exit logic.
include/linux/sched.h | 4 ++ kernel/freezer.c | 2 - mm/oom_kill.c | 75 ++++++++++++++++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 27 deletions(-)
include/linux/sched.h +4 -0
@@ -2308,6 +2308,7 @@ static inline void memalloc_noio_restore(unsigned int flags)#define PFA_SPREAD_PAGE 1/* Spread page cache over cpuset */ #define PFA_SPREAD_SLAB 2/* Spread some slab caches over cpuset */ #define PFA_LMK_WAITING 3/* Lowmemorykiller is waiting */ +#define PFA_THAW_WAITING 4/* A thawed thread waiting for termination */ #define TASK_PFA_TEST (name, func) \
@@ -2334,6 +2335,9 @@ TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab) TASK_PFA_TEST(LMK_WAITING, lmk_waiting) TASK_PFA_SET(LMK_WAITING, lmk_waiting) +TASK_PFA_TEST(THAW_WAITING, thaw_waiting) +TASK_PFA_SET (THAW_WAITING , thaw_waiting) +/* * task->jobctl flags */
kernel/freezer.c +1 -1
@@ -42,7 +42,7 @@ bool freezing_slow_path(struct task_struct *p)if (p->flags & (PF_NOFREEZE |PF_SUSPEND_TASK ))return false; -if (test_tsk_thread_flag (p,TIF_MEMDIE )) +if (task_thaw_waiting (p))return false;if (pm_nosig_freezing ||cgroup_freezing (p))
mm/oom_kill.c +49 -26
106 lines not on this page · raw message
--
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>
Michal Hocko
maintainerRe: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
Quoted 10 lines · Tetsuo Handa
Quoted 6 lines · Tetsuo Handa
Quoted 6 lines
Quoted 2 lines
Do we want to thaw OOM victims from the beginning? If the freezer depends on
CONFIG_MMU=y, we don't need to thaw OOM victims.We want to thaw them, at least at this stage, because the task might be sitting on a memory which is not reclaimable by the oom reaper (e.g. different buffers of file descriptors etc.).
I haven't heard an answer to the question whether the freezer depends on
CONFIG_MMU=y. But I assume the answer is yes here.
I do not think it depends on CONFIG_MMU. At least CGROUP_FREEZER depends on CONFIG_CGROUPS and that doesn't seem to have any direct dependency on MMU.
Quoted 7 lines
Quoted 6 lines
If you worry about tasks which are sitting on a memory which is not reclaimable by the oom reaper, why you don't worry about tasks which share mm and do not share signal (i.e.
clone(CLONE_VM && !CLONE_SIGHAND)tasks) ? Thawing only tasks which share signal is a halfway job.
Quoted 6 lines
Here is a different approach which does not thaw tasks as of
mark_oom_victim()but thaws tasks as ofoom_killer_disable(). I think that we don't need to distinguish OOM victims and killed/exiting tasks when we disable the OOM killer, for trying to reclaim as much memory as possible is preferable for reducing the possibility of memory allocation failure after the OOM killer is disabled.
This makes the oom_killer_disable suspend specific which is imho not necessary. While we do not have any other user outside of the suspend path right now and I hope we will not need any in a foreseeable future there is no real reason to do a hack like this if we can make the implementation suspend independent.
Quoted 9 lines
Compared to your approach
Quoted 5 lines
include/linux/sched.h | 2 +- kernel/exit.c | 38 ++++++++++++++++++++++++++++---------- kernel/freezer.c | 3 ++- mm/oom_kill.c | 29 +++++++++++++++++------------ 4 files changed, 48 insertions(+), 24 deletions(-), my approach does not touch exit logic.
I consider the exit path changes so miniscule that trading it with pm specific code in the oom sounds like a worse solution. Well, all that assuming that the actual change is correct, 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>
Re: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
Quoted 15 lines · Michal Hocko
Quoted 7 lines · Tetsuo Handa
Quoted 5 lines · Tetsuo Handa
If you worry about tasks which are sitting on a memory which is not reclaimable by the oom reaper, why you don't worry about tasks which share mm and do not share signal (i.e.
clone(CLONE_VM && !CLONE_SIGHAND)tasks) ? Thawing only tasks which share signal is a halfway job.Quoted 6 lines
Here is a different approach which does not thaw tasks as of
mark_oom_victim()but thaws tasks as ofoom_killer_disable(). I think that we don't need to distinguish OOM victims and killed/exiting tasks when we disable the OOM killer, for trying to reclaim as much memory as possible is preferable for reducing the possibility of memory allocation failure after the OOM killer is disabled.
Quoted 5 lines
This makes the
oom_killer_disablesuspend specific which is imho not necessary. While we do not have any other user outside of the suspend path right now and I hope we will not need any in a foreseeable future there is no real reason to do a hack like this if we can make the implementation suspend independent.
My intention is to somehow get rid of oom_killer_disable(). While I wrote this approach, I again came to wonder why we need to disable the OOM killer during suspend.
If the reason is that the OOM killer thaws already frozen OOM victims, we won't have reason to disable the OOM killer if the OOM killer does not thaw OOM victims. We can rely on the OOM killer/reaper immediately before start taking a memory snapshot for suspend.
If the reason is that the OOM killer changes SIGKILL pending state of already frozen OOM victims during taking a memory snapshot, I think that sending SIGKILL via not only SysRq-f but also SysRq-i will be problematic.
If the reason is that the OOM reaper changes content of mm_struct of OOM victims during taking a memory snapshot, what guarantees that the OOM reaper does not call __oom_reap_task_mm() because we are not waiting for oom_reaper_list to become NULL at oom_killer_disable(), for patch "oom, suspend: fix oom_killer_disable vs. pm suspend properly" removed set_freezable() from oom_reaper() which made oom_reaper() no longer enter __refrigerator() at wait_event_freezable() in oom_reaper() ?
--
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>
Michal Hocko
maintainerRe: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
Quoted 22 lines · Tetsuo Handa
Quoted 15 lines · Michal Hocko
Quoted 7 lines · Tetsuo Handa
Quoted 5 lines · Tetsuo Handa
If you worry about tasks which are sitting on a memory which is not reclaimable by the oom reaper, why you don't worry about tasks which share mm and do not share signal (i.e.
clone(CLONE_VM && !CLONE_SIGHAND)tasks) ? Thawing only tasks which share signal is a halfway job.Quoted 6 lines
Here is a different approach which does not thaw tasks as of
mark_oom_victim()but thaws tasks as ofoom_killer_disable(). I think that we don't need to distinguish OOM victims and killed/exiting tasks when we disable the OOM killer, for trying to reclaim as much memory as possible is preferable for reducing the possibility of memory allocation failure after the OOM killer is disabled.Quoted 5 lines
This makes the
oom_killer_disablesuspend specific which is imho not necessary. While we do not have any other user outside of the suspend path right now and I hope we will not need any in a foreseeable future there is no real reason to do a hack like this if we can make the implementation suspend independent.
Quoted 8 lines
My intention is to somehow get rid of
oom_killer_disable(). While I wrote this approach, I again came to wonder why we need to disable the OOM killer during suspend.If the reason is that the OOM killer thaws already frozen OOM victims, we won't have reason to disable the OOM killer if the OOM killer does not thaw OOM victims. We can rely on the OOM killer/reaper immediately before start taking a memory snapshot for suspend.
Yes, if we don't have to wake already frozen tasks then the life would be easier. But as I've already mentioned the async oom doesn't cover all we need and the tasks can be frozen also from the userspace which means that this is under user control.
Quoted 3 lines
If the reason is that the OOM killer changes SIGKILL pending state of already frozen OOM victims during taking a memory snapshot, I think that sending SIGKILL via not only SysRq-f but also SysRq-i will be problematic.
Sysrq+i will not be a problem because that will not thaw any frozen tasks.
Quoted 2 lines
If the reason is that the OOM reaper changes content of
mm_structof OOM victims during taking a memory snapshot,
I do not think this is a problem. But I have to think about this some more. My thinking is that even if saved the original content before reaping it then all that matters is that the victim just goes away so it cannot observe the corruption.
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>
Michal Hocko
maintainerRe: [RFC 3/4] mm, oom: do not rely on TIF_MEMDIE for exit_oom_victim
In reply to Michal HockoHi Oleg,
does this sound sane/correct to you?
Quoted 248 lines · Michal Hocko
From: Michal Hocko <[email protected]>
mark_oom_victimandexit_oom_victimare used foroom_killer_disablewhich should block as long as there any any oom victims alive. Up to now we have relied onTIF_MEMDIEtask flag to count how many oom victim we have. This is not optimal because only one thread receives this flag at the time while the whole process (thread group) is killed and should die. As a result we do not thaw the whole thread group and so a multi threaded process can leave some threads behind in the fridge. We really want to thaw all the threads.This is not all that easy because there is no reliable way to count threads in the process as the oom killer might race with
copy_process. So marking all threads withTIF_MEMDIEand incrementoom_victimsaccordingly is not safe. AlsoTIF_MEMDIEflag should just die so we should better come up with a different approach.All we need to guarantee is that
exit_oom_victimis called at the time when no further access to (possibly suspended) devices or generate other IO (which would clobber suspended image and only once per process) is possible. It seems we can rely onexit_notifyfor that because we already have to detect the last thread to do a cleanup. Let's propagate that information up todo_exitand only callexit_oom_victimfor such a thread. With this in place we can safely incrementoom_victimsonly once per thread group and thaw all the threads from the process.freezing_slow_pathcan also rely ontsk_is_oom_victimas well now.
exit_io_contextis currently called afterexit_notifybut it seems it is safe to call it right beforeexit_notifybecause that is passedexit_files.Cc Oleg Nesterov <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Michal Hocko <[email protected]>--- include/linux/sched.h | 2 +- kernel/exit.c | 38 ++++++++++++++++++++++++++++---------- kernel/freezer.c | 3 ++- mm/oom_kill.c | 29 +++++++++++++++++------------ 4 files changed, 48 insertions(+), 24 deletions(-)include/linux/sched.h +1
-1@@ -2660,7 +2660,7 @@ static inline void kernel_signal_stop(void)schedule (); } -extern void release_task (struct task_struct * p); +extern bool release_task (struct task_struct * p);extern int send_sig_info (int ,struct siginfo *,struct task_struct *);extern int force_sigsegv (int ,struct task_struct *);extern int force_sig_info (int ,struct siginfo *,struct task_struct *);kernel/exit.c +28
-10@@ -165,10 +165,11 @@ static void delayed_put_task_struct(struct rcu_head *rhp) } -void release_task (struct task_struct *p) +bool release_task (struct task_struct *p) {struct task_struct *leader;int zap_leader; +bool last = false; repeat:/* don't need to get the RCU readlock here - the process is dead and * can't be modifying its own credentials. But shut RCU-lockdep up */ @@ -197,8 +198,10 @@ void release_task(struct task_struct *p)* then we are the one who should release the leader. */ zap_leader =do_notify_parent (leader, leader->exit_signal); -if (zap_leader) +if (zap_leader) { leader->exit_state =EXIT_DEAD ; + last = true; + } }write_unlock_irq (&tasklist_lock);@@ -208,6 +211,8 @@ void release_task(struct task_struct *p) p = leader;if (unlikely (zap_leader)) goto repeat; + +return last; }/* @@ -434,8 +439,6 @@ static void exit_mm(struct task_struct *tsk)task_unlock (tsk);mm_update_next_owner (mm);mmput (mm); -if (test_thread_flag (TIF_MEMDIE )) -exit_oom_victim (); }static struct task_struct *find_alive_thread (struct task_struct *p)@@ -584,12 +587,15 @@ static void forget_original_parent(struct task_struct *father,/* * Send signals to all our closest relatives so that they know * to properly mourn us.. +* +* Returns true if this is the last thread from the thread group */ -static void exit_notify (struct task_struct *tsk,int group_dead) +static bool exit_notify (struct task_struct *tsk,int group_dead) {bool autoreap;struct task_struct *p, *n;LIST_HEAD (dead); +bool last = false;write_lock_irq (&tasklist_lock);forget_original_parent (tsk, &dead);@@ -606,6 +612,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead) }else if (thread_group_leader (tsk)) { autoreap =thread_group_empty (tsk) &&do_notify_parent (tsk, tsk->exit_signal); + last =thread_group_empty (tsk); }else { autoreap = true; }@@ -621,8 +628,11 @@ static void exit_notify(struct task_struct *tsk, int group_dead)list_for_each_entry_safe (p, n, &dead, ptrace_entry) {list_del_init (&p->ptrace_entry); -release_task (p); +if (release_task (p) && p == tsk) + last = true; } + +return last; }#ifdef CONFIG_DEBUG_STACK_USAGE @@ -766,7 +776,18 @@ void do_exit(long code)TASKS_RCU (preempt_disable ());TASKS_RCU (tasks_rcu_i =__srcu_read_lock (&tasks_rcu_exit_srcu));TASKS_RCU (preempt_enable ()); -exit_notify (tsk, group_dead); + +if (tsk->io_context) +exit_io_context (tsk); + +/* +* Notify oom_killer_disable that the last oom thread is exiting. +* We might have more threads running at this point but none of them +* will access any devices behind this point. +*/ +if (exit_notify (tsk, group_dead) &&tsk_is_oom_victim (current)) +exit_oom_victim (); +proc_exit_connector (tsk);mpol_put_task_policy (tsk);#ifdef CONFIG_FUTEX @@ -784,9 +805,6 @@ void do_exit(long code)*/ tsk->flags |=PF_EXITPIDONE ; -if (tsk->io_context) -exit_io_context (tsk); -if (tsk->splice_pipe)free_pipe_info (tsk->splice_pipe);kernel/freezer.c +2
-1@@ -10,6 +10,7 @@#include <linux/syscalls.h> #include <linux/freezer.h> #include <linux/kthread.h> +#include <linux/oom.h> /* total number of freezing conditions in effect */ atomic_t system_freezing_cnt =ATOMIC_INIT (0 );@@ -42,7 +43,7 @@ bool freezing_slow_path(struct task_struct *p)if (p->flags & (PF_NOFREEZE |PF_SUSPEND_TASK ))return false; -if (test_tsk_thread_flag (p,TIF_MEMDIE )) +if (tsk_is_oom_victim (p))return false;if (pm_nosig_freezing ||cgroup_freezing (p))mm/oom_kill.c +17
-12@@ -649,33 +649,38 @@ static inline void wake_oom_reaper(struct task_struct *tsk)static void mark_oom_victim (struct task_struct *tsk) {struct mm_struct *mm = tsk->mm; +struct task_struct *t;WARN_ON (oom_killer_disabled); -/* OOM killer might race with memcg OOM */ -if (test_and_set_tsk_thread_flag (tsk,TIF_MEMDIE )) -return ;/* oom_mm is bound to the signal struct life time. */ -if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) +if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) {atomic_inc (&tsk->signal->oom_mm->mm_count); +/* Only count thread groups */ +atomic_inc (&oom_victims); + } +/* -* Make sure that the task is woken up from uninterruptible sleep -* if it is frozen because OOM killer wouldn't be able to free -* any memory and livelock. freezing_slow_path will tell the freezer -* that TIF_MEMDIE tasks should be ignored. +* Make sure that the the whole thread groupd is woken up from +* uninterruptible sleep if it is frozen because the oom victim +* will free its memory completely only after exit. +* freezing_slow_path will tell the freezer that oom victims +* should be ignored. */ -__thaw_task (tsk); -atomic_inc (&oom_victims); +rcu_read_lock (); +for_each_thread (tsk, t) +__thaw_task (t); +rcu_read_unlock (); }/** * exit_oom_victim - note the exit of an OOM victim +* +* Has to be called only once per thread group. */ void exit_oom_victim (void ) { -clear_thread_flag (TIF_MEMDIE ); -if (!atomic_dec_return (&oom_victims))wake_up_all (&oom_victims_wait); }Signature · 1 line
2.8.1
Signature · 2 lines
Michal Hocko SUSE Labs
Johannes Weiner
maintainerHi Michal,
Quoted 19 lines · Michal Hocko
Hi,
this is an early RFC to see whether the approach I've taken is acceptable. The series is on top of the current mmotm tree (2016-08-31-16-06). I didn't get to test it so it might be completely broken.The primary point of this series is to get rid of
TIF_MEMDIEfinally. Recent changes in the oom proper allows for that finally, I believe. Now that all the oom victims are reapable we are no longer depending onALLOC_NO_WATERMARKSbecause the memory held by the victim is reclaimed asynchronously. A partial access to memory reserves should be sufficient just to guarantee that the oom victim is not starved due to other memory consumers. This also means that we do not have to pretend to be conservative and give access to memory reserves only to one thread from the process at the time. This is patch 1.Patch 2 is a simple cleanup which turns
TIF_MEMDIEusers totsk_is_oom_victimwhich is process rather than thread centric. None of those callers really requires to be thread aware AFAICS.
Quoted 8 lines
The tricky part then is
exit_oom_victimvs.oom_killer_disablebecauseTIF_MEMDIEacted as a token there so we had a way to count threads from the process. It didn't work 100% reliably and had it own issues but we have to replace it with something which doesn't rely on counting threads but rather find a moment when all threads have reached steady state indo_exit. This is what patch 3 does and I would really appreciate if Oleg could double check my thinking there. I am also CCing Al on that one because I am movingexit_io_contextup indo_exitright beforeexit_notify.
You're explaining the mechanical thing you are doing, but I'm having trouble understanding why you want to get rid of TIF_MEMDIE. For one, it's more code. And apparently, it's also more complicated than what we have right now.
Can you please explain in the cover letter what's broken/undesirable?
Thanks
--
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>
Michal Hocko
maintainerQuoted 31 lines · Johannes Weiner
Hi Michal,
Quoted 19 lines · Michal Hocko
Hi,
this is an early RFC to see whether the approach I've taken is acceptable. The series is on top of the current mmotm tree (2016-08-31-16-06). I didn't get to test it so it might be completely broken.The primary point of this series is to get rid of
TIF_MEMDIEfinally. Recent changes in the oom proper allows for that finally, I believe. Now that all the oom victims are reapable we are no longer depending onALLOC_NO_WATERMARKSbecause the memory held by the victim is reclaimed asynchronously. A partial access to memory reserves should be sufficient just to guarantee that the oom victim is not starved due to other memory consumers. This also means that we do not have to pretend to be conservative and give access to memory reserves only to one thread from the process at the time. This is patch 1.Patch 2 is a simple cleanup which turns
TIF_MEMDIEusers totsk_is_oom_victimwhich is process rather than thread centric. None of those callers really requires to be thread aware AFAICS.Quoted 8 lines
The tricky part then is
exit_oom_victimvs.oom_killer_disablebecauseTIF_MEMDIEacted as a token there so we had a way to count threads from the process. It didn't work 100% reliably and had it own issues but we have to replace it with something which doesn't rely on counting threads but rather find a moment when all threads have reached steady state indo_exit. This is what patch 3 does and I would really appreciate if Oleg could double check my thinking there. I am also CCing Al on that one because I am movingexit_io_contextup indo_exitright beforeexit_notify.
Quoted 6 lines
You're explaining the mechanical thing you are doing, but I'm having trouble understanding why you want to get rid of
TIF_MEMDIE. For one, it's more code. And apparently, it's also more complicated than what we have right now.Can you please explain in the cover letter what's broken/undesirable?
Sure, I will extend the cover when submitting the series again. This RFC was mostly aimed at correctness so I focused more on technical details. Patch 1 should contain some reasoning. Do you find it sufficient or I should extend on top of that?
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>
Johannes Weiner
maintainerQuoted 37 lines · Michal Hocko
Quoted 36 lines · Johannes Weiner
Hi Michal,
Quoted 19 lines · Michal Hocko
Hi,
this is an early RFC to see whether the approach I've taken is acceptable. The series is on top of the current mmotm tree (2016-08-31-16-06). I didn't get to test it so it might be completely broken.The primary point of this series is to get rid of
TIF_MEMDIEfinally. Recent changes in the oom proper allows for that finally, I believe. Now that all the oom victims are reapable we are no longer depending onALLOC_NO_WATERMARKSbecause the memory held by the victim is reclaimed asynchronously. A partial access to memory reserves should be sufficient just to guarantee that the oom victim is not starved due to other memory consumers. This also means that we do not have to pretend to be conservative and give access to memory reserves only to one thread from the process at the time. This is patch 1.Patch 2 is a simple cleanup which turns
TIF_MEMDIEusers totsk_is_oom_victimwhich is process rather than thread centric. None of those callers really requires to be thread aware AFAICS.Quoted 8 lines
The tricky part then is
exit_oom_victimvs.oom_killer_disablebecauseTIF_MEMDIEacted as a token there so we had a way to count threads from the process. It didn't work 100% reliably and had it own issues but we have to replace it with something which doesn't rely on counting threads but rather find a moment when all threads have reached steady state indo_exit. This is what patch 3 does and I would really appreciate if Oleg could double check my thinking there. I am also CCing Al on that one because I am movingexit_io_contextup indo_exitright beforeexit_notify.You're explaining the mechanical thing you are doing, but I'm having trouble understanding why you want to get rid of
TIF_MEMDIE. For one, it's more code. And apparently, it's also more complicated than what we have right now.
Quoted 6 lines
Quoted 1 line
Can you please explain in the cover letter what's broken/undesirable?
Sure, I will extend the cover when submitting the series again. This RFC was mostly aimed at correctness so I focused more on technical details. Patch 1 should contain some reasoning. Do you find it sufficient or I should extend on top of that?
: For ages we have been relying on TIF_MEMDIE thread flag to mark OOM : victims and then, among other things, to give these threads full : access to memory reserves. There are few shortcomings of this : implementation, though.
:
: First of all and the most serious one is that the full access to memory : reserves is quite dangerous because we leave no safety room for the : system to operate and potentially do last emergency steps to move on.
Do we encounter this in practice? I think one of the clues is that you introduce the patch with "for ages we have been doing X", so I'd like to see a more practical explanation of how we did it was flawed.
: Secondly this flag is per task_struct while the OOM killer operates : on mm_struct granularity so all processes sharing the given mm are : killed. Giving the full access to all these task_structs could leave to : a quick memory reserves depletion. We have tried to reduce this risk by : giving TIF_MEMDIE only to the main thread and the currently allocating : task but that doesn't really solve this problem while it surely opens up : a room for corner cases - e.g. GFP_NO{FS,IO} requests might loop inside : the allocator without access to memory reserves because a particular : thread was not the group leader.
Same here I guess.
It *sounds* to me like there are two different things going on here. One being the access to emergency reserves, the other being the synchronization token to count OOM victims. Maybe it would be easier to separate those issues out in the line of argument?
For emergency reserves, you make the point that we now have the reaper and don't rely on the reserves as much anymore. However, we need to consider that the reaper relies on the mmap_sem and is thus not as robust as the concept of an emergency pool to guarantee fwd progress.
For synchronization, I don't quite get the argument. The patch 4 changelog uses term like "not optimal" and that we "should" be doing certain things, but doesn't explain the consequences of the "wrong" behavior, the impact is of frozen threads getting left behind etc.
That stuff would be useful to know, both in the cover letter (higher level user impact) and the changelogs (more detailed user impact).
I.e. sell the problem before selling the solution :-)
Thanks!
--
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>
Michal Hocko
maintainerQuoted 1 line · Johannes Weiner
On Fri, Sep 16, 2016 at 09:15:17AM +0200, Michal Hocko wrote:
[...]
Quoted 10 lines
: For ages we have been relying on
TIF_MEMDIEthread flag to mark OOM : victims and then, among other things, to give these threads full : access to memory reserves. There are few shortcomings of this : implementation, though.
:
: First of all and the most serious one is that the full access to memory : reserves is quite dangerous because we leave no safety room for the : system to operate and potentially do last emergency steps to move on.Do we encounter this in practice?
We rarely experience anything from this in practice. Even OOM is an outstanding situation. Most of the lockups I am trying to solve are close to non-existent. But this doesn't mean they are non-existent so as far as the resulting code makes sense and doesn't make the situation overly more complicated then I would go with enhancements.
Quoted 3 lines
I think one of the clues is that you
introduce the patch with "for ages we have been doing X", so I'd like to see a more practical explanation of how we did it was flawed.
OK, I will try harder to explain that. The core idea is that we couldn't do anything better without the async oom killing because we were strictly synchronous and only the victim could make some progress.
Quoted 10 lines
: Secondly this flag is per
task_structwhile the OOM killer operates : onmm_structgranularity so all processes sharing the given mm are : killed. Giving the full access to all thesetask_structscould leave to : a quick memory reserves depletion. We have tried to reduce this risk by : givingTIF_MEMDIEonly to the main thread and the currently allocating : task but that doesn't really solve this problem while it surely opens up : a room for corner cases - e.g. GFP_NO{FS,IO} requests might loop inside : the allocator without access to memory reserves because a particular : thread was not the group leader.
Quoted 6 lines
Same here I guess.
It *sounds* to me like there are two different things going on here. One being the access to emergency reserves, the other being the synchronization token to count OOM victims. Maybe it would be easier to separate those issues out in the line of argument?
Yes this is precisely the problem. The meaning of the flag is overloaded for multiple purposes and it is not as easy to describe all of this and get tangled in all the details. Over time we have reduced the locking side of the flag but we still use it for oom_disable synchronization and memory reserves access.
Quoted 4 lines
For emergency reserves, you make the point that we now have the reaper and don't rely on the reserves as much anymore. However, we need to consider that the reaper relies on the
mmap_semand is thus not as robust as the concept of an emergency pool to guarantee fwd progress.
Yes it is not 100% but if we get stuck there then we will have a way to go on to another victim so we will not lockup. On the other hand lockup due to mmap_sem for write should be really rare because the lock is mostly killable and taken outside of the oom victim context even more rarely.
Quoted 4 lines
For synchronization, I don't quite get the argument. The patch 4 changelog uses term like "not optimal" and that we "should" be doing certain things, but doesn't explain the consequences of the "wrong" behavior, the impact is of frozen threads getting left behind etc.
Yes I will try harder. The primary point is a mismatch between oom killer being per-mm operation and the flag being per-thread thing. For the freezer context it means that only one thread is woken up while other are still in the fridge. This wouldn't be a big deal for the pm freezer but the cgroup freezer allows normal user to hide processes in the fridge so users might hide processes there intentionally. The other part of the puzzle is that not all resources are reclaimable by the async oom killer. Say pipe/socket buffers can consume a lot of memory while they are pinned by process not threads.
Quoted 4 lines
That stuff would be useful to know, both in the cover letter (higher level user impact) and the changelogs (more detailed user impact).
I.e. sell the problem before selling the solution :-)
Sure, I see what you are saying. I just feel there are so many subtle details that it is hard to squeeze all of them into the changelog and still make some sense ;)
Anyway, I will definitely try to be more specific in the next post. Thanks for the feedback!
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>