From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id 811FA6B0279 for ; Thu, 15 Jun 2017 08:03:41 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id 56so3131157wrx.5 for ; Thu, 15 Jun 2017 05:03:41 -0700 (PDT) Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id a84si545570wma.33.2017.06.15.05.03.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 15 Jun 2017 05:03:40 -0700 (PDT) Date: Thu, 15 Jun 2017 14:03:35 +0200 From: Michal Hocko Subject: Re: [patch] mm, oom: prevent additional oom kills before memory is freed Message-ID: <20170615120335.GJ1486@dhcp22.suse.cz> References: <20170615103909.GG1486@dhcp22.suse.cz> <201706151953.HFH78657.tFFLOOOQHSMVFJ@I-love.SAKURA.ne.jp> <20170615110119.GI1486@dhcp22.suse.cz> <201706152032.BFE21313.MSHQOtLVFFJOOF@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201706152032.BFE21313.MSHQOtLVFFJOOF@I-love.SAKURA.ne.jp> Sender: owner-linux-mm@kvack.org List-ID: To: Tetsuo Handa Cc: rientjes@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org On Thu 15-06-17 20:32:39, Tetsuo Handa wrote: > Michal Hocko wrote: [...] > > An alternative would be to allow reaping and exit_mmap race. The unmap > > part should just work I guess. We just have to be careful to not race > > with free_pgtables and that shouldn't be too hard to implement (e.g. > > (ab)use mmap_sem for write there). I haven't thought that through > > completely though so I might miss something of course. > > I think below one is simpler. [...] > @@ -556,25 +553,21 @@ static void oom_reap_task(struct task_struct *tsk) > struct mm_struct *mm = tsk->signal->oom_mm; > > /* Retry the down_read_trylock(mmap_sem) a few times */ > - while (attempts++ < MAX_OOM_REAP_RETRIES && !__oom_reap_task_mm(tsk, mm)) > + while (__oom_reap_task_mm(tsk, mm), !test_bit(MMF_OOM_SKIP, &mm->flags) > + && attempts++ < MAX_OOM_REAP_RETRIES) > schedule_timeout_idle(HZ/10); > > - if (attempts <= MAX_OOM_REAP_RETRIES) > - goto done; > - > - > - pr_info("oom_reaper: unable to reap pid:%d (%s)\n", > - task_pid_nr(tsk), tsk->comm); > - debug_show_all_locks(); > - > -done: > - tsk->oom_reaper_list = NULL; > - > /* > * Hide this mm from OOM killer because it has been either reaped or > * somebody can't call up_write(mmap_sem). > */ > - set_bit(MMF_OOM_SKIP, &mm->flags); > + if (!test_and_set_bit(MMF_OOM_SKIP, &mm->flags)) { > + pr_info("oom_reaper: unable to reap pid:%d (%s)\n", > + task_pid_nr(tsk), tsk->comm); > + debug_show_all_locks(); > + } > + How does this _solve_ anything? Why would you even retry when you _know_ that the reference count dropped to zero. It will never increment. So the above is basically just schedule_timeout_idle(HZ/10) * MAX_OOM_REAP_RETRIES before we set MMF_OOM_SKIP. This might be enough for victim to finish the exit_mmap but it is more a hack^Wworkround than anything else. You could very well do the sleep without any obfuscation... -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org