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.0 required=3.0 tests=INCLUDES_PATCH, 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 6621DC433E0 for ; Thu, 9 Jul 2020 08:17:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3672A2070E for ; Thu, 9 Jul 2020 08:17:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3672A2070E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A0AC36B000C; Thu, 9 Jul 2020 04:17:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 994036B000E; Thu, 9 Jul 2020 04:17:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85A716B0010; Thu, 9 Jul 2020 04:17:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 686B96B000C for ; Thu, 9 Jul 2020 04:17:11 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 172B2181AEF0B for ; Thu, 9 Jul 2020 08:17:11 +0000 (UTC) X-FDA: 77017832262.30.women20_300d03526ec4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id CF62C180B3C95 for ; Thu, 9 Jul 2020 08:17:10 +0000 (UTC) X-HE-Tag: women20_300d03526ec4 X-Filterd-Recvd-Size: 8519 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 9 Jul 2020 08:17:10 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id 17so896915wmo.1 for ; Thu, 09 Jul 2020 01:17:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=ojsjmtyqTkI+iTgfw96vqyKBpemIJlANmJU75mPnV4o=; b=gfxcwc1KU9bpmpKVCrNemoZAu38+WWqg/278lctNzxr/KbAYJ8Ki/v7JZWjyBJxuFO unigi7FLAfPSz39K5QvndAOBe6iVAFcNXSomYUI1i8zbnZL19lHOS1FWbze9c22eb5px 0Poo4OfG5RXzdpULfgQsMQQdywFkFl3j6+rW/InNUh269jl0FP9a9g57xyvBDalT0807 akw3IRMzQyw4EOjV4HfX9tB+cC0Htsi2x3f/NWVn74It9Iy+533XlDpf5zLG16tou3l+ 0BmjmDdLrWF9gUmvb56LVzK0hm/zD5pAOKwj9n7xI5E0XT/XcAKpxlVpuxwyBS4lrRff qjsQ== X-Gm-Message-State: AOAM533hy/oqN1DKa0zODvzEotWbowZ+1YXoZnrml3VxQa57TeHiT3KT aioo4Eh1qlh+LGk8kWU/wBU= X-Google-Smtp-Source: ABdhPJz0VxnJfjRsbseDV82mZgIGbGsPO4bA7gxGROr+NzWs25cDOaaF9CNAZ1V+T4QJ2CCkE0DQhA== X-Received: by 2002:a1c:96c5:: with SMTP id y188mr13454871wmd.71.1594282629189; Thu, 09 Jul 2020 01:17:09 -0700 (PDT) Received: from localhost (ip-37-188-179-51.eurotel.cz. [37.188.179.51]) by smtp.gmail.com with ESMTPSA id v5sm4484868wre.87.2020.07.09.01.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 01:17:07 -0700 (PDT) Date: Thu, 9 Jul 2020 10:17:06 +0200 From: Michal Hocko To: Yafang Shao Cc: David Rientjes , Andrew Morton , Linux MM Subject: Re: [PATCH] mm, oom: make the calculation of oom badness more accurate Message-ID: <20200709081706.GC19160@dhcp22.suse.cz> References: <1594214649-9837-1-git-send-email-laoar.shao@gmail.com> <20200708142806.GJ7271@dhcp22.suse.cz> <20200708143211.GK7271@dhcp22.suse.cz> <20200708190225.GM7271@dhcp22.suse.cz> <20200709062644.GA12704@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: CF62C180B3C95 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable 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 Thu 09-07-20 15:31:23, Yafang Shao wrote: > On Thu, Jul 9, 2020 at 2:26 PM Michal Hocko wrote: > > > > On Thu 09-07-20 10:14:14, Yafang Shao wrote: > > > On Thu, Jul 9, 2020 at 3:02 AM Michal Hocko wro= te: > > > > > > > > On Wed 08-07-20 10:57:27, David Rientjes wrote: > > > > > On Wed, 8 Jul 2020, Michal Hocko wrote: > > > > > > > > > > > I have only now realized that David is not on Cc. Add him her= e. The > > > > > > patch is http://lkml.kernel.org/r/1594214649-9837-1-git-send-= email-laoar.shao@gmail.com. > > > > > > > > > > > > I believe the main problem is that we are normalizing to oom_= score_adj > > > > > > units rather than usage/total. I have a very vague recollecti= on this has > > > > > > been done in the past but I didn't get to dig into details ye= t. > > > > > > > > > > > > > > > > The memcg max is 4194304 pages, and an oom_score_adj of -998 wo= uld yield a > > > > > page adjustment of: > > > > > > > > > > adj =3D -998 * 4194304 / 1000 =3D =E2=88=924185915 pages > > > > > > > > > > The largest pid 58406 (data_sim) has rss 3967322 pages, > > > > > pgtables 37101568 / 4096 =3D 9058 pages, and swapents 0. So it= 's unadjusted > > > > > badness is > > > > > > > > > > 3967322 + 9058 pages =3D 3976380 pages > > > > > > > > > > Factoring in oom_score_adj, all of these processes will have a = badness of > > > > > 1 because oom_badness() doesn't underflow, which I think is the= point of > > > > > Yafang's proposal. > > > > > > > > > > I think the patch can work but, as you mention, also needs an u= pdate to > > > > > proc_oom_score(). proc_oom_score() is using the global amount = of memory > > > > > so Yafang is likely not seeing it go negative for that reason b= ut it could > > > > > happen. > > > > > > > > Yes, memcg just makes it more obvious but the same might happen f= or the > > > > global case. I am not sure how we can both alow underflow and pre= sent > > > > the value that would fit the existing model. The exported value s= hould > > > > really reflect what the oom killer is using for the calculation o= r we > > > > are going to see discrepancies between the real oom decision and > > > > presented values. So I believe we really have to change the calcu= lation > > > > rather than just make it tolerant to underflows. > > > > > > > > > > Hi Michal, > > > > > > - Before my patch, > > > The result of oom_badness() is [1, 2 * totalpages), > > > and the result of proc_oom_score() is [0, 2000). > > > > > > While the badness score in the Documentation/filesystems/proc.rst i= s: [0, 1000] > > > "The badness heuristic assigns a value to each candidate task rangi= ng from 0 > > > (never kill) to 1000 (always kill) to determine which process is ta= rgeted" > > > > > > That means, we need to update the documentation anyway unless my > > > calculation is wrong. > > > > No, your calculation is correct. The documentation is correct albeit > > slightly misleading. The net score calculation is indeed in range of = [0, 1000]. > > It is the oom_score_adj added on top which skews it. This is document= ed > > as > > "The value of /proc//oom_score_adj is added to the badness score= before it > > is used to determine which task to kill." > > > > This is the exported value but paragraph "3.2 /proc//oom_score" = only says > > "This file can be used to check the current score used by the oom-kil= ler is for > > any given ." which is not really explicit about the exported ran= ge. > > > > Maybe clarifying that would be helpful. I will post a patch. There ar= e > > few other things to sync up with the current state. > > > > > So the point will be how to change it ? > > > > > > - After my patch > > > oom_badness(): (-totalpages, 2 * totalpages) > > > proc_oom_score(): (-1000, 2000) > > > > > > If we allow underflow, we can change the documentation as "from -10= 00 > > > (never kill) to 2000(always kill)". > > > While if we don't allow underflow, we can make bellow simple chang= e, > > > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > > index 774784587..0da8efa41 100644 > > > --- a/fs/proc/base.c > > > +++ b/fs/proc/base.c > > > @@ -528,7 +528,7 @@ static int proc_oom_score(struct seq_file *m, > > > struct pid_namespace *ns, > > > unsigned long totalpages =3D totalram_pages + total_swap_pa= ges; > > > unsigned long points =3D 0; > > > > > > - points =3D oom_badness(task, NULL, NULL, totalpages) * > > > + points =3D 1000 + oom_badness(task, NULL, NULL, totalpages)= * > > > 1000 / totalpages; > > > seq_printf(m, "%lu\n", points); > > > > > > And then update the documentation as "from 0 (never kill) to 3000 > > > (always kill)" > > > > This is still not quite there yet, I am afraid. OOM_SCORE_ADJ_MIN tas= ks have > > always reported 0 and I can imagine somebody might depend on this fac= t. >=20 > No, I don't think anybody will use the reported 0 to get the > conclusion that it is a OOM_SCORE_ADJ_MIN task. > Because, > points =3D oom_badness(task, totalpages) * 1000 / totalpages; > so the points will always be 0 if the return value of > oom_badness(task, totalpages) is less than totalpages/1000. Correct, I've had the other implication in mind though. OOM_SCORE_ADJ_MIN -> score =3D=3D 0 > If the user wants to know whether it is an OOM_SCORE_ADJ_MIN task, he > will always use /proc/[pid]/oom_score_adj to get it, that is more > reliable. >=20 > > So you need to special case LONG_MIN at least. It would be also bette= r > > to stick with [0, 2000] range. >=20 > I don't know why it must stick with [0, 2000] range. Because this is a long term exported API and userspace might depend on it. --=20 Michal Hocko SUSE Labs