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=-2.5 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 1CD2BC43603 for ; Fri, 20 Dec 2019 11:37:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B6DA524680 for ; Fri, 20 Dec 2019 11:37:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6DA524680 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 06A8B8E0196; Fri, 20 Dec 2019 06:37:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 018BA8E0184; Fri, 20 Dec 2019 06:37:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFD428E0196; Fri, 20 Dec 2019 06:37:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id C76A38E0184 for ; Fri, 20 Dec 2019 06:37:48 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 6AFCB181AEF15 for ; Fri, 20 Dec 2019 11:37:48 +0000 (UTC) X-FDA: 76285320216.11.quill80_7e4b97aa5d637 X-HE-Tag: quill80_7e4b97aa5d637 X-Filterd-Recvd-Size: 5361 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Dec 2019 11:37:47 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id a5so8606582wmb.0 for ; Fri, 20 Dec 2019 03:37:47 -0800 (PST) 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:user-agent; bh=+xqrG/Fr+lk5K0m1pptDnTQOO1AdoG749ulUXApgoJo=; b=FNb+Gi79yh83dfxs2FOM/W0D6OUpPTc2fat0XhDs0nPUPLD8OddgGZl3HOmPMrew6M 1Hb6pE/4dlrmL6xNWXL9Xj0ON2J/W8z4BdKDThBGCt4aBd57fYsAp21GKUCoBRwLrmDS QM5BsO2HLl6PlEpsLgq3NjUOvh9p2/cUyjbPbWMayitKhx2lEMqLPDRO6cFIMFdrE1/4 ugx4fW2LE9gNM5AVl8A4MfL51pH6Idm8suwS/dorigLVBRxpNKOweHr7JsIV8OD6xAlA WuBDveeXzihoO/o5YI84msDJEN8KqOzBi6UlmnVDQRMSfBF0JgF4FStOKv3kXol4cBBE fwrg== X-Gm-Message-State: APjAAAWw1x60kNJg9XOc4HY8qLRa5FTatITDhE0y4ITs5SOXJxlpbMv+ Dyk61BjLANcV8MooSdVKTXo= X-Google-Smtp-Source: APXvYqxea3sQYL0zemf/BDfh/Fngl+lzOAoLU0x312PESG6f2yo0GmWBhUf3frSoVwbx7/PQps66Kg== X-Received: by 2002:a1c:638a:: with SMTP id x132mr16983341wmb.43.1576841866625; Fri, 20 Dec 2019 03:37:46 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id f1sm9955905wrp.93.2019.12.20.03.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 03:37:45 -0800 (PST) Date: Fri, 20 Dec 2019 12:37:44 +0100 From: Michal Hocko To: =?utf-8?B?5b2t5b+X5Yia?= Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, zgpeng Subject: Re: [PATCH] oom: choose a more suitable process to kill while all processes are not killable Message-ID: <20191220113744.GF20332@dhcp22.suse.cz> References: <1576823172-25943-1-git-send-email-zgpeng.linux@gmail.com> <20191220071334.GB20332@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) 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: [Please do not top post] On Fri 20-12-19 17:56:20, =E5=BD=AD=E5=BF=97=E5=88=9A wrote: > certainly. >=20 > Steps to reproduce: > (1)Create a mm cgroup and set memory.limit_in_bytes > (2)Move the bash process to the newly created cgroup, and set the > oom_score_adj of the bash process to -998. > (3)In bash, start multiple processes, each process consumes different > memory until cgroup oom is triggered. >=20 > The triggered phenomenon is shown below. We can see that when cgroup oo= m > happened, process 23777 was killed, but in fact, 23772 consumes more me= mory; >=20 > [ 591.000970] Tasks state (memory values in pages): > [ 591.000970] [ pid ] uid tgid total_vm rss pgtables_bytes s= wapents oom_score_adj name > [ 591.000973] [ 23344] 0 23344 2863 923 61440 = 0 -998 bash > [ 591.000975] [ 23714] 0 23714 27522 25935 258048 = 0 -998 test > [ 591.000976] [ 23772] 0 23772 104622 103032 876544 = 0 -998 test points =3D 103032 + 0 + 876544/4096 =3D 103246 > [ 591.000978] [ 23777] 0 23777 78922 77335 667648 = 0 -998 test points =3D 77335 + 0 + 667648/4096 =3D 77498 It is not clear what is the actual hard limit but let's assume that rss+page_tables is the only charged memory (or at least the majority of it). That would be 207680 so the normalized oom_score_adj would be -206586 which is way too big for both tasks so from the OOM killer perspective both tasks are equal. The question is whether this is a bug or a (mis)feature. The oom_score_adj je documented as follows: Documentation/filesystems/proc.txt : Consequently, it is very simple for userspace to define the amount of m= emory to : consider for each task. Setting a /proc//oom_score_adj value of += 500, for : example, is roughly equivalent to allowing the remainder of tasks shari= ng the : same system, cpuset, mempolicy, or memory controller resources to use a= t least : 50% more memory. A value of -500, on the other hand, would be roughly : equivalent to discounting 50% of the task's allowed memory from being c= onsidered : as scoring against the task. Which implies that we are talking about the budget based on a usable memory (aka hard limit in this case). I do agree that the semantic is awkward. I know there are usecases which try to use the existing scheme for oom_score_adj to fine tune oom decisions and I am worried your patch might break those. That being said, I am not sure this change is safe wrt. to backward compatibility. I would rather recommend to not using oom_score_adj for anything but OOM_SCORE_ADJ_MIN resp OOM_SCORE_ADJ_MAX. --=20 Michal Hocko SUSE Labs