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 C305DC54FCB for ; Wed, 22 Apr 2020 13:15:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 58C0A2077D for ; Wed, 22 Apr 2020 13:15:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58C0A2077D 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 BA51F8E0020; Wed, 22 Apr 2020 09:15:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2FBD8E0003; Wed, 22 Apr 2020 09:15:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D06C8E0020; Wed, 22 Apr 2020 09:15:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 7F5ED8E0003 for ; Wed, 22 Apr 2020 09:15:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 358194435 for ; Wed, 22 Apr 2020 13:15:37 +0000 (UTC) X-FDA: 76735537914.09.alley18_30fef12a7172e X-HE-Tag: alley18_30fef12a7172e X-Filterd-Recvd-Size: 6962 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 13:15:36 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id h2so2266620wmb.4 for ; Wed, 22 Apr 2020 06:15:36 -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=iKw//13FMxEuVpRKhtqJlxwmLfxtnTrt97TTuMjPjsY=; b=grwygsFOThCRTikJhN2txQEEIFO2ZvzlvDqJ/fjh3vvQvz6SzOkDax8ZVNNbaG4aLY zmjjMOsQdAOW6b6kR2KFhkabtZQDjLZHuueCaZF0fMpFVlRv+/olcsKL0m98QAkOrRh8 nF3QY1NU8MgdsHFOjhL3K4RCII3bktHJyP1B+zQ+O/PVqrX5Qg68QV0jprmxY9E99bR1 JM9ZWcPYfbpUbSk4J0RcOZECO/9b10h2PtQ1QwIjRbIQMcSzvwZqioU6GdJ8G0AFWSfn Z8PXmL9Pl4cqrRkU/nbDHeBS/0FmOU168FMTgxNhJQa8KeY4jfX8dhLGS0GDiMCwYIJA HtQg== X-Gm-Message-State: AGi0PuZrjVi3xBlUY6UIpW7dJw7Rnj0928Aa9NklUW/3E5NdFKaZG1gA FPwDink4gLGNtFWyjq8K+gc= X-Google-Smtp-Source: APiQypIogzBDpnVHWtPAuEP7nmnNX3r6do6RstQsQKPbWe6hNeLlEkisl7XYIcTiCFlJUTqcJHWv9g== X-Received: by 2002:a1c:9e52:: with SMTP id h79mr10582397wme.84.1587561335428; Wed, 22 Apr 2020 06:15:35 -0700 (PDT) Received: from localhost (ip-37-188-130-62.eurotel.cz. [37.188.130.62]) by smtp.gmail.com with ESMTPSA id 60sm8611153wrr.7.2020.04.22.06.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 06:15:34 -0700 (PDT) Date: Wed, 22 Apr 2020 15:15:33 +0200 From: Michal Hocko To: Johannes Weiner Cc: Yafang Shao , akpm@linux-foundation.org, linux-mm@kvack.org, Chris Down , Shakeel Butt Subject: Re: [PATCH v2] mm, memcg: fix inconsistent oom event behavior Message-ID: <20200422131533.GF30312@dhcp22.suse.cz> References: <20200422110643.15725-1-laoar.shao@gmail.com> <20200422125426.GC358439@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422125426.GC358439@cmpxchg.org> 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 08:54:26, Johannes Weiner wrote: > On Wed, Apr 22, 2020 at 07:06:43AM -0400, 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. > > > > 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 > > --- > > 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. > > + */ > > + cgrp_dfl_root.flags |= CGRP_ROOT_MEMORY_LOCAL_EVENTS; > > That will cause problems for people trying to remount. From > cgroup1_reconfigure(): > > /* Don't allow flags or name to change at remount */ > if ((ctx->flags ^ root->flags) || > (ctx->name && strcmp(ctx->name, root->name))) { > errorfc(fc, "option or name mismatch, new: 0x%x \"%s\", old: 0x%x \"%s\"", > ctx->flags, ctx->name ?: "", root->flags, root->name); > ret = -EINVAL; > goto out_unlock; > } OK, I was not aware of this restriction. Under these circumstances special casing in memcg_memory_event is the right approach. > These flags belong to the user, they're read-only to the cgroup > implementation. Let's not mess with them from a controller. > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 4b868e5a687f..e831a90b5506 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -773,6 +773,8 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg, > atomic_long_inc(&memcg->memory_events[event]); > cgroup_file_notify(&memcg->events_file); > > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) > + break; > if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS) > break; > } while ((memcg = parent_mem_cgroup(memcg)) && -- Michal Hocko SUSE Labs