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)) From patchwork Wed Nov 6 22:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13865577 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 7B214D59F7D for ; Wed, 6 Nov 2024 22:14:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE5126B00A9; Wed, 6 Nov 2024 17:14:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D91E76B00AC; Wed, 6 Nov 2024 17:14:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B98296B00AD; Wed, 6 Nov 2024 17:14:40 -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 9A5076B00A9 for ; Wed, 6 Nov 2024 17:14:40 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 53FA4120150 for ; Wed, 6 Nov 2024 22:14:40 +0000 (UTC) X-FDA: 82757073924.08.85B18B8 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by imf14.hostedemail.com (Postfix) with ESMTP id B8DF3100004 for ; Wed, 6 Nov 2024 22:13:59 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="NPXhX/2o"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730931219; a=rsa-sha256; cv=none; b=tk82FAIALBkrexQ8fUYPVIhtwXXDTrlLN0h7kUX/w+fC7sVyolSXceHtKAoVEx3Faoqi0e RtXKRXylz+vBqd6xI4e1+zDoGHZWvM72NUViAYv8HfVDBiBfFtpRRpTgRV/HzSPgT3OR7J MZbPBXsSO9RPPvs5aB8t6y4ISt7lqEU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="NPXhX/2o"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.176 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=1730931219; 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=cbER8uQRgMc3lGFT4u7VFeg6pXjRf9IXs/IQf6vmq6s=; b=4bJU+At3gCV0A6W0xtVYWj69pVzfS31WI46MRe7VHLcSl7180XH5dOJV3v9OdDLyJ/SCsq ShdetASRpI5wTvdvyLZjeoq31QpCRosJkA+8TUgVuPpUPkjjpczDQ7xi/5MNm5qNk4GV09 wJFh11+1G0Xw3FvkFODCU5LVp+jvEEM= Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-6e35bf59cf6so14280787b3.0 for ; Wed, 06 Nov 2024 14:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730931277; x=1731536077; 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=cbER8uQRgMc3lGFT4u7VFeg6pXjRf9IXs/IQf6vmq6s=; b=NPXhX/2ox2p51O8Y8qhbTISaoSKvIKfeInu8QT1Yqk98d1xGbPrB6BMToWU3sGd8OC SsIPlMePfnBvmXr9z22H58A7QCN1K37eXcu/hw0zxIlTuYAcHP/mkDCoPWGUEz31Arf/ OHx9WAaXG6YpI7wQ1KIJ2Z9wWg1poMj+ZWy28N2RECIvBHRyKao4TpyMxVeBF0zNLkif rR7ZUzMc8hk7IIQcJiGSew4ikvhVaQ9iDN9IvgGUvl+dwA2ZeOea5CjiIl2Ep19IcyTb QQedlYNPawXHcsHJ6tDvMGpjGJeEvKCnZNkQVOZi3qMlwGvy+NJMiNBLMoh5UurTCYma oZyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931277; x=1731536077; 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=cbER8uQRgMc3lGFT4u7VFeg6pXjRf9IXs/IQf6vmq6s=; b=h++aFogyDz3LhDfKpWWv5sg+JLhXYnJ1hEmnC/yvFJQF6cweAsghqMq4NwPwiS3INb fBe7Tq1qfREpyOvICujmAKUktudPJZCgpzma4+oEhbSAPDVVW1pDQzYCdzaHBnQThPC6 Cq8fx8KHyHlysSNZMAvHqVnwoRYfIKIbl0KOkkUj55+gR9ix9GGLOzbkT7utLVP0Qp9s KC2PMKjDUOJp/FB8vcfFbce6/ULSIlXrjDo0ZKJCy6oA/FpPvSFNvhXVvpPyxKRqJI6J zi7DOcKEz28TrHt2Ks3xQI8TiTjUHFvMwazOQ8Q0QZF1FbYFgx+FAbmNLQYIbRHQLmkq A5zw== X-Forwarded-Encrypted: i=1; AJvYcCVlF8Y4mXzRTc41VNPCCiHByiGR1nRWIxYiR9NIpmA/Zv2cpg1U9xd5SGaN98fHG/ShxHnFKkqUcw==@kvack.org X-Gm-Message-State: AOJu0YysCPYIJqdkQflkI0uYkSxyh4qhG3x6gbZq8stC+12R4iSjdsYN QR4lvG9Ytu0KWRZ25HFKOgvhn1GhcM8C2PerYWuLeAOdGbOMijsf X-Google-Smtp-Source: AGHT+IGszx+ho52yOVYH5yhv/l6mOK19o5HKqSOg2vLBuohvAZ7xFIBSVJm6ut1NbuJt/3OD0+/bdw== X-Received: by 2002:a05:690c:23c5:b0:6db:e1e0:bf6a with SMTP id 00721157ae682-6eacbff145fmr10678587b3.7.1730931277584; Wed, 06 Nov 2024 14:14:37 -0800 (PST) Received: from localhost (fwdproxy-frc-002.fbsv.net. [2a03:2880:21ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb7a578sm185057b3.102.2024.11.06.14.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:14:36 -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 2/2] memcg/hugetlb: Deprecate hugetlb memcg try-commit-cancel charging Date: Wed, 6 Nov 2024 14:14:34 -0800 Message-ID: <20241106221434.2029328-3-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-Rspam-User: X-Rspamd-Queue-Id: B8DF3100004 X-Rspamd-Server: rspam01 X-Stat-Signature: ntdgzpq384iq5o6en94r3gtm4qqpoim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wDVBnv1OxmOZ+KdF/zKCXT6h3LELi6XJ+6y5MaEfRglcp3NDG18Cm8Q7/4uP+wXX4+NKMTa3MEMcZAcGPbg4riuj7U0UKSHTRm2d/99P46Lbjppla0P1ud0ZwgKEqaVcUs+f6mTUnmJzTMGe/HDfcTQfWY4qlStB6BlATU7olmyYuiI8Cafi9oXCqMqRIJ/UbdGhUMK0F6G1OqdSQmRo1zVAP2gsefhikwyPCYlAw8Hmslmy9fn/1KtMnYCHt6aN0jahn7w7h6JJlQ1a07U7R9ka8slmr0wfaTKHTXgPQ49Au3ttNELhbAz0MLrKDyYUTSmzq/WJ3sU/q3jN34lWN1c7qrY61W8s= 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 deprecates the memcg try-{commit,cancel} logic used in hugetlb. Instead of having three points of error for memcg accounting, the error patch is reduced to just one point at the end, and shares the same path with the hugeTLB controller as well. Please note that the hugeTLB controller still uses the try_charge to {commit/cancel} protocol. Signed-off-by: Joshua Hahn --- include/linux/memcontrol.h | 3 +-- mm/hugetlb.c | 35 ++++++++++++----------------------- mm/memcontrol.c | 37 +++++++++---------------------------- 3 files changed, 22 insertions(+), 53 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 25761d55799e..0024634d161f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -696,8 +696,7 @@ static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, bool memcg_accounts_hugetlb(void); -int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, - long nr_pages); +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp); int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, gfp_t gfp, swp_entry_t entry); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index fbb10e52d7ea..db9801b16d13 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2967,21 +2967,13 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, struct hugepage_subpool *spool = subpool_vma(vma); struct hstate *h = hstate_vma(vma); struct folio *folio; - long map_chg, map_commit, nr_pages = pages_per_huge_page(h); + long map_chg, map_commit; long gbl_chg; - int memcg_charge_ret, ret, idx; + int ret, idx; struct hugetlb_cgroup *h_cg = NULL; - struct mem_cgroup *memcg; bool deferred_reserve; gfp_t gfp = htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; - memcg = get_mem_cgroup_from_current(); - memcg_charge_ret = mem_cgroup_hugetlb_try_charge(memcg, gfp, nr_pages); - if (memcg_charge_ret == -ENOMEM) { - mem_cgroup_put(memcg); - return ERR_PTR(-ENOMEM); - } - idx = hstate_index(h); /* * Examine the region/reserve map to determine if the process @@ -2989,12 +2981,8 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, * code of zero indicates a reservation exists (no change). */ map_chg = gbl_chg = vma_needs_reservation(h, vma, addr); - if (map_chg < 0) { - if (!memcg_charge_ret) - mem_cgroup_cancel_charge(memcg, nr_pages); - mem_cgroup_put(memcg); + if (map_chg < 0) return ERR_PTR(-ENOMEM); - } /* * Processes that did not create the mapping will have no @@ -3056,6 +3044,12 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, /* Fall through */ } + ret = mem_cgroup_charge_hugetlb(folio, gfp); + if (ret == -ENOMEM) + goto free_folio; + else if (!ret) + lruvec_stat_mod_folio(folio, NR_HUGETLB, pages_per_huge_page(h)); + hugetlb_cgroup_commit_charge(idx, pages_per_huge_page(h), h_cg, folio); /* If allocation is not consuming a reservation, also store the * hugetlb_cgroup pointer on the page. @@ -3092,13 +3086,11 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, } } - if (!memcg_charge_ret) - mem_cgroup_commit_charge(folio, memcg); - lruvec_stat_mod_folio(folio, NR_HUGETLB, pages_per_huge_page(h)); - mem_cgroup_put(memcg); - return folio; +free_folio: + spin_unlock_irq(&hugetlb_lock); + free_huge_folio(folio); out_uncharge_cgroup: hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), h_cg); out_uncharge_cgroup_reservation: @@ -3110,9 +3102,6 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, hugepage_subpool_put_pages(spool, 1); out_end_reservation: vma_end_reservation(h, vma, addr); - if (!memcg_charge_ret) - mem_cgroup_cancel_charge(memcg, nr_pages); - mem_cgroup_put(memcg); return ERR_PTR(-ENOSPC); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 59dea0122579..3b728635d6aa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1448,8 +1448,7 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) u64 size; #ifdef CONFIG_HUGETLB_PAGE - if (unlikely(memory_stats[i].idx == NR_HUGETLB) && - !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING)) + if (unlikely(memory_stats[i].idx == NR_HUGETLB) && !memcg_accounts_hugetlb()) continue; #endif size = memcg_page_state_output(memcg, memory_stats[i].idx); @@ -4506,37 +4505,19 @@ bool memcg_accounts_hugetlb(void) #endif } -/** - * mem_cgroup_hugetlb_try_charge - try to charge the memcg for a hugetlb folio - * @memcg: memcg to charge. - * @gfp: reclaim mode. - * @nr_pages: number of pages to charge. - * - * This function is called when allocating a huge page folio to determine if - * the memcg has the capacity for it. It does not commit the charge yet, - * as the hugetlb folio itself has not been obtained from the hugetlb pool. - * - * Once we have obtained the hugetlb folio, we can call - * mem_cgroup_commit_charge() to commit the charge. If we fail to obtain the - * folio, we should instead call mem_cgroup_cancel_charge() to undo the effect - * of try_charge(). - * - * Returns 0 on success. Otherwise, an error code is returned. - */ -int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, - long nr_pages) +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp) { - /* - * If hugetlb memcg charging is not enabled, do not fail hugetlb allocation, - * 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) || !memcg_accounts_hugetlb()) + struct mem_cgroup *memcg = get_mem_cgroup_from_current(); + + if (mem_cgroup_disabled() || !memcg_accounts_hugetlb() || + !memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) return -EOPNOTSUPP; - if (try_charge(memcg, gfp, nr_pages)) + if (charge_memcg(folio, memcg, gfp)) return -ENOMEM; + mem_cgroup_put(memcg); + return 0; }