Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp938214rwe; Wed, 24 Aug 2022 11:37:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR6CFGdfQcBYc9FKmQgZo1KGkAMW8LwqtUjLsVlPJ+h8dZBiv9SWJhtoB+wUuQhkPwzueGQB X-Received: by 2002:a17:907:b590:b0:73d:ad56:4527 with SMTP id qx16-20020a170907b59000b0073dad564527mr164669ejc.237.1661366261386; Wed, 24 Aug 2022 11:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661366261; cv=none; d=google.com; s=arc-20160816; b=qaM8vbxL4VOcCiT5bY/lMCHF88zFA0Q7cW6zkbPQPw6AdDWWbScjdwDXZLpu1U5KA+ 8VZWknXvhoMrItUhXTM4MKYat65Xoqy7ovIvzYV1kH1VRSar7uI0Zgw2vV9x4SeeAvqZ 7uRbhwHIo0B232JPhsvuMpwA5Gwd77ofn2ykQctZ0Zz4uXeLS6qNX+cFecLHnGrYnuP8 JlWjZ++1KyVv3GQvmPtbTgt1S16eD+3qPSVi7fydxCOrblCdmvh331kIlbW+lpeBSQ3+ qPF9Nq4kX/K9WxNFfRfqKTvhR+2VgCB/EliFwV1xDJ9KTodMiNzRWCt+pROBsIO8VTuw oxyg== 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=nALw85bqOF3gyi0IhYuUBAdShMU6pleGfRDPmIPW20o=; b=A9qIS4/hfFgaYcyElSZS1sVDhcFaT8u9kaEgGy9D+k/g3o98TwEmsJ8Fu93t8nXmdV HSWeXyPvMSkXRjpRg5cofMuLO34dOjCqiGJqwacAkB+X1ZpQCT9Lw2d0ZlH7rSLg5HOK B2dF6zYlC5z2sj3+0Ngr/6FNecSNRRjPEEcIWpWGeryG5ZYyV3x+Y2o4Xvex0e8106lE 2b2XL024k+12vum+3fqea5FWU3MT/x7mdvMK/17fj666IZvBVD3TScxGj+nVslr/a0jP gEcnW3jc8cba51HIaYQUHuDS868rDmoXVuCD32usmLtoo6Cqlo4KGyOFI/5YQSMvS7h7 gWSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TvMpTzzp; 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 q25-20020a056402249900b004478580939esi1426740eda.260.2022.08.24.11.37.15; Wed, 24 Aug 2022 11:37:41 -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=20210112 header.b=TvMpTzzp; 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 S239936AbiHXROC (ORCPT + 99 others); Wed, 24 Aug 2022 13:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238837AbiHXRN5 (ORCPT ); Wed, 24 Aug 2022 13:13:57 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 643847B798 for ; Wed, 24 Aug 2022 10:13:56 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-335624d1e26so478260527b3.4 for ; Wed, 24 Aug 2022 10:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=nALw85bqOF3gyi0IhYuUBAdShMU6pleGfRDPmIPW20o=; b=TvMpTzzprKB3QQsEsxpI6k6LbDetrJ6rCT+0LkjJ52Y8ACXF2oZ2UiUTjQmUzRTHNX ZSMC/uHhXMTLWadDIylZQbtLSbYb+o+RDxb83Jx4hsLdQy/2adQOWzB1Acr5QssUCVYO 805SbwHsXmGqRmqOfdfws/s238Ow1e4LD7pEodwsewLLMGUr+QGT/MOt5E7Cf2tbYTeB uhkJdGeATjYm09x6D8CjbfhkvTp/g4/hD9nmZDHKqWcHHkMPGJBYuqexJ7gcRqWRdow2 e/IcQ89lTNCSTEjLWvozENuPJxmKTyR693FGsrIPFAHBSG+9WyuU1UBA329tTD8DquTx YlbQ== 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=nALw85bqOF3gyi0IhYuUBAdShMU6pleGfRDPmIPW20o=; b=6vVG2q9I8l3czDnhWLtf+kP0cGAw+r1cUyfZm5QgcTRRov+uECZ41plseWNuCOqUV1 KZhWY8FmeApfK5N/xf08xSwwV/MzJl/Jdeknwes3QSlHQTLa2bUqgNgqKnGtNS8Mfghc BDjxxmlpEi0l0A6m74AL4SA21JqoalVIqkkh6kAZ9tx3Mww/HhEaq0ho7u6pNhrEoiz6 ldx7XFScq8KlDbjEISOHmtvg+K74wFob25qvp8glInS2FrPFZkbRlJMMKCVC9H5OLSgS fM2TUhBc5ip6cWAuK1dW+/3807NmIRxbKHRR1zB3+E7rvPd3TSKPwBOb83hVj7ujyJCH 9MdQ== X-Gm-Message-State: ACgBeo2rUMEB4cd+SVNeSpfGYsayKmsmPYWHsCTZP5FKeUiTSD9+Y4MC LeFd9cDpdg61y6KYLATxmurTyo9JfxkhRZVfrTBrnA== X-Received: by 2002:a25:9885:0:b0:67b:e79b:ded1 with SMTP id l5-20020a259885000000b0067be79bded1mr81717ybo.441.1661361235394; Wed, 24 Aug 2022 10:13:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Suren Baghdasaryan Date: Wed, 24 Aug 2022 10:13:43 -0700 Message-ID: Subject: Re: [RFC PATCH] memcg: use root_mem_cgroup when css is inherited To: Michal Hocko Cc: Zhaoyang Huang , Tejun Heo , Shakeel Butt , "zhaoyang.huang" , Johannes Weiner , Linux MM , LKML , Cgroups , Ke Wang , Zefan Li , Roman Gushchin , Muchun Song Content-Type: text/plain; charset="UTF-8" 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,URIBL_BLOCKED,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, Aug 24, 2022 at 12:59 AM Michal Hocko wrote: > > On Tue 23-08-22 09:21:16, Suren Baghdasaryan wrote: > > On Tue, Aug 23, 2022 at 4:51 AM Michal Hocko wrote: > > > > > > On Tue 23-08-22 17:20:59, Zhaoyang Huang wrote: > > > > On Tue, Aug 23, 2022 at 4:33 PM Michal Hocko wrote: > > > > > > > > > > On Tue 23-08-22 14:03:04, Zhaoyang Huang wrote: > > > > > > On Tue, Aug 23, 2022 at 1:21 PM Michal Hocko wrote: > > > > > > > > > > > > > > On Tue 23-08-22 10:31:57, Zhaoyang Huang wrote: > > > > > [...] > > > > > > > > I would like to quote the comments from google side for more details > > > > > > > > which can also be observed from different vendors. > > > > > > > > "Also be advised that when you enable memcg v2 you will be using > > > > > > > > per-app memcg configuration which implies noticeable overhead because > > > > > > > > every app will have its own group. For example pagefault path will > > > > > > > > regress by about 15%. And obviously there will be some memory overhead > > > > > > > > as well. That's the reason we don't enable them in Android by > > > > > > > > default." > > > > > > > > > > > > > > This should be reported and investigated. Because per-application memcg > > > > > > > vs. memcg in general shouldn't make much of a difference from the > > > > > > > performance side. I can see a potential performance impact for no-memcg > > > > > > > vs. memcg case but even then 15% is quite a lot. > > > > > > Less efficiency on memory reclaim caused by multi-LRU should be one of > > > > > > the reason, which has been proved by comparing per-app memcg on/off. > > > > > > Besides, theoretically workingset could also broken as LRU is too > > > > > > short to compose workingset. > > > > > > > > > > Do you have any data to back these claims? Is this something that could > > > > > be handled on the configuration level? E.g. by applying low limit > > > > > protection to keep the workingset in the memory? > > > > I don't think so. IMO, workingset works when there are pages evicted > > > > from LRU and then refault which provide refault distance for pages. > > > > Applying memcg's protection will have all LRU out of evicted which > > > > make the mechanism fail. > > > > > > It is really hard to help you out without any actual data. The idea was > > > though to use the low limit protection to adaptively configure > > > respective memcgs to reduce refaults. You already have data about > > > refaults ready so increasing the limit for often refaulting memcgs would > > > reduce the trashing. > > > > Sorry for joining late. > > A couple years ago I tested root-memcg vs per-app memcg configurations > > on an Android phone. Here is a snapshot from my findings: > > > > Problem > > ======= > > We see tangible increase in major faults and workingset refaults when > > transitioning from root-only memory cgroup to per-application cgroups > > on Android. > > > > Test results > > ============ > > Results while running memory-demanding workload: > > root memcg per-app memcg delta > > workingset_refault 1771228 3874281 +118.73% > > workingset_nodereclaim 4543 13928 +206.58% > > pgpgin 13319208 20618944 +54.81% > > pgpgout 1739552 3080664 +77.1% > > pgpgoutclean 2616571 4805755 +83.67% > > pswpin 359211 3918716 +990.92% > > pswpout 1082238 5697463 +426.45% > > pgfree 28978393 32531010 +12.26% > > pgactivate 2586562 8731113 +237.56% > > pgdeactivate 3811074 11670051 +206.21% > > pgfault 38692510 46096963 +19.14% > > pgmajfault 441288 4100020 +829.1% > > pgrefill 4590451 12768165 +178.15% > > > > Results while running application cycle test (20 apps, 20 cycles): > > root memcg per-app memcg delta > > workingset_refault 10634691 11429223 +7.47% > > workingset_nodereclaim 37477 59033 +57.52% > > pgpgin 70662840 69569516 -1.55% > > pgpgout 2605968 2695596 +3.44% > > pgpgoutclean 13514955 14980610 +10.84% > > pswpin 1489851 3780868 +153.77% > > pswpout 4125547 8050819 +95.15% > > pgfree 99823083 105104637 +5.29% > > pgactivate 7685275 11647913 +51.56% > > pgdeactivate 14193660 21459784 +51.19% > > pgfault 89173166 100598528 +12.81% > > pgmajfault 1856172 4227190 +127.74% > > pgrefill 16643554 23203927 +39.42% > > Thanks! It would be interesting to see per memcg stats as well. Are > there any outliers? Are there any signs of over-reclaim (more pages > scanned & reclaimed by both kswapd and direct reclaim? I don't have all the details from that study but will capture them when I rerun the tests on newer kernels. > > > Tests were conducted on an Android phone with 4GB RAM. > > Similar regression was reported a couple years ago here: > > https://www.spinics.net/lists/linux-mm/msg121665.html > > > > I plan on checking the difference again on newer kernels (likely 5.15) > > after LPC this September. > > Thanks, that would be useful! > > -- > Michal Hocko > SUSE Labs