From patchwork Fri Nov 8 21:29:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13868972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D5C9D6408F for ; Fri, 8 Nov 2024 21:29:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B99F6B00C5; Fri, 8 Nov 2024 16:29:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 769EE6B00CA; Fri, 8 Nov 2024 16:29:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BCD66B00CB; Fri, 8 Nov 2024 16:29:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3BD876B00C5 for ; Fri, 8 Nov 2024 16:29:52 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AD638120F7F for ; Fri, 8 Nov 2024 21:29:51 +0000 (UTC) X-FDA: 82764219426.18.71C1022 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf02.hostedemail.com (Postfix) with ESMTP id 70E5F80011 for ; Fri, 8 Nov 2024 21:28:39 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cGacy6yP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731101264; a=rsa-sha256; cv=none; b=3FealC6rFNoU6D4884UMR78Mciim/JS2VhPYsuLfd8e67R7otuzK2M1cuNhaiyrWr7Gw+4 WdsulyKN2N793zeLbXItT/x3BuEvWeziARe5rfKtwl+zHlxOZGE18e/01yxaiV0s48VNm/ 8Pj9fYiHSQ+gGywQTJcMygBdDDR+Qms= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cGacy6yP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731101264; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fN+w5UJnH1OJ63mHkAqq0SxDq06prIp4qqjizUvyrVU=; b=L9wNZyqHkaQZURjUvqSTQTJ8Yn/n430Wc0FzQy4k4vvddf9ff1NzPvxOYMMcCYYBoFAZYr k8eOl/0vNdSWhHSA0SnZEzvZR9M8L9UujfiJJzpi9FAqDFMmP4/HY6c1kVmyO4Fsukzh09 tyg9MgRe22/LLf9x6YhXEJ1sI5lPkHY= Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e28fe3b02ffso2555764276.3 for ; Fri, 08 Nov 2024 13:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731101389; x=1731706189; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fN+w5UJnH1OJ63mHkAqq0SxDq06prIp4qqjizUvyrVU=; b=cGacy6yPdc14x8BzeCslBbwWSISutLf1xRug/JyV0z6pCxNP/JMLRHljoKtFw1nF/y gDf7j69BpInQ9vDrOz7G7MA9BqqI/Y26Xpop6MXQnfGm4iKma0216Jt/7JADI2wE6cfR tVCFW4kjhKpaQ8+DlCJDberwDHlPm4jNQp7qMvR/XVM8nQGBKk75d80EPsieoj0q3szZ Yxw/GYpvbP06oZO4fZ8GRzPr0l/C2ul1M+vpgrY1wiGafSuE3y0Cg1PttXcfF5Irjtwl qQyxosPZrpQy+x7/rVn54d4LY+cXVZ/WYnw8x891Ch0UZEPreLAPTzRaTKcQck60dmMR u7XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731101389; x=1731706189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fN+w5UJnH1OJ63mHkAqq0SxDq06prIp4qqjizUvyrVU=; b=aLvAwEY5bHswgBzeDMEBLfNVrQBKjrxAkfeRrnAqIIUgy9xQgOXTitWEB3x0kxK8J5 yFiuHr5FvAjzXY1cGrURVLs6TGTZKejx7GXMAX4NI43j3v2vq+rAcQEpPfnU8Oi3o46p n6DzCCBgKVNAQSsQllvF6UU8wpvfaBLo/DSYPhL+FdXa2GiSA+YuS67bIy82KOPB8lhN xUjVjD/JfnALIRmnG3bFNQrgVk9NLJYr6bSm+fXHQ8SFlflhVsaNZ0g/JqjYjpXwuTlI SC+YDynXZiDXltyhXoQSixOTGrKFhyRlmLS7qa77uET/mPZpku/bb38fCO0mCtUIHdG6 Z6+A== X-Forwarded-Encrypted: i=1; AJvYcCVTbjsHiTV8ElXqWisRPcGXpuwJu595lrCfu1LLcIudq3mK4Dn0265fnaD7PluudnxQU78oe/8Z4Q==@kvack.org X-Gm-Message-State: AOJu0YzkDjAMV3WYqqYR2Wu9+6yS7PuzAnWpgLaK4pv4FAMqoMvuJGk5 0xnn/zflWhzqvwtkZ1gJKAdE2i95snt8BvwL6U5cezblWvZ+6t3W X-Google-Smtp-Source: AGHT+IF01KDV23z8HCRAEbhxmD/lQoqCQ1DCmjSyHkvYxXH6OJ4PaV9aA0NGxTGCRf0Ixws2pRdvog== X-Received: by 2002:a05:6902:124f:b0:e2b:9967:6363 with SMTP id 3f1490d57ef6-e337f8f200dmr5284036276.37.1731101388953; Fri, 08 Nov 2024 13:29:48 -0800 (PST) Received: from localhost (fwdproxy-frc-013.fbsv.net. [2a03:2880:21ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1ba829sm888330276.40.2024.11.08.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 13:29:47 -0800 (PST) From: Joshua Hahn To: shakeel.butt@linux.dev Cc: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, muchun.song@linux.dev, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 1/3] memcg/hugetlb: Introduce memcg_accounts_hugetlb Date: Fri, 8 Nov 2024 13:29:44 -0800 Message-ID: <20241108212946.2642085-2-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241108212946.2642085-1-joshua.hahnjy@gmail.com> References: <20241108212946.2642085-1-joshua.hahnjy@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 70E5F80011 X-Stat-Signature: ywp3e1qtwby65np4nw6dwp19awnynkyz X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731101319-533557 X-HE-Meta: U2FsdGVkX18VDj6PxNPAciG7m2EJiAA0S1FjOGpXJIC+jsne8IZK9RQxgYW5qpBAdo9cC6C4LgdIyP1lxe0tLM8RxgEI5xbv/kGSzwEzXbRvVGyzHIJwjNilZrEZGPNm3EHZkintE8aa7u3CrcuwuZT1DQvm/uNyYoP5/KVRfzK/OU3y9AUYn6JCd4nTG/W+mrjjNz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pMMB8LKnfKVEB/MFOttLsyrmZfcXVIpoIqcoSzDMYh6RTYN4THn2zKP7WnisEu/dYlQ01ui/UUZjhQw6Av54+PN/18oJtn50c1e8eUdY73+txuyDgClGQgmpCPTvo4Uvh5f1HbcysmfSiI61VuRaa4SvpLQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000017, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch isolates the check for whether memcg accounts hugetlb. This condition can only be true if the memcg mount option memory_hugetlb_accounting is on, which includes hugetlb usage in memory.current. Signed-off-by: Joshua Hahn --- mm/memcontrol.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f3a9653cef0e..97f63ec9c9fb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1425,6 +1425,9 @@ unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item) memcg_page_state_output_unit(item); } +/* Forward declaration */ +bool memcg_accounts_hugetlb(void); + static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) { int i; @@ -1446,7 +1449,7 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) #ifdef CONFIG_HUGETLB_PAGE if (unlikely(memory_stats[i].idx == NR_HUGETLB) && - !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING)) + !memcg_accounts_hugetlb()) continue; #endif size = memcg_page_state_output(memcg, memory_stats[i].idx); @@ -4483,6 +4486,15 @@ int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp) return ret; } +bool memcg_accounts_hugetlb(void) +{ +#ifdef CONFIG_HUGETLB_PAGE + return cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING; +#else + return false; +#endif +} + /** * mem_cgroup_hugetlb_try_charge - try to charge the memcg for a hugetlb folio * @memcg: memcg to charge. @@ -4508,8 +4520,7 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, * but do not attempt to commit charge later (or cancel on error) either. */ if (mem_cgroup_disabled() || !memcg || - !cgroup_subsys_on_dfl(memory_cgrp_subsys) || - !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING)) + !cgroup_subsys_on_dfl(memory_cgrp_subsys) || !memcg_accounts_hugetlb()) return -EOPNOTSUPP; if (try_charge(memcg, gfp, nr_pages))