Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3654601rdh; Thu, 28 Sep 2023 20:20:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDWgSwk4o4HUjwIsYF7qMp3NrzRkS3g03k+Dx7+JjyhaqvzyVSoCm1VftxIjEVb+xq7x8f X-Received: by 2002:a05:6a00:1394:b0:690:41a1:9b77 with SMTP id t20-20020a056a00139400b0069041a19b77mr3568142pfg.10.1695957610359; Thu, 28 Sep 2023 20:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695957610; cv=none; d=google.com; s=arc-20160816; b=NC1XfWedyMAJfO8NgkcrUdcMqexvJXs5XZyP0/EFwdB8cJUmkwDWtquH7oz/GOGPZ2 capVGv7JQI6Ig3Q9vh8O2iV3c7Y3IN28GXJ1b8CKDtX4kS2d3recp/Yk566pxx8xs6ox ccC1ratoRyqfajYTJ+phXyWrelBroWIPuSP5dkoBmvJ+3gPxshOZL+8xQhGw/68epS7W qESvHEChDkjvJ97mPtqBoMxzO2d7Smt7fw5XI31svGwu4r7fvOufnLLT/5zn/a6IaV9j vPotRJUIQ3nUZn94s81BFSDV9pTOQ+kDlZU22OXkkPhkCNI5jugeSxhsT9iJAPPWb3Y8 Me/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZndDvjVADU6GuKHszhELnx+eP/DDe/5FgQazo+VWICo=; fh=qUku7vrmrqtnl3JMxpi97/f8ZrHFLsHCD9thAfl3pZg=; b=RBbav7QAYupJakfqfIHvLQdU5tl5RCfUDSDNaD5GY8iSGAzj9wYNjAMyZsGUo9PhHP AjsLJXDLy3y5Ndwl6H2s8h9Lk3dYMjXmfJvukWGv+GVtlxmveyHbIzoIGRhQeWmwHYPX B/XxAxQc+QRUrQGsavzjD4swJOUSC1TO5GVSY93szz2HGNIRUrdAzYftsgkf9yxjwa4p EDW/0/d3B5vUQvhydDh29boDCIsRjCjQJjZy+0vW6hLXZx5/wcA8HJ0iEdLE4D3rNHWd 3eaTbPkWNcZIco1PRRcgLykXgiIgEPe70Iw0kVGUOgf4UlyJtctJA1VOSgXtvnsX4FAZ 6JuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z3FhmGKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v189-20020a6389c6000000b005859f9d8e4fsi597030pgd.5.2023.09.28.20.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z3FhmGKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 495958350FE8; Thu, 28 Sep 2023 18:19:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbjI2BTD (ORCPT + 99 others); Thu, 28 Sep 2023 21:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjI2BTC (ORCPT ); Thu, 28 Sep 2023 21:19:02 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73447195 for ; Thu, 28 Sep 2023 18:19:00 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso1799870566b.2 for ; Thu, 28 Sep 2023 18:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695950339; x=1696555139; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZndDvjVADU6GuKHszhELnx+eP/DDe/5FgQazo+VWICo=; b=z3FhmGKVgykolqgvdknTpN5/d4XISRQQLaLPzv1L9yZWRob6rNpwH9CdLWsXQqMeW7 ryWUIw7U4ygplh+FSVMYaUWk5OqtHnIzUw5N3jSfujcY13MOiwljnUgGBsB2E9fFRu/a YssNxuYcigcypnlJmxx48dajhqT7WyJSiX/Nnur+dybbLGAM7F4S7fw4T9kshOKmABBP G8wA7NnwK2qz3xMtQmA5XLf5AW+syuKlsKqCxT8aB3F4/j/PnbKmZ3ejh/VRsFv7nXVY GJ8nxL4ecfqpLg467oSFBaCW+QFLZbMDcd3Fh7O1+d8yCKTVS2Hb7sfWtDaGUw2atGuE uhuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695950339; x=1696555139; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZndDvjVADU6GuKHszhELnx+eP/DDe/5FgQazo+VWICo=; b=gqCxxsjthkSQM5En4F8llZ5LBW8VKQcXqw86hibjtXFUui5S4TidNzU4eSm2II6Ck2 NKo1aTJXeWw/bx+bu11TtugqScz0zm4ekloOk6FRMZ2bSSyJiqSuvIvHWOqwE/6wvoti JNUhfdW6kn5aeq2/yX+42Egq+ABEsEEFBcyRFeog98p16//ePWn9Y5rdEka3AyhIMdRG jrvPtU1zrr6MT2fCJyylfuyCgF4yfMg95hu48CD8rES52LeVoNx4gT/SSoNKiENKa2ke vfTxTM5gALdyoKHdzpG04h250LhdT3806Bqs2152yIgpX8AZfY8i/U2azq1bUXtADLrD lmEA== X-Gm-Message-State: AOJu0YxVMqmizSkJ9AD0pa4DOY7FP6qviD/cosAaaFXdFkIjZqpfZjfD 9KbNkzsqvPK8LzeD5qenF/GFV7H2Vmvvtp7cqOexMQ== X-Received: by 2002:a17:906:209e:b0:9ae:829e:d930 with SMTP id 30-20020a170906209e00b009ae829ed930mr2742309ejq.9.1695950338777; Thu, 28 Sep 2023 18:18:58 -0700 (PDT) MIME-Version: 1.0 References: <20230928005723.1709119-1-nphamcs@gmail.com> <20230928005723.1709119-2-nphamcs@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Thu, 28 Sep 2023 18:18:19 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] hugetlb: memcg: account hugetlb-backed memory in memory controller To: Nhat Pham Cc: akpm@linux-foundation.org, riel@surriel.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, tj@kernel.org, lizefan.x@bytedance.com, shuah@kernel.org, mike.kravetz@oracle.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 18:19:17 -0700 (PDT) On Thu, Sep 28, 2023 at 6:07=E2=80=AFPM Nhat Pham wrote= : > > On Thu, Sep 28, 2023 at 5:58=E2=80=AFPM Nhat Pham wro= te: > > > > On Thu, Sep 28, 2023 at 5:38=E2=80=AFPM Yosry Ahmed wrote: > > > > > > > > > > > > > > > > > + > > > > +/** > > > > + * mem_cgroup_hugetlb_charge_folio - Charge a newly allocated huge= tlb folio. > > > > + * @folio: folio to charge. > > > > + * @gfp: reclaim mode > > > > + * > > > > + * This function charges an allocated hugetlbf folio to the memcg = of the > > > > + * current task. > > > > + * > > > > + * Returns 0 on success. Otherwise, an error code is returned. > > > > + */ > > > > +int mem_cgroup_hugetlb_charge_folio(struct folio *folio, gfp_t gfp= ) > > > > +{ > > > > + struct mem_cgroup *memcg; > > > > + int ret; > > > > + > > > > + if (mem_cgroup_disabled() || > > > > + !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_AC= COUNTING)) > > > > > > What happens if the memory controller is mounted in a cgroup v1 > > > hierarchy? It appears to me that we *will* go through with hugetlb > > > charging in this case? > > > > Ah right, cgroup v1. Does it not work with mount flag guarding? > > What's the behavior of cgroup v1 when it comes to memory > > recursive protection for e.g (which this mount flag is based on)? > > > > If it doesn't work, we'll have to add a separate knob for v1 - > > no biggies. > > But to be clear, my intention is that we're not adding this > feature to v1 (which, to my understanding, has been > deprecated). > > If it's added by virtue of it sharing infrastructure with v2, > then it's fine, but only if the mount option still works to > guard against unintentional enablement (if not we'll > also short-circuit v1, or add knobs if ppl really want > it in v1 as well). > > If it's not added at all, then I don't have any complaints :) > > > > > Other than this concern, I don't have anything against cgroup v1 > > having this feature per se - everything should still work. But let > > I know if it can break cgroupv1 accounting otherwise :) > > My concern is the scenario where the memory controller is mounted in cgroup v1, and cgroup v2 is mounted with memory_hugetlb_accounting. In this case it seems like the current code will only check whether memory_hugetlb_accounting was set on cgroup v2 or not, disregarding the fact that cgroup v1 did not enable hugetlb accounting. I obviously prefer that any features are also added to cgroup v1, because we still didn't make it to cgroup v2, especially when the infrastructure is shared. On the other hand, I am pretty sure the maintainers will not like what I am saying :)