From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F82C433E2 for ; Mon, 20 Jul 2020 14:00:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B86F2070A for ; Mon, 20 Jul 2020 14:00:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TprIQhKQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B86F2070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 14A716B0006; Mon, 20 Jul 2020 10:00:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D57D6B0007; Mon, 20 Jul 2020 10:00:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDD8E6B0008; Mon, 20 Jul 2020 10:00:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id D51896B0006 for ; Mon, 20 Jul 2020 10:00:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5FAE64698123 for ; Mon, 20 Jul 2020 14:00:26 +0000 (UTC) X-FDA: 77058614052.28.face23_5b151c826f25 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 058364698155 for ; Mon, 20 Jul 2020 14:00:24 +0000 (UTC) X-HE-Tag: face23_5b151c826f25 X-Filterd-Recvd-Size: 7767 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Jul 2020 14:00:23 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id z6so163525iow.6 for ; Mon, 20 Jul 2020 07:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RyquF4EO2L2+woYTXpKQiczdRijP185DqxkYuzH9PpM=; b=TprIQhKQO29SolVHLIZkVTh3LqxCTYaqFOgwKwD+dSA5ig9Pa+I3IRrl4mjMySGywP b5MJBo8PKqHYBliKTIJve8/rAfEAik4LDJH2rHl1SWwePdFyyKaj1bTxvNTn/pb311jN 9Cu+g3mLacY9aIFu2hCsRIXwV6QtNCBTrwO8yK+zlvSQ7NQ2LqlYRN57Hw6FAOTjf4OK y8gpSysgFlDO5ahfjrp9UPirN3viR9EsLNQrTk3C1yLKnGUYIhYFkbodZhuKoC+jKB3/ mr2QL55dlWPPg8i3rLo8bocnaDIX4MyY4E5bPpssU6I5Mlh2KhKIT/51gOxkmorF1kV5 pp5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RyquF4EO2L2+woYTXpKQiczdRijP185DqxkYuzH9PpM=; b=F3vx8i/1TcfRuIIcf1q+wv/0IV/pGhWXzY1Yc7pDRnWBLG2UEHDQddTW/leTE8sCMr 9z6LtHV/in9cwlbm+KXPk8neoZHGVoysCwqPcj2pJY4bX0zPk13s0deFhbAfApmGxKRT //KdeIEMDJirifaIDkbzJWs10SCX3Qe2+ee9nw8XCbEOfKFew9sWkEiC+kTp6bkkWdqz 9F7a8bJ+jj7zcSftR6yvbj3YgXEaiOxpdEHrB5JJWjPzVZWp5bwlQaE/IHzulxuDN3FD MTEuLiX6COQOOjIVl6HNNfWvBT7t/5mozMVV8cHX5pQBs9uENvx8Kusc0MoOZpY7Adr5 4y1Q== X-Gm-Message-State: AOAM531RBvXpE6elpi3xLXmKRlhuOwXfdax5fYLfW68xvhvJWBlrO5B3 DCW36f8AFVLC+8eSiSAtZ/rjM1LerB2J6d3/z0E= X-Google-Smtp-Source: ABdhPJyU2KeZna7shZaxmd4KkQn9SA4GtY1z/tnHHl17r5dlsghTC9Ngv9JJBxnQzD8dJ5fA7rStWw7OvQLOYIKhmos= X-Received: by 2002:a6b:c343:: with SMTP id t64mr23708592iof.66.1595253622652; Mon, 20 Jul 2020 07:00:22 -0700 (PDT) MIME-Version: 1.0 References: <1595166795-27587-1-git-send-email-laoar.shao@gmail.com> <20200720071607.GA18535@dhcp22.suse.cz> <253332d9-9f8c-d472-0bf4-388b29ecfb96@i-love.sakura.ne.jp> <7f58363a-db1a-5502-e2b4-ee4b9fa31824@i-love.sakura.ne.jp> In-Reply-To: <7f58363a-db1a-5502-e2b4-ee4b9fa31824@i-love.sakura.ne.jp> From: Yafang Shao Date: Mon, 20 Jul 2020 21:59:49 +0800 Message-ID: Subject: Re: [PATCH] mm, oom: show process exiting information in __oom_kill_process() To: Tetsuo Handa Cc: Michal Hocko , David Rientjes , Andrew Morton , Linux MM Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 058364698155 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jul 20, 2020 at 9:11 PM Tetsuo Handa wrote: > > On 2020/07/20 21:19, Yafang Shao wrote: > > On Mon, Jul 20, 2020 at 7:06 PM Tetsuo Handa > > wrote: > >> > >> On 2020/07/20 19:36, Yafang Shao wrote: > >>> On Mon, Jul 20, 2020 at 3:16 PM Michal Hocko wrote: > >>>> I do agree that a silent bail out is not the best thing to do. The above > >>>> message would be more useful if it also explained what the oom killer > >>>> does (or does not): > >>>> > >>>> "OOM victim %d (%s) is already exiting. Skip killing the task\n" > >>>> > >>> > >>> Sure. > >> > >> This path is rarely hit because find_lock_task_mm() in oom_badness() from > >> select_bad_process() in the next round of OOM killer will skip this task. > >> > >> Since we don't wake up the OOM reaper when hitting this path, unless __mmput() > >> for this task itself immediately reclaims memory and updates the statistics > >> counter, we just get two chunks of dump_header() messages and one OOM victim. > >> > > > > Could you pls. explain more specifically why we will get two chunks of > > dump_header()? > > My understanding is the free_mm() happens between select_bad_process() > > and __oom_kill_process() as bellow, > > > > P1 > > Victim > > select_bad_process() > > oom_badness() > > p = find_lock_task_mm() # p isn't NULL > > > > __mmput() > > > > free_mm() > > dump_header() # dump once > > __oom_kill_process() > > p = find_lock_task_mm(victim); # p is NULL now > > > > So where is another dump_header() ? > > > > Start of __mmput() does not guarantee that memory is reclaimed immediately. > Moreover, even __mmput() might not have started by the moment second chunk of > dump_header() happens. The "OOM victim %d (%s) is already exiting." case only > indicates that victim's mm became NULL; there is no guarantee that memory is > reclaimed (in order to avoid OOM kill) by the moment next round hits. > > P1 Victim1 Victim2 > > out_of_memory() { > select_bad_process() { > oom_badness() { > p = find_lock_task_mm() { > task_lock(victim); // finds Victim1 because Victim1->mm != NULL. > } > get_task_struct(p); > task_unlock(p); > } > } > oom_kill_process() { > task_lock(victim); > task_unlock(victim); > do_exit() { > dump_header(oc, victim); // first dump_header() with Victim1 and Victim2 > __oom_kill_process(victim, message) { > exit_mm() { > task_lock(current); > current->mm = NULL; > task_unlock(current); > p = find_lock_task_mm(victim); > put_task_struct(victim); // without killing Victim1 because p == NULL. > } > } > } > } > out_of_memory() { > select_bad_process() { > oom_badness() { > p = find_lock_task_mm() { > task_lock(victim); // finds Victim2 because Victim2->mm != NULL. > } > get_task_struct(p); > task_unlock(p); > } > } > mmput() { > __mmput() { > uprobe_clear_state() { > // Might wait for delayed_uprobe_lock. > } > oom_kill_process() { > task_lock(victim); > task_unlock(victim); > dump_header(oc, victim); // second dump_header() with Victim2 > __oom_kill_process(victim, message) { > p = find_lock_task_mm(victim); > pr_err("%s: Killed process %d (%s) "...); // first kill message. > put_task_struct(p); > } > } > } > exit_mmap(); // Which frees memory. > } > } > } > } > > Maybe the better behavior is to restart out_of_memory() without dump_header() > (we can remember whether we already called dump_header() into "struct oom_control"), > with last second watermark check before select_bad_process() and after dump_header(). I understand what you mean now. But I agree with Michal that this output won't be harmful in your case. And for your case, I think Michal's suggestion that retry the victim selection would be better. -- Thanks Yafang