• Michal Hocko's avatar
    mm, oom_reaper: clear TIF_MEMDIE for all tasks queued for oom_reaper · 449d777d
    Michal Hocko authored
    Right now the oom reaper will clear TIF_MEMDIE only for tasks which were
    successfully reaped.  This is the safest option because we know that
    such an oom victim would only block forward progress of the oom killer
    without a good reason because it is highly unlikely it would release
    much more memory.  Basically most of its memory has been already torn
    down.
    
    We can relax this assumption to catch more corner cases though.
    
    The first obvious one is when the oom victim clears its mm and gets
    stuck later on.  oom_reaper would back of on find_lock_task_mm returning
    NULL.  We can safely try to clear TIF_MEMDIE in this case because such a
    task would be ignored by the oom killer anyway.  The flag would be
    cleared by that time already most of the time anyway.
    
    The less obvious one is when the oom reaper fails due to mmap_sem
    contention.  Even if we clear TIF_MEMDIE for this task then it is not
    very likely that we would select another task too easily because we
    haven't reaped the last victim and so it would be still the #1
    candidate.  There is a rare race condition possible when the current
    victim terminates before the next select_bad_process but considering
    that oom_reap_task had retried several times before giving up then this
    sounds like a borderline thing.
    
    After this patch we should have a guarantee that the OOM killer will not
    be block for unbounded amount of time for most cases.
    Signed-off-by: default avatarMichal Hocko <mhocko@suse.com>
    Cc: Raushaniya Maksudova <rmaksudova@parallels.com>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
    Cc: Daniel Vetter <daniel.vetter@intel.com>
    Cc: Oleg Nesterov <oleg@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    449d777d
oom_kill.c 26.6 KB