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=-7.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,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 61D95C433E0 for ; Mon, 13 Jul 2020 01:49:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E7B49206B6 for ; Mon, 13 Jul 2020 01:49:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qZg7ixS7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7B49206B6 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 38C158D0003; Sun, 12 Jul 2020 21:49:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 315FD8D0002; Sun, 12 Jul 2020 21:49:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E00A8D0003; Sun, 12 Jul 2020 21:49:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 03DD28D0002 for ; Sun, 12 Jul 2020 21:49:37 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 545288248047 for ; Mon, 13 Jul 2020 01:49:37 +0000 (UTC) X-FDA: 77031370794.15.shoe93_480e1a126ee4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 229311814B0C8 for ; Mon, 13 Jul 2020 01:49:37 +0000 (UTC) X-HE-Tag: shoe93_480e1a126ee4 X-Filterd-Recvd-Size: 7687 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 13 Jul 2020 01:49:36 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id v6so11829626iob.4 for ; Sun, 12 Jul 2020 18:49:36 -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:content-transfer-encoding; bh=UCgQ5OkChFctXpXHrvYqS2fAOh+viWd11lFcxLhVv70=; b=qZg7ixS7tk+RWK/Qp6mI8RJyBT93Jprv/Nt3c9e+iAsOLuO+t2387QP4Z3jwm3hAV9 leQcRYeEv2BwFEZt4tnoek/l94C8gK0qHTI0uM26YlEQCpPCFaPLYwmnYiPNBeGjo+1r mnVIV6UzED2ZO6Cr4kP+zgdE+APXrQGu0rVmh9F0igzvR84885uFN/1AGDIe6gMGxCVF WjeMpzu/D3zjA/+aQ6xq3FAVStdVUN/t5uUkayDIjzcMsBnVPHTLzfqRjtfV/J7Sapkw JkeXLqdnWvjdHgK2v7nusHcyNV9bZRIVXAWLaqy0KwKqvdcacktZJ/T1evyqrsrb+I/F cbow== 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:content-transfer-encoding; bh=UCgQ5OkChFctXpXHrvYqS2fAOh+viWd11lFcxLhVv70=; b=Uxq8zbjSAzY6pkZLAVUuBo1/jSct9VgiGIymOrxGgjOn1mFt3rfVlzPp27xA/Rn4Ej GuOdl6pj8W8DdmNenaeAiF3ex9zKy3KVD38wqZEmTjKmXPRHQz9jwfjtpl9ocwmJQOYi i/GQ+ikfLZHOrnCOZXOgaAh0QGGw9yoxoIyCHXwLzQEV8IJa8fU1RFr1swdMUjyDKXNY F680/jXAQ/KKMZdfYGEVAtoyqWlthrRnPgBotgqFZupcTIzi/Euasw4W6PVeKa6fDdsy bU+0yL/7AMHHTGcojUSIEPB3DO6ai0XCNisKQE3jD+vovP0Dvg4tUPDHaRiYeWcspQuK 7xbg== X-Gm-Message-State: AOAM532M+pi0xu+O1VLCB3bjlUchVvQGkP6uwIMbooRI8BLH855v7uPR gHj2HiAjNLNTlCkMeiaXN3PzR2F7a6k96Hvly9Q= X-Google-Smtp-Source: ABdhPJz46PulmRo4JCRnlh8JcJ/1jHzGCXBxdJA2NCgzUw0WXnc7jAxK9MRNA3uGHqO09X2gboHPO/Fof6tl0TDQScI= X-Received: by 2002:a6b:c343:: with SMTP id t64mr4349756iof.66.1594604975937; Sun, 12 Jul 2020 18:49:35 -0700 (PDT) MIME-Version: 1.0 References: <1594396651-9931-1-git-send-email-laoar.shao@gmail.com> In-Reply-To: From: Yafang Shao Date: Mon, 13 Jul 2020 09:49:00 +0800 Message-ID: Subject: Re: [PATCH v3] mm, oom: make the calculation of oom badness more accurate To: Naresh Kamboju Cc: Michal Hocko , Qian Cai , David Rientjes , Andrew Morton , linux-mm , Stephen Rothwell , Linux-Next Mailing List , open list , lkft-triage@lists.linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 229311814B0C8 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 13, 2020 at 2:34 AM Naresh Kamboju wrote: > > On Fri, 10 Jul 2020 at 21:28, Yafang Shao wrote: > > > > Recently we found an issue on our production environment that when memc= g > > oom is triggered the oom killer doesn't chose the process with largest > > resident memory but chose the first scanned process. Note that all > > processes in this memcg have the same oom_score_adj, so the oom killer > > should chose the process with largest resident memory. > > > > Bellow is part of the oom info, which is enough to analyze this issue. > > [7516987.983223] memory: usage 16777216kB, limit 16777216kB, failcnt 52= 843037 > > [7516987.983224] memory+swap: usage 16777216kB, limit 9007199254740988k= B, failcnt 0 > > [7516987.983225] kmem: usage 301464kB, limit 9007199254740988kB, failcn= t 0 > [...] > > [7516987.984221] oom-kill:constraint=3DCONSTRAINT_MEMCG,nodemask=3D(nul= l),cpuset=3D3aa16c9482ae3a6f6b78bda68a55d32c87c99b985e0f11331cddf05af6c4d75= 3,mems_allowed=3D0-1,oom_memcg=3D/kubepods/podf1c273d3-9b36-11ea-b3df-246e9= 693c184,task_memcg=3D/kubepods/podf1c273d3-9b36-11ea-b3df-246e9693c184/1f24= 6a3eeea8f70bf91141eeaf1805346a666e225f823906485ea0b6c37dfc3d,task=3Dpause,p= id=3D5740,uid=3D0 > > [7516987.984254] Memory cgroup out of memory: Killed process 5740 (paus= e) total-vm:1028kB, anon-rss:4kB, file-rss:0kB, shmem-rss:0kB > > [7516988.092344] oom_reaper: reaped process 5740 (pause), now anon-rss:= 0kB, file-rss:0kB, shmem-rss:0kB > > > > We can find that the first scanned process 5740 (pause) was killed, but= its > > rss is only one page. That is because, when we calculate the oom badnes= s in > > oom_badness(), we always ignore the negtive point and convert all of th= ese > > negtive points to 1. Now as oom_score_adj of all the processes in this > > targeted memcg have the same value -998, the points of these processes = are > > all negtive value. As a result, the first scanned process will be kille= d. > > > > The oom_socre_adj (-998) in this memcg is set by kubelet, because it is= a > > a Guaranteed pod, which has higher priority to prevent from being kille= d by > > system oom. > > > > To fix this issue, we should make the calculation of oom point more > > accurate. We can achieve it by convert the chosen_point from 'unsigned > > long' to 'long'. > > > > [cai@lca.pw: reported a issue in the previous version] > > [mhocko@suse.com: fixed the issue reported by Cai] > > [mhocko@suse.com: add the comment in proc_oom_score()] > > Signed-off-by: Yafang Shao > > Acked-by: Michal Hocko > > Cc: David Rientjes > > Cc: Qian Cai > > > > --- > > v2 -> v3: > > - fix the type of variable 'point' in oom_evaluate_task() > > - initialize oom_control->chosen_points in select_bad_process() per Mic= hal > > - update the comment in proc_oom_score() per Michal > > > > Signed-off-by: Yafang Shao > > Tested-by: Naresh Kamboju > > I have noticed kernel panic with v2 patch while running LTP mm test suite= . > > [ 63.451494] Out of memory and no killable processes... > [ 63.456633] Kernel panic - not syncing: System is deadlocked on memory > > Then I have removed the v2 patch and applied this below v3 patch and re-t= ested. > No regression noticed with v3 patch while running LTP mm on x86_64 and ar= m. > > OTOH, > oom01 test case started with 100 iterations but runltp got killed after t= he > 6th iteration [3]. I think this is expected. > > test steps: > - cd /opt/ltp > - ./runltp -s oom01 -I 100 || true > > [ 209.052842] Out of memory: Killed process 519 (runltp) > total-vm:10244kB, anon-rss:904kB, file-rss:4kB, shmem-rss:0kB, UID:0 > pgtables:60kB oom_score_adj:0 > [ 209.066782] oom_reaper: reaped process 519 (runltp), now > anon-rss:0kB, file-rss:0kB, shmem-rss:0kB > /lava-1558245/0/tests/0_prep-tmp-disk/run.sh: line 21: 519 Killed > ./runltp -s oom01 -I 100 > > > --- > > fs/proc/base.c | 11 ++++++++++- > > include/linux/oom.h | 4 ++-- > > mm/oom_kill.c | 22 ++++++++++------------ > > 3 files changed, 22 insertions(+), 15 deletions(-) > > > Reference test jobs, > [1] https://lkft.validation.linaro.org/scheduler/job/1558246#L9189 > [2] https://lkft.validation.linaro.org/scheduler/job/1558247#L17213 > [3] https://lkft.validation.linaro.org/scheduler/job/1558245#L1407 Thanks for the test, Naresh. --=20 Thanks Yafang