From patchwork Wed Nov 6 22:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13865576 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 4A0F3D59F75 for ; Wed, 6 Nov 2024 22:14:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B71A6B00A7; Wed, 6 Nov 2024 17:14:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63F7F6B00A9; Wed, 6 Nov 2024 17:14:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 507626B00AA; Wed, 6 Nov 2024 17:14:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 35B9D6B00A7 for ; Wed, 6 Nov 2024 17:14:39 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E8D7C40146 for ; Wed, 6 Nov 2024 22:14:38 +0000 (UTC) X-FDA: 82757074428.30.C1DEA64 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by imf16.hostedemail.com (Postfix) with ESMTP id 7B3EE18001E for ; Wed, 6 Nov 2024 22:14:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ljHn3jgz; spf=pass (imf16.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730931091; 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=D+BYvY7IMf430+vWeEHCo5rwaXQ0/XpIOzOhZE2+FDs=; b=8jnTvyMx8OtTCVwOKKnL+43VclX+TiWTPlAG75vO9pBV7OziaXicY/paDLHO8XUcGwE+Xk TQryVc/wJDflE4d0u6J5k+4AlIoEvyOCG2RvPqTRFbdgcWc9PzIRErDQxLdQtn5GxUkwtN eCMuMX9uPsua8AMyLSbsfBylNG6p1Qw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ljHn3jgz; spf=pass (imf16.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730931091; a=rsa-sha256; cv=none; b=hSkLOp8OmC6TZMoqifUbI2dRY1q/m5EG+16zN2d+eq+nqZL1HPXsS64Gog/ElFxVcueI52 iNUZDQu0tHiOYx6GVtGUJ8Omk+5JVeCJ8ApDe08R4Z9PZNicNB6mrg1TcT3VofLX/eYbdr sUDbwC75MWvtuaXVmtSexeAR/7SNwzw= Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e30d517c82fso309962276.1 for ; Wed, 06 Nov 2024 14:14:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730931276; x=1731536076; 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=D+BYvY7IMf430+vWeEHCo5rwaXQ0/XpIOzOhZE2+FDs=; b=ljHn3jgzQOuDSAi54SW5LASiWEhyi9DLG3kXGvWUgY9233Nrl3W9bONOcdRyGiQLG6 ozK2BAh8PtacP3Kl1XsgJLLRrgCBRn4G3iXp82LAZZOtBEv7JuR8XsdgZw5fcXlxubxj 6xS1/HJvxX8PG0SM5lzE6ILaJTWB+2pWMo1TfV/X26O+qW4BCbS6sYzdMHhu85zxAlK3 E528tXFfHBmRZawxKsTFe/bKMpQWlouQ9diZw+CgVAmRPIFxbMBl01BhNy4tbTHQ8oAm ZKj30Z5MhI0stubusA9SNf5WHRqIpBpsYVgo8z2FiMh54J/AVqNHKcWvhf1DZJWf66Wx al4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931276; x=1731536076; 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=D+BYvY7IMf430+vWeEHCo5rwaXQ0/XpIOzOhZE2+FDs=; b=j6y3Qs4KZ8xnpFLzZOCgwbKwO+hcGLfrZ8u7K1oJ5tDLiMP50apWpg5cUwDzsDTrXv nN2qnuJUaMGkQ/r7ZyVzacbgU99j3J0QxIlYeKf2Lp1+kNniIP8KQQ07eLr/CkMcSXvJ Z/QWVJpPGam9K/nxnOTM7Fp7whnmWMpt9KROkYnz4PjEkqhnDOVV0MkXW0H7XvONUIc2 wIdc5CzuwP2ZvS4I8I6FokgIzTm6is51ZYOKT4uAteEpltpWKneeyAEL3o57ZPkgbytE drsQpYED5ieSTB6VrPbmQEx/pL27W0AHhPWSZtyn7NfbyRGUr5fKI5P4ZhGSpusrQDsD Ev5Q== X-Forwarded-Encrypted: i=1; AJvYcCVcJNxIg4M7pJ6Zl3aDHS4oii/MHAU0XbG2pceBnjuoJyEkoBvbRDdSebJSQdhIUCvQfo9/AmsfuA==@kvack.org X-Gm-Message-State: AOJu0YxoeYCGz5B81PDTkVaLj/m0dwvHST+Eg7q6Umi+vTc/wm0Vqt3a fZTIu8JSqMfrFB6yaWgTlHRbTMlEX+iStRfjViIV6aeWq8aXjo4e X-Google-Smtp-Source: AGHT+IEZB9rihXZ3AKiyPE/dIYsUpmlpyAXZCpI9bcRjC/JzUNq0GMLJ+lPD4+mXrSwJbO3Tlf6xIw== X-Received: by 2002:a05:6902:1a48:b0:e30:7c38:668b with SMTP id 3f1490d57ef6-e30cf4d0428mr28204692276.37.1730931276231; Wed, 06 Nov 2024 14:14:36 -0800 (PST) Received: from localhost (fwdproxy-frc-016.fbsv.net. [2a03:2880:21ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e30e8a61035sm3052634276.1.2024.11.06.14.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:14:35 -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/2] memcg/hugetlb: Introduce memcg_accounts_hugetlb Date: Wed, 6 Nov 2024 14:14:33 -0800 Message-ID: <20241106221434.2029328-2-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241106221434.2029328-1-joshua.hahnjy@gmail.com> References: <20241106221434.2029328-1-joshua.hahnjy@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7B3EE18001E X-Stat-Signature: egia969womrrz1u6551q5hqazes3i6ou X-Rspam-User: X-HE-Tag: 1730931242-52844 X-HE-Meta: U2FsdGVkX1//UlSZa36OON65DysOrQ2/Mr1+RpGfW/Bhc0l0aLBNIN0TsaVItyLiYnfjZ0LoZCkG6a/2d+UzM1tCG7a8D9cR8ZOKHTGHe1fNH6Y/yQl8B1XYSSC7rm+SRZEXWqVm+5Lj46MruNizmUUE96x02pxPZCJbh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iAJSzIq2GMLDN21w7erfL2jWn7hUz+Pa/dL9a5VLonShUT+DpSCbADUdna8p/+/44VfRaIsIxYFKrQKbwm+Of1sY8RTk9fIxCD5qOG8hdwXlskfqS6YBhDRNj6J47b/g7n4+ubN8qVvhyvc3Naf1IYJ04mrUtXdFuOnFnBCsMQ== 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: 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-of-by: Joshua Hahn --- include/linux/memcontrol.h | 2 ++ mm/memcontrol.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 34d2da05f2f1..25761d55799e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -694,6 +694,8 @@ static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, return __mem_cgroup_charge(folio, mm, gfp); } +bool memcg_accounts_hugetlb(void); + int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, long nr_pages); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5444d0e7bb64..59dea0122579 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4497,6 +4497,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. @@ -4522,8 +4531,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))