From patchwork Wed Dec 11 20:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13904131 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 3BA55E77180 for ; Wed, 11 Dec 2024 20:40:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77AF36B0088; Wed, 11 Dec 2024 15:39:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68EE56B0089; Wed, 11 Dec 2024 15:39:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46ED26B008C; Wed, 11 Dec 2024 15:39:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 203946B0088 for ; Wed, 11 Dec 2024 15:39:59 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DBDFFA171D for ; Wed, 11 Dec 2024 20:39:58 +0000 (UTC) X-FDA: 82883843994.13.21DAECC Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by imf19.hostedemail.com (Postfix) with ESMTP id 09B371A0012 for ; Wed, 11 Dec 2024 20:39:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M1V02cay; spf=pass (imf19.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.176 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=1733949585; 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=TB7w562sxA4ON1zeYB8I14khwhTIPTHUGFUW2mmo+w4=; b=0dZWkoMDkRpJRTs7pIpJkC8wY8Jrl7w3Jhh7Div51tJ2Yy3OWb6BwleClNmCAZ6QdhpmFg W2uTg7SKZrFLSCG9riZkOsogOLGvY3ZOez6Q4KlgwZQ2WZmMtFfysB0d476sFw0aChJFL7 Zb9tz3Yk2CzzsFo+bdsNaFPQsz5Brdg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733949585; a=rsa-sha256; cv=none; b=z7uhArANm8dIwy3vntMiJslkpzafpy0B52nyvMh8H6te9r9wTT2yrADfYZ6/NDnk0tS+Pm 1QWJxjrkDB1uLnuCKKLGjNJZiajgU4q3gvIyfHnPeYTjGcfA//r/mbIurMirZPVF1X+Wov tJV/G6IxVQ/JKHAvcHKppj2PmB+kb6k= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M1V02cay; spf=pass (imf19.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.176 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-6eeca160f14so61295437b3.2 for ; Wed, 11 Dec 2024 12:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733949596; x=1734554396; 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=TB7w562sxA4ON1zeYB8I14khwhTIPTHUGFUW2mmo+w4=; b=M1V02caygmUpwndr8KRDvkvA6lyzRA8YHJVW73Fnm4vNqruymC4i0E+kYUsx/wF/SP t4PioqBcqZELX9oyTrfvO/OyAz4vhifD6UnWcavJnT/hjLKnN2JJ8MtKjMTpzDnmJwpW la7rhc+NeRVuYFXibYFYg3pyi9QvpmJw8VdxTXbScNPWUPcB3ZDXUrlboWfpZ1UpnAdB GYhTOS3NVt4xPpQDwqNMePKKT3Z356PDPGQHzyiC2BX2VdEMzOrRCMWOhSZX8s9KBPxR KkJxUxFjQ/RpZ06krfYG4dZbVznLX4J8u6K3/Q3JDdKgxgVZ6tBUUfd0US5uBDtZ2ozf zxYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733949596; x=1734554396; 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=TB7w562sxA4ON1zeYB8I14khwhTIPTHUGFUW2mmo+w4=; b=lXhYGFTTQl67LMmM35FdrRvUueFJ5YjNGcFRbeSSRt/t9UhenZ5p+I60K6ckqRQHSa UJDmz10e1zW9igzv12C43oR6nye7WonA15DDNHIpvUrYn2SpFzSJHC2u7/pRzdGtPBr6 0OjqIVinhKn95sau10ppSEyHSMRIzochx1pKwQH6Fn6aKgSeo3S+PWNlagQCZLMkyd2E qwtsIrKHfLE/XXlhuw1Wq7SaMKLO726pMyUOr9fHcTKpUj6HrFHa3mK+EEZEHltggOoI jFr5rIjlEA117RLA+aGGe1fW1vxNoejqvG7Pe6zC2923hhjJZvKaF9n3C92AJti7znRW RcVg== X-Forwarded-Encrypted: i=1; AJvYcCX9kcj8nt4kI7YpOrO0YkBibpCxjuXrqQ4VFkAN1amnq1AwmGWD3Z5kNsq+GVIkJCITdf15gv1uSg==@kvack.org X-Gm-Message-State: AOJu0Yx5m+tKph3Pl/yUUpz0Cp3BDWVgP0UZRQf95/cSyexjrXKHvqXe xLZ/gFfAIiZ/lJDltYcLfiaqPW5mBjhqztNYvLvKncRWx9Qx4Sj0q5DJCewq X-Gm-Gg: ASbGncuoB9xx8cqB92Ji0ut9ftztbNbPySubZFAg4r17vCdgTQ0BojV9991vlguSRet MpfjdT2ingf4a59B06ksAZaF7YczWxK9eL534QTCHOCiNecZxWefR8qqDFm5GWdHU2CSqj0XSYv gfleYH3cTaprXKS33S4Pf3ZlPrXaHWYsO6xQ0Rlu9k73vpK1LgIHsBZiJ3krJwFgbUDtqpH3ZHi m4egyEqd675bLK/rHjzgwTOluZf1LLxeECtZ/3s4BnyknCbMc6VavmQzTiQtKR8RmFMVvHoH/8m nLf4IICI7yMq5A== X-Google-Smtp-Source: AGHT+IHKldzU41mVArIiVR43SbQPj9lPuiGmJL7kSl+CvnB5gG8KxKv/VPEhLHgXKWwXvwNSDfRJ8g== X-Received: by 2002:a05:690c:6610:b0:6ef:504e:a50a with SMTP id 00721157ae682-6f198a3cf33mr14425157b3.2.1733949596093; Wed, 11 Dec 2024 12:39:56 -0800 (PST) Received: from localhost (fwdproxy-nha-002.fbsv.net. [2a03:2880:25ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e3c94b436f9sm455633276.42.2024.12.11.12.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 12:39:55 -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, sj@kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 3/3] memcg/hugetlb: Remove memcg hugetlb try-commit-cancel protocol Date: Wed, 11 Dec 2024 12:39:51 -0800 Message-ID: <20241211203951.764733-4-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211203951.764733-1-joshua.hahnjy@gmail.com> References: <20241211203951.764733-1-joshua.hahnjy@gmail.com> MIME-Version: 1.0 X-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RWfI2KaiQL9p5XB1bfayF pJZYVbyQ Ae6YWWkH1u4CPBoK7k/OTDCKn16Obtiiar7mePSgalhIUyFn8/xgy76W7PYSxBZizVTDkJIHN4bX0Mkiyz8v7IqE24klhL7Qfd7QYjWmacsiSk2a1Iv2OIXoA2zsjVJePn0nMKlatf/dSaSFo7WuuZjGs3nSSLGt/E4Juck5sl4ghqyYwS3jsWefHaWhodZL0pCZnISZr8Z1F5xQMQLvJ9zvfOf86dS0hPaJV7V4B2HtYpreJ2hVQqIA2eUgpWJN1+Ni8Qtqlkm7+dYmxQpuGozWKYzCm++rurSztzIWATmeuIPIbzdq5kl0QUd7ZCurWIf921mGjSbM2AzIVzZZJfkxJyk3fS08RwYbbvcIeQKHxlPaTW95b4wkYabak9AGApcyXqzXYhYnJjcY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, 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 fully removes the mem_cgroup_{try, commit, cancel}_charge functions, as well as their hugetlb variants. Signed-off-by: Joshua Hahn Acked-by: Shakeel Butt Reviewed-by: Nhat Pham --- include/linux/memcontrol.h | 22 ------------- mm/memcontrol.c | 65 ++------------------------------------ 2 files changed, 3 insertions(+), 84 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d1ee98dc3a38..e1a9998d8add 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -620,8 +620,6 @@ static inline bool mem_cgroup_below_min(struct mem_cgroup *target, page_counter_read(&memcg->memory); } -void mem_cgroup_commit_charge(struct folio *folio, struct mem_cgroup *memcg); - int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp); /** @@ -646,9 +644,6 @@ static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, return __mem_cgroup_charge(folio, mm, gfp); } -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, @@ -679,7 +674,6 @@ static inline void mem_cgroup_uncharge_folios(struct folio_batch *folios) __mem_cgroup_uncharge_folios(folios); } -void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages); void mem_cgroup_replace_folio(struct folio *old, struct folio *new); void mem_cgroup_migrate(struct folio *old, struct folio *new); @@ -1137,23 +1131,12 @@ static inline bool mem_cgroup_below_min(struct mem_cgroup *target, return false; } -static inline void mem_cgroup_commit_charge(struct folio *folio, - struct mem_cgroup *memcg) -{ -} - static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp) { return 0; } -static inline int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, - gfp_t gfp, long nr_pages) -{ - return 0; -} - static inline int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, gfp_t gfp, swp_entry_t entry) { @@ -1172,11 +1155,6 @@ static inline void mem_cgroup_uncharge_folios(struct folio_batch *folios) { } -static inline void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, - unsigned int nr_pages) -{ -} - static inline void mem_cgroup_replace_folio(struct folio *old, struct folio *new) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c903e260a830..7ddbb2d12eb9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2383,21 +2383,6 @@ int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, return 0; } -/** - * mem_cgroup_cancel_charge() - cancel an uncommitted try_charge() call. - * @memcg: memcg previously charged. - * @nr_pages: number of pages previously charged. - */ -void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) -{ - if (mem_cgroup_is_root(memcg)) - return; - - page_counter_uncharge(&memcg->memory, nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&memcg->memsw, nr_pages); -} - static void commit_charge(struct folio *folio, struct mem_cgroup *memcg) { VM_BUG_ON_FOLIO(folio_memcg_charged(folio), folio); @@ -2411,18 +2396,6 @@ static void commit_charge(struct folio *folio, struct mem_cgroup *memcg) folio->memcg_data = (unsigned long)memcg; } -/** - * mem_cgroup_commit_charge - commit a previously successful try_charge(). - * @folio: folio to commit the charge to. - * @memcg: memcg previously charged. - */ -void mem_cgroup_commit_charge(struct folio *folio, struct mem_cgroup *memcg) -{ - css_get(&memcg->css); - commit_charge(folio, memcg); - memcg1_commit_charge(folio, memcg); -} - static inline void __mod_objcg_mlstate(struct obj_cgroup *objcg, struct pglist_data *pgdat, enum node_stat_item idx, int nr) @@ -4510,7 +4483,9 @@ static int charge_memcg(struct folio *folio, struct mem_cgroup *memcg, if (ret) goto out; - mem_cgroup_commit_charge(folio, memcg); + css_get(&memcg->css); + commit_charge(folio, memcg); + memcg1_commit_charge(folio, memcg); out: return ret; } @@ -4527,40 +4502,6 @@ int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp) return ret; } -/** - * 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) -{ - /* - * 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()) - return -EOPNOTSUPP; - - if (try_charge(memcg, gfp, nr_pages)) - return -ENOMEM; - - return 0; -} - /** * mem_cgroup_charge_hugetlb - charge the memcg for a hugetlb folio * @folio: folio being charged