Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1093192rwb; Thu, 8 Dec 2022 06:43:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HbBi4L5EuAHYXTNVlyI+oI/1+bcL0DG5Br8Ul/1yA93py/HxyofbMPdeawP+XIA5s3zYo X-Received: by 2002:a17:906:15ca:b0:7a5:7c1c:cc5c with SMTP id l10-20020a17090615ca00b007a57c1ccc5cmr78473706ejd.644.1670510599426; Thu, 08 Dec 2022 06:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670510599; cv=none; d=google.com; s=arc-20160816; b=arA4xGTYEcFnyMpfXJaNdX9CFKV8wd82OeETBWoneHh6MFpXc9UVcWiGxhoAn9TEGJ /QaAgNbsBwSIfVs07CCoGXd5xCKpdzrILijlAbF+WI+yyySgYaHkAYLJe/d//cZ3h43u O3pCMyL30O75ZZomK0Cf8E1WCgKlEwLG8ll7405mBcFPBCfFjsyycrJKwhCByUY0XpFs DwGWSGBnbIDGrKPRegkTf1KfrTHfloRSOeT6LJHmYl9BsRAJPhaH1t0CYfsZ5B3rsSUp gYJZVNfyRiE4XV6IvHuHPZXU1UpQbMXDoDxmh/kV464Oj5oTyeGGQCwnSH3d3bM6LKw6 8V/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=DX6YDzb8PyIKMrTf468EmhvBSzk6iJctUJatHJ6cuIA=; b=Y29zhFOUOdD/S94qod6/flO1ibuTpUq3jEyMOfh0nP1+qtz1kFGPxqhmmLqlP+91Q1 yvG/e4hYQh3n7NhgJF3486lbpBbRH8+UnBaVSkDy73z3VEsgh+w/Fi9Po0ZIw9SmQT2k gkJ+IF7WwQfWEiJ1pkevsuJhS7vMWfkZQO7rZjfpM9tsAgd9BqnFoYhw5OtvD/Z0ArIW jzdCjBbSF8utg+QQ37uilXiuG7jabGGat2R3ygB/hS4fos0ELvOaPeoqjGjilLFcb/2o 8cm/o3Io7ygRK1ytIBRG2HFCDOst/zag7tI41qRoFKzflIFrsSWMhTFT01l4k0BQOukw C0pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Qz7O1fJU; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs3-20020a1709073e8300b007be1d7d1c22si22034357ejc.32.2022.12.08.06.43.01; Thu, 08 Dec 2022 06:43:19 -0800 (PST) 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=@suse.com header.s=susede1 header.b=Qz7O1fJU; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiLHOZJ (ORCPT + 72 others); Thu, 8 Dec 2022 09:25:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbiLHOYp (ORCPT ); Thu, 8 Dec 2022 09:24:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B50C45080; Thu, 8 Dec 2022 06:23:58 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3F65B208CE; Thu, 8 Dec 2022 14:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1670509437; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DX6YDzb8PyIKMrTf468EmhvBSzk6iJctUJatHJ6cuIA=; b=Qz7O1fJU8HHKKGBJmw8kfV/cErZ0iiN4f0bZfE5jsTRKpgLCCwWA2WlbQKYkLPlqYUsdIv QL4Tw0VatsYd6IlM50vHZ/Vh+5Gf/HUmlVUUZOZbte/Xefcdyd2eJjwb7GOYwzbCqbDOFp u3emrcIcxK2r4dEtCLvHkYxAVTnsGc0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1574913416; Thu, 8 Dec 2022 14:23:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SgCvBH3zkWODbAAAMHmgww (envelope-from ); Thu, 08 Dec 2022 14:23:57 +0000 Date: Thu, 8 Dec 2022 15:23:56 +0100 From: Michal Hocko To: =?utf-8?B?56iL5Z6y5rab?= Chengkaitao Cheng Cc: chengkaitao , "tj@kernel.org" , "lizefan.x@bytedance.com" , "hannes@cmpxchg.org" , "corbet@lwn.net" , "roman.gushchin@linux.dev" , "shakeelb@google.com" , "akpm@linux-foundation.org" , "songmuchun@bytedance.com" , "viro@zeniv.linux.org.uk" , "zhengqi.arch@bytedance.com" , "ebiederm@xmission.com" , "Liam.Howlett@oracle.com" , "chengzhihao1@huawei.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" , "sujiaxun@uniontech.com" , "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" Subject: Re: [PATCH v2] mm: memcontrol: protect the memory in cgroup from being oom killed Message-ID: References: <3E260DAC-2E2F-48B7-98BB-036EF0A423DC@didiglobal.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3E260DAC-2E2F-48B7-98BB-036EF0A423DC@didiglobal.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 Thu 08-12-22 14:07:06, 程垲涛 Chengkaitao Cheng wrote: > At 2022-12-08 16:14:10, "Michal Hocko" wrote: > >On Thu 08-12-22 07:59:27, 程垲涛 Chengkaitao Cheng wrote: > >> At 2022-12-08 15:33:07, "Michal Hocko" wrote: > >> >On Thu 08-12-22 11:46:44, chengkaitao wrote: > >> >> From: chengkaitao > >> >> > >> >> We created a new interface for memory, If there is > >> >> the OOM killer under parent memory cgroup, and the memory usage of a > >> >> child cgroup is within its effective oom.protect boundary, the cgroup's > >> >> tasks won't be OOM killed unless there is no unprotected tasks in other > >> >> children cgroups. It draws on the logic of in the > >> >> inheritance relationship. > >> >> > >> >> It has the following advantages, > >> >> 1. We have the ability to protect more important processes, when there > >> >> is a memcg's OOM killer. The oom.protect only takes effect local memcg, > >> >> and does not affect the OOM killer of the host. > >> >> 2. Historically, we can often use oom_score_adj to control a group of > >> >> processes, It requires that all processes in the cgroup must have a > >> >> common parent processes, we have to set the common parent process's > >> >> oom_score_adj, before it forks all children processes. So that it is > >> >> very difficult to apply it in other situations. Now oom.protect has no > >> >> such restrictions, we can protect a cgroup of processes more easily. The > >> >> cgroup can keep some memory, even if the OOM killer has to be called. > >> >> > >> >> Signed-off-by: chengkaitao > >> >> --- > >> >> v2: Modify the formula of the process request memcg protection quota. > >> > > >> >The new formula doesn't really address concerns expressed previously. > >> >Please read my feedback carefully again and follow up with questions if > >> >something is not clear. > >> > >> The previous discussion was quite scattered. Can you help me summarize > >> your concerns again? > > > >The most important part is http://lkml.kernel.org/r/Y4jFnY7kMdB8ReSW@dhcp22.suse.cz > >: Let me just emphasise that we are talking about fundamental disconnect. > >: Rss based accounting has been used for the OOM killer selection because > >: the memory gets unmapped and _potentially_ freed when the process goes > >: away. Memcg changes are bound to the object life time and as said in > >: many cases there is no direct relation with any process life time. > > > We need to discuss the relationship between memcg's mem and process's mem, > > task_usage = task_anon(rss_anon) + task_mapped_file(rss_file) > + task_mapped_share(rss_share) + task_pgtables + task_swapents > > memcg_usage = memcg_anon + memcg_file + memcg_pgtables + memcg_share > = all_task_anon + all_task_mapped_file + all_task_mapped_share > + all_task_pgtables + unmapped_file + unmapped_share > = all_task_usage + unmapped_file + unmapped_share - all_task_swapents You are missing all the kernel charged objects (aka __GFP_ACCOUNT allocations resp. SLAB_ACCOUNT for slab caches). Depending on the workload this can be really a very noticeable portion. So not this is not just about unmapped cache or shm. > >That is to the per-process discount based on rss or any per-process > >memory metrics. > > > >Another really important question is the actual configurability. The > >hierarchical protection has to be enforced and that means that same as > >memory reclaim protection it has to be enforced top-to-bottom in the > >cgroup hierarchy. That makes the oom protection rather non-trivial to > >configure without having a good picture of a larger part of the cgroup > >hierarchy as it cannot be tuned based on a reclaim feedback. > > There is an essential difference between reclaim and oom killer. oom killer is a memory reclaim of the last resort. So yes, there is some difference but fundamentally it is about releasing some memory. And long term we have learned that the more clever it tries to be the more likely corner cases can happen. It is simply impossible to know the best candidate so this is a just a best effort. We try to aim for predictability at least. > The reclaim > cannot be directly perceived by users, I very strongly disagree with this statement. First the direct reclaim is a direct source of latencies because the work is done on behalf of the allocating process. There are side effect possible as well because refaults have their cost as well. > so memcg need to count indicators > similar to pgscan_(kswapd/direct). However, when the user process is killed > by oom killer, users can clearly perceive and count (such as the number of > restarts of a certain type of process). At the same time, the kernel also has > memory.events to count some information about the oom killer, which can > also be used for feedback adjustment. Yes we have those metrics already. I suspect I haven't made myself clear. I didn't say there are no measures to see how oom behaves. What I've said that I _suspect_ that oom protection would be really hard to configure correctly because unlike the memory reclaim which happens during the normal operation, oom is a relatively rare event and it is quite hard to use it for any feedback mechanisms. But I am really open to be convinced otherwise and this is in fact what I have been asking for since the beginning. I would love to see some examples on the reasonable configuration for a practical usecase. It is one thing to say that you can set the protection to a certain value and a different one to have a way to determine that value. See my point? -- Michal Hocko SUSE Labs