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.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 C2C42C55189 for ; Wed, 22 Apr 2020 11:51:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F10D2077D for ; Wed, 22 Apr 2020 11:51:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F10D2077D 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 1377C8E0011; Wed, 22 Apr 2020 07:51:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E7EA8E0003; Wed, 22 Apr 2020 07:51:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3F248E0011; Wed, 22 Apr 2020 07:51:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id DA5518E0003 for ; Wed, 22 Apr 2020 07:51:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 921A5181AEF07 for ; Wed, 22 Apr 2020 11:51:50 +0000 (UTC) X-FDA: 76735326780.16.soap82_2d2a36a28c91d X-HE-Tag: soap82_2d2a36a28c91d X-Filterd-Recvd-Size: 6303 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 11:51:50 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id u16so1996373wmc.5 for ; Wed, 22 Apr 2020 04:51:50 -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:in-reply-to; bh=4h6ssWCTxrZbvBMY6xRZuwtkqVFu4DjgTloBy9J6QRo=; b=nlNSJLhvlQhn0tSWiOqE+cbZlNMjHHd4TrwT4cA42Qz5sKsMYVtC79BWnBM4PYiiM0 /qiqcAPdmcbwo8PUtB6DKf0weYToAG5QoMaCYWT/jeYj9RjWm7iEb/j7HS23OJU4w/lm L3WGyyU5YxIDqJV4K/6alusJx8vNn3CdvS8yggQqs3fCrGesGzT7sZrRh35/EwZ3E1pv Z4PbTQpfgINBAHV3YaeR6RnUFr/IN87zv7dSNLPqU+TCRfG7M1sZwVFXjavY4HcnQ3g3 Q2myUMtdBhtXlishdYO4Fif0bX1QbddcfPKZ99X2FM6Fwu6khXwIaXggOShJ8Kxi8Mi3 VXnA== X-Gm-Message-State: AGi0Pub2hdonEEz0LVvWvfEZN7Yl7PiqTGTLz818x2YNzXrTXW1bmkm3 2KwB17BjMf3xDpYv5fK6McA= X-Google-Smtp-Source: APiQypKTDYZcK9dTP/rol4C297BTMN1dAf0ysWEo9mmwNRJYJGkd8lpvWVvv4rCZmZT9gawNUlTYfA== X-Received: by 2002:a1c:4085:: with SMTP id n127mr10766770wma.163.1587556309270; Wed, 22 Apr 2020 04:51:49 -0700 (PDT) Received: from localhost (ip-37-188-130-62.eurotel.cz. [37.188.130.62]) by smtp.gmail.com with ESMTPSA id v1sm7799356wrv.19.2020.04.22.04.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 04:51:48 -0700 (PDT) Date: Wed, 22 Apr 2020 13:51:47 +0200 From: Michal Hocko To: Yafang Shao Cc: akpm@linux-foundation.org, linux-mm@kvack.org, Chris Down , Shakeel Butt , Johannes Weiner Subject: Re: [PATCH v2] mm, memcg: fix inconsistent oom event behavior Message-ID: <20200422115147.GE30312@dhcp22.suse.cz> References: <20200422110643.15725-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422110643.15725-1-laoar.shao@gmail.com> 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 Wed 22-04-20 07:06:43, Yafang Shao wrote: > A recent commit 9852ae3fe529 ("mm, memcg: consider subtrees in > memory.events") changes the behavior of memcg events, which will > consider subtrees in memory.events. But oom_kill event is a special one > as it is used in both cgroup1 and cgroup2. In cgroup1, it is displayed > in memory.oom_control. The file memory.oom_control is in both root memcg > and non root memcg, that is different with memory.event as it only in > non-root memcg. That commit is okay for cgroup2, but it is not okay for > cgroup1 as it will cause inconsistent behavior between root memcg and > non-root memcg. > > Here's an example on why this behavior is inconsistent in cgroup1. > root memcg > / > memcg foo > / > memcg bar > > Suppose there's an oom_kill in memcg bar, then the oon_kill will be > > root memcg : memory.oom_control(oom_kill) 0 > / > memcg foo : memory.oom_control(oom_kill) 1 > / > memcg bar : memory.oom_control(oom_kill) 1 > > For the non-root memcg, its memory.oom_control(oom_kill) includes its > descendants' oom_kill, but for root memcg, it doesn't include its > descendants' oom_kill. That means, memory.oom_control(oom_kill) has > different meanings in different memcgs. That is inconsistent. Then the user > has to know whether the memcg is root or not. > > If we can't fully support it in cgroup1, for example by adding > memory.events.local into cgroup1 as well, then let's don't touch > its original behavior. > > Setting CGRP_ROOT_MEMORY_LOCAL_EVENTS for legacy hierarchy by > default rather than special casing it somewhere quite deep in the code > would be better, per discussion with Michal. OK, this makes sense to me. Cgroup v1 really had local semantic and 9852ae3fe529 changed it unintentionally. I think it is reasonable to use the CGRP_ROOT_MEMORY_LOCAL_EVENTS which denotes this mode but I will defer to cgroup maintainers. Maybe there are some other side effects which I am not aware of that would make this more awkward than a special case for cgroup v1 > Fixes: 9852ae3fe529 ("mm, memcg: consider subtrees in memory.events") > Cc: Chris Down > Cc: Shakeel Butt > Cc: Michal Hocko > Cc: Johannes Weiner > Signed-off-by: Yafang Shao Acked-by: Michal Hocko > --- > mm/memcontrol.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 5beea03dd58a..0f7381bddcee 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5940,10 +5940,20 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css) > * guarantees that @root doesn't have any children, so turning it > * on for the root memcg is enough. > */ > - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) > + if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > root_mem_cgroup->use_hierarchy = true; > - else > + } else { > root_mem_cgroup->use_hierarchy = false; > + /* > + * Set CGRP_ROOT_MEMORY_LOCAL_EVENTS for legacy hierarchy > + * by default to avoid inconsistent oom_kill behavior > + * between root memcg and non-root memcg. > + * Regarding default hierarchy, as this flag will be set > + * or cleared later, we don't need to process it in this > + * function. > + */ I do not think the comment has to be so specific about oom events behavior. I would just go with /* * Cgroup v1 has traditionally had local semantic for * event counters. Cgroup v2 changed that to a * hierarchical behavior. This is expressed by * CGRP_ROOT_MEMORY_LOCAL_EVENTS in the cgroup core. */ > + cgrp_dfl_root.flags |= CGRP_ROOT_MEMORY_LOCAL_EVENTS; > + } > } > > static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value) > -- > 2.18.2 -- Michal Hocko SUSE Labs