Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29273rwd; Wed, 17 May 2023 14:08:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mxdrTsrQJWsF4eRS37BuLZW+CWoZcSk+V92HW6Vn2BICmKQW5pOT95YiloS7KLNiH44zC X-Received: by 2002:a05:6a21:9011:b0:f2:bfe1:4867 with SMTP id tq17-20020a056a21901100b000f2bfe14867mr44720923pzb.17.1684357688786; Wed, 17 May 2023 14:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684357688; cv=none; d=google.com; s=arc-20160816; b=eppohsJa0l15R2tU4a6e2AhEP2EmdPXs3QbM5jp1WW7Mb06pbO8atLIrlTHSL+eNL9 mFESfRaeQgCnSokrXD/AZWzrrP32S1FJwnNHdrwh80PB21vl/Nv7E+FU0SN2cufuSclk hc3hZQFEwsIE8eKjl+tuKdgfqSBqamceH7sT0DBrtLgiLnIszLgMy/yadUiJ1ORp1sbB FSINaaxHgVSDt1qfj/yoQ69LCyJstw1mFtcQuighghWhKY2t2BAY+89HZiINU+ECZiWu LwTDV7frcdfNXm8co1VQTPKTgg7U0fzrrFSoPxSZf4gmmG25w9LEy+Qt9LtDkMzVT88N 6KUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CvCkfJyXdBizSrj+S1CIuIjHPj7mR2pZW70tMG5/ENw=; b=0vVViyH+0VItB9JKSlpRRq60liz3oMshMB/tPjnjMC7VcLEYTl9CVDAwSLYHTgHa5V 7Rg+VWzlzULRmm/9Qeu+LOp0Q9wzl84r8GCdM9xM+WIQ2VDUvC+xb5GgfpFAvgPyWsdg EjyXZXtCCJRhk4drGAR/12ckwjA/YpXsIouArRPMlwE7i19MRHm3uyZvD0ogIPUJK4Cj hgJFKfwK4lyM703+fcVzwzDulgye4ze37X/ZWC5cV1tNxfYI2qKiYHhMAMxfzaMdfIPS HeYlqKNKpvqpCSoc+5Be9zuLgpd4ctrl0vSlwxNzLIdojaISnzVFHsNUVVrYrTiLBYRw DqTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=k1ibNgQ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020a637313000000b0051b37c000dcsi16600986pgc.81.2023.05.17.14.07.54; Wed, 17 May 2023 14:08:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=k1ibNgQ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbjEQUnU (ORCPT + 99 others); Wed, 17 May 2023 16:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjEQUnS (ORCPT ); Wed, 17 May 2023 16:43:18 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 338AC6195 for ; Wed, 17 May 2023 13:42:50 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-965e93f915aso229410166b.2 for ; Wed, 17 May 2023 13:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684356168; x=1686948168; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CvCkfJyXdBizSrj+S1CIuIjHPj7mR2pZW70tMG5/ENw=; b=k1ibNgQ1aq28Dhp9cGBlgSxQJ7lbc/VdbcXrDj0eAoSPCEx1xcoDbcgMCSEqtIEIKI 3GPic5hMCSaX21aJvzjbvjDyMc8l0sqejX2otxM8GSrW6JWPtr/4f8YtHld2rn1dnUBx k+aSQCrSTdfmO5gim5Lnq9Ve8U1YlVehAWMGpz0+oufZ424aTfD8G852MYX5GuYYjS21 vsrdXtzfvgk/1X5CChW00yaz0QHjQVFPesWj0npLjj185JeKtvibvT3TRJg1tejKzou7 gemYCK9U2mfESleEXZ1k2GewsSh30YnAmHtuHgyWG99vSxr6pMWI54GUX+JThPbOoTqA IbpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684356168; x=1686948168; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CvCkfJyXdBizSrj+S1CIuIjHPj7mR2pZW70tMG5/ENw=; b=fxxGRtj3fG69azfbtCf00WE43HZp+u8ukA4DG4hRL2QPjEmCQLuvzJxqhlsAeflUss zm0yaZWTYXhpRxGz+OEdom29x8IGEpDlooJ1nGKJRwFA2Ds+soN4C5hRuXX/5Mo4lVPd wxdNlfuOVQlVtDI0Um4BKc967RkJnNrEGyMYC4y8bguOrQ71r3pr3MkeTfrpOLw5+STu JsmbQMhr/QlKFz0UDGdWMX6N8i/wyfzlBvliuEL6e2RpHB4eDzIvaVoYvasz3lovEVE8 dqjKR+VujutHIsYaeuSe81e26zCTkh2Ow9XUHgwtRzBnekVLtrFUdc19KuQm4CYcu/Li JW6A== X-Gm-Message-State: AC+VfDzeLNwy4o7vEc9W3+K8B8G5wmVD8v5KtlmCSeJeBy7f5j3KpipS bywqzd+hCjZsuu5I2RxTHS+gf2UunzMWAhqIfnVBuQ== X-Received: by 2002:a17:907:9485:b0:96a:b12d:2fdf with SMTP id dm5-20020a170907948500b0096ab12d2fdfmr17122192ejc.12.1684356168500; Wed, 17 May 2023 13:42:48 -0700 (PDT) MIME-Version: 1.0 References: <6AB7FF12-F855-4D5B-9F75-9F7D64823144@didiglobal.com> In-Reply-To: <6AB7FF12-F855-4D5B-9F75-9F7D64823144@didiglobal.com> From: Yosry Ahmed Date: Wed, 17 May 2023 13:42:12 -0700 Message-ID: Subject: Re: [PATCH v4 0/2] memcontrol: support cgroup level OOM protection To: =?UTF-8?B?56iL5Z6y5rabIENoZW5na2FpdGFvIENoZW5n?= Cc: "tj@kernel.org" , "lizefan.x@bytedance.com" , "hannes@cmpxchg.org" , "corbet@lwn.net" , "mhocko@kernel.org" , "roman.gushchin@linux.dev" , "shakeelb@google.com" , "akpm@linux-foundation.org" , "brauner@kernel.org" , "muchun.song@linux.dev" , "viro@zeniv.linux.org.uk" , "zhengqi.arch@bytedance.com" , "ebiederm@xmission.com" , "Liam.Howlett@oracle.com" , "chengzhihao1@huawei.com" , "pilgrimtao@gmail.com" , "haolee.swjtu@gmail.com" , "yuzhao@google.com" , "willy@infradead.org" , "vasily.averin@linux.dev" , "vbabka@suse.cz" , "surenb@google.com" , "sfr@canb.auug.org.au" , "mcgrof@kernel.org" , "feng.tang@intel.com" , "cgroups@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , David Rientjes Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 17, 2023 at 3:01=E2=80=AFAM =E7=A8=8B=E5=9E=B2=E6=B6=9B Chengka= itao Cheng wrote: > > At 2023-05-17 16:09:50, "Yosry Ahmed" wrote: > >On Wed, May 17, 2023 at 1:01=E2=80=AFAM =E7=A8=8B=E5=9E=B2=E6=B6=9B Chen= gkaitao Cheng > > wrote: > >> > >> At 2023-05-17 14:59:06, "Yosry Ahmed" wrote: > >> >+David Rientjes > >> > > >> >On Tue, May 16, 2023 at 8:20=E2=80=AFPM chengkaitao wrote: > >> >> > >> >> Establish a new OOM score algorithm, supports the cgroup level OOM > >> >> protection mechanism. When an global/memcg oom event occurs, we tre= at > >> >> all processes in the cgroup as a whole, and OOM killers need to sel= ect > >> >> the process to kill based on the protection quota of the cgroup. > >> >> > >> > > >> >Perhaps this is only slightly relevant, but at Google we do have a > >> >different per-memcg approach to protect from OOM kills, or more > >> >specifically tell the kernel how we would like the OOM killer to > >> >behave. > >> > > >> >We define an interface called memory.oom_score_badness, and we also > >> >allow it to be specified per-process through a procfs interface, > >> >similar to oom_score_adj. > >> > > >> >These scores essentially tell the OOM killer the order in which we > >> >prefer memcgs to be OOM'd, and the order in which we want processes i= n > >> >the memcg to be OOM'd. By default, all processes and memcgs start wit= h > >> >the same score. Ties are broken based on the rss of the process or th= e > >> >usage of the memcg (prefer to kill the process/memcg that will free > >> >more memory) -- similar to the current OOM killer. > >> > >> Thank you for providing a new application scenario. You have described= a > >> new per-memcg approach, but a simple introduction cannot explain the > >> details of your approach clearly. If you could compare and analyze my > >> patches for possible defects, or if your new approach has advantages > >> that my patches do not have, I would greatly appreciate it. > > > >Sorry if I was not clear, I am not implying in any way that the > >approach I am describing is better than your patches. I am guilty of > >not conducting the proper analysis you are requesting. > > There is no perfect approach in the world, and I also seek your advice wi= th > a learning attitude. You don't need to say sorry, I should say thank you. > > >I just saw the thread and thought it might be interesting to you or > >others to know the approach that we have been using for years in our > >production. I guess the target is the same, be able to tell the OOM > >killer which memcgs/processes are more important to protect. The > >fundamental difference is that instead of tuning this based on the > >memory usage of the memcg (your approach), we essentially give the OOM > >killer the ordering in which we want memcgs/processes to be OOM > >killed. This maps to jobs priorities essentially. > > Killing processes in order of memory usage cannot effectively protect > important processes. Killing processes in a user-defined priority order > will result in a large number of OOM events and still not being able to > release enough memory. I have been searching for a balance between > the two methods, so that their shortcomings are not too obvious. > The biggest advantage of memcg is its tree topology, and I also hope > to make good use of it. For us, killing processes in a user-defined priority order works well. It seems like to tune memory.oom.protect you use oom_kill_inherit to observe how many times this memcg has been killed due to a limit in an ancestor. Wouldn't it be more straightforward to specify the priority of protections among memcgs? For example, if you observe multiple memcgs being OOM killed due to hitting an ancestor limit, you will need to decide which of them to increase memory.oom.protect for more, based on their importance. Otherwise, if you increase all of them, then there is no point if all the memory is protected, right? In this case, wouldn't it be easier to just tell the OOM killer the relative priority among the memcgs? > > >If this approach works for you (or any other audience), that's great, > >I can share more details and perhaps we can reach something that we > >can both use :) > > If you have a good idea, please share more details or show some code. > I would greatly appreciate it The code we have needs to be rebased onto a different version and cleaned up before it can be shared, but essentially it is as described. (a) All processes and memcgs start with a default score. (b) Userspace can specify scores for memcgs and processes. A higher score means higher priority (aka less score gets killed first). (c) The OOM killer essentially looks for the memcg with the lowest scores to kill, then among this memcg, it looks for the process with the lowest score. Ties are broken based on usage, so essentially if all processes/memcgs have the default score, we fallback to the current OOM behavior. > > >> > >> >This has been brought up before in other discussions without much > >> >interest [1], but just thought it may be relevant here. > >> > > >> >[1]https://lore.kernel.org/lkml/CAHS8izN3ej1mqUpnNQ8c-1Bx5EeO7q5NOkh0= qrY_4PLqc8rkHA@mail.gmail.com/#t > > -- > Thanks for your comment! > chengkaitao >