Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2302788rwb; Mon, 15 Aug 2022 02:56:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/aHNaDYo5YbpSC/5RKaVX/CBnou+u7/09r0chSRXwneYnHrgMK8kDzAFiSvCZtat5SBaE X-Received: by 2002:a17:906:5a5f:b0:731:8586:7904 with SMTP id my31-20020a1709065a5f00b0073185867904mr9887816ejc.559.1660557386848; Mon, 15 Aug 2022 02:56:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660557386; cv=none; d=google.com; s=arc-20160816; b=AEmVI0ArR2cVOh92btgfm4ttHS4SYIRoT71O22DK4tcPUm7/hgC3PwEoHIM8CFoUoM YxMRoB2B6S+voc8pNCBkUOqFylhGGnzmSuZNF6tk9F6D98XeWLwqW4u6twCETxwOgg7e I9togmFG62o7wXM9Yb/lteiRwefpJhe+N/vEteNPt+JAwDr75qRa4nhf9TUjBzFrj0dN TbMeqfzULUI2qWE93nK2hUtgl0V3IGCmdZka9vc2oj37LneLXlIuGstPfFMhPphMqqDn OyLvMp4oM+Y+0cievgvHFCJ9mNv2i5aaGRRaoyQlMFd3HyBtoqdbkNeUMUw/KdmF0cKm pZoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eiqkvF+xYiNF2DpRXQeLPgqIYFAmFLS0V8w6NeOkAps=; b=ZIqJqYWZY5mwqddmaaXbPbNgVGFnMua3HyOPOeV8tSCHNy/5fEaKz9ptfgjzNa9AP4 2el4RcQS8DP6ba6O/bCLsL0l1+xzSPbZbBLJL3ZGEDHWWMr3vGKW86H6lmm6oWD49Ktd EvJA6NTKsSYVvGxnoJ7Cto8lRTbE47wW58mpRepQe6msrDLS5Z4QX2RTCuYDH0nPdF+2 9tAc/v3Yl7jtP6Pjai8dEvtK0OU2BAZR0yWP7Bl632D2PpQ20ZR0Kuw5BZu5qsT9CLXn Ygolk1oTmZbpYXRBjB9pKQWyZNiFTAL2ekYi8M9c0oMYZlzJ4EWUfX+lgAUjMkdQ5DXX YbJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nLzwUzH1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a170906848b00b007315809ec84si7102161ejx.398.2022.08.15.02.56.01; Mon, 15 Aug 2022 02:56:26 -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=@gmail.com header.s=20210112 header.b=nLzwUzH1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbiHOJRf (ORCPT + 99 others); Mon, 15 Aug 2022 05:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232000AbiHOJRV (ORCPT ); Mon, 15 Aug 2022 05:17:21 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1AF122528; Mon, 15 Aug 2022 02:17:17 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id d14so9835379lfl.13; Mon, 15 Aug 2022 02:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=eiqkvF+xYiNF2DpRXQeLPgqIYFAmFLS0V8w6NeOkAps=; b=nLzwUzH1mFhYYOp7STOZsHfn7f2SW3Gl6xJ8vP+9vPX2YAZB2C6OlzaSKAeYnmAQv1 1PdjeD/WpfSf7CrTfALpgrSOS4Z5IcOcuc/ZJTLrj+ypqyWlP8AusY08hpNwC6czmjy0 zc3VJeNGhdWq/xRoIuGB7Kygb2vskfasVGLXx0rbvEwJgKMLskTKjBNlQ388bRI6Mpcf RvjU2kUboC2pvVZnkXL00TmNZnpEmLvxb59g9DI9T5v/teeX3DQaOM+ybyPGLI1qOL7l Ys5Ddw4/L4rYxBm9Vvmxcq23T86HxaW/lYWcHNVjV0cjAhfpCGgmjCbWXyayuOFE9Om/ oqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=eiqkvF+xYiNF2DpRXQeLPgqIYFAmFLS0V8w6NeOkAps=; b=nCz0ovPiC8u3aMwwcLR9eiegH+kRAWzmqzTr+zvOppZUqgG0Z4qDNpG8j6ahVJ9d6Q Z4itMMY/N1wu0xKxK8Q68t7iVVWwkTxv0pPZokRenzk6eMa8Vjvhdv9FkSK4DPon71SK Ydspf3lCeh9Chb91nWxUoK49m/UFER4zdu4Cf8PREJDxbaKnQCFYlL9jV8X3zYPkvjqk 3mXqR0fL5UAnQLmOHaPxyOWw/RxbhwCJ6StVP00bffkx3dQOXCC/jzE+q0CAY+mN41kJ qh9UJ4lhUODH/YQWwSm8vjOXpf9mQM+D0aUgN6nUwUGsy6DUKJ0tsmWafn+UUbGS6uDf R8dw== X-Gm-Message-State: ACgBeo1FcuAdcwZXVKzdgSrPF44ZT0Qp2vsmtz3RVD7/aUBc8U8/FuYr Ji/rtghYLE77Hng4G2QKtaqEO0t+W+8XYFJgQAM= X-Received: by 2002:ac2:4e4f:0:b0:48c:e6b6:9d7e with SMTP id f15-20020ac24e4f000000b0048ce6b69d7emr4850618lfr.128.1660555035731; Mon, 15 Aug 2022 02:17:15 -0700 (PDT) MIME-Version: 1.0 References: <1660298966-11493-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Mon, 15 Aug 2022 17:17:03 +0800 Message-ID: Subject: Re: [RFC PATCH] cgroup: use root_mem_cgroup as css when current is not enabled To: Tejun Heo Cc: "zhaoyang.huang" , Johannes Weiner , Michal Hocko , LKML , cgroups mailinglist , Ke Wang , Zefan Li , Suren Baghdasaryan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Mon, Aug 15, 2022 at 9:38 AM Zhaoyang Huang wrote: > > On Sun, Aug 14, 2022 at 2:40 PM Zhaoyang Huang wrote: > > > > On Sat, Aug 13, 2022 at 3:06 AM Tejun Heo wrote: > > > > > > On Fri, Aug 12, 2022 at 06:09:26PM +0800, zhaoyang.huang wrote: > > > > From: Zhaoyang Huang > > > > > > > > Memory charged on group B abserved on belowing v2 hierarchy where we just would > > > > like to only have group E's memory be controlled and B's descendants compete freely > > > > for memory. This should be the consequences of unified hierarchy. Solve this by > > > > have the cgroup without valid memory css alloced use root_mem_cgroup instead of > > > > its ancestor's. > > > > > > > > A(subtree_control = memory) - B(subtree_control = NULL) - C() > > > > \ D() > > > > - E(subtree_control = memory) - F() > > > > \ G() > > > > > > > > Signed-off-by: Zhaoyang Huang > > > > --- > > > > kernel/cgroup/cgroup.c | 8 ++++++++ > > > > 1 file changed, 8 insertions(+) > > > > > > > > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c > > > > index 1779ccd..b29b3f6 100644 > > > > --- a/kernel/cgroup/cgroup.c > > > > +++ b/kernel/cgroup/cgroup.c > > > > @@ -533,6 +533,14 @@ static struct cgroup_subsys_state *cgroup_e_css_by_mask(struct cgroup *cgrp, > > > > * can't test the csses directly. Test ss_mask. > > > > */ > > > > while (!(cgroup_ss_mask(cgrp) & (1 << ss->id))) { > > > > + /* > > > > + * charging to the parent cgroup which hasn't distribute > > > > + * memory control to its descendants doesn't make sense > > > > + * especially on cgroup v2, where the parent could be configured > > > > + * to use memory controller as its sibling want to use it > > > > + */ > > > > + if (memory_cgrp_id == ss->id) > > > > + return &root_mem_cgroup->css; > > > > > > This is gonna be a hard nack. A given cgroup always encompasses all the > > > resources consumed in its self-including subtree. > > > > > > Thanks. > > IMHO, I would like to say if it makes more sense as "A given cgroup > > always encompasses all the resources consumed in its ENABLED > > self-including subtree." Otherwise, how should I couple with the > > scenarios I raised in the commit message which I prefer parts of the > > subtrees compete for "memory" while others are free for it. The free > > here is not only without "min/low/high watermarks" but also not > > charged to their own LRU. > I would like to state more why these make sense. Memory cgroup is a > little bit different to other cgroups, that is, memcg will have real > physical resources attached, say pages. From perspective of memory > reclaiming, it is odd to find that pages under free memcgs are charged > to separate LRUs but without any management(no watermark control) and > perhaps affect workingset mechanism by LRU reason. Furthermore, v2 > should grant the groups with the right to reject the subsys which > introduced by sibling enable, which could be deemed as v2's > inconvenient. The memcg could also apply subtree_control to enroll all > memory back whenever it want. As suggested by zefan, raise the practical scenario here to make more sense. The issue is observed in android system where per-app cgroup is demanded by freezer subsys and part of them require memory control. Under this scenario, less efficient memory reclaim is observed when comparing with no memory control. It is believed that multi LRU scanning introduces some of the overhead. Furthermore, page thrashing is also heavier than global LRU which could be the consequences of partial failure of WORKINGSET mechanism as LRU is too short to protect the active pages. > > > > > > -- > > > tejun