From patchwork Fri Nov 8 21:29:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13868974 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 69E2CD6408E for ; Fri, 8 Nov 2024 21:29:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B16D900009; Fri, 8 Nov 2024 16:29:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F55900007; Fri, 8 Nov 2024 16:29:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B30F900009; Fri, 8 Nov 2024 16:29:54 -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 DEB8E900007 for ; Fri, 8 Nov 2024 16:29:53 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A1D8C1A0132 for ; Fri, 8 Nov 2024 21:29:53 +0000 (UTC) X-FDA: 82764219888.28.DAC571C Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf23.hostedemail.com (Postfix) with ESMTP id 6D74814001A for ; Fri, 8 Nov 2024 21:29:27 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JtWbtyj7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.177 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=1731101306; 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=dcz0dG1cPpUACCNHLbhNPDeGAN7gwrWZYHnMXSk4J1Y=; b=aXA77tAhltqA4asB+NxHk++7rwV9US75JAnQqUQunw7j/OOt4nxjHppLneI2VXPbevujSn DAm4AGJ4wgfC2v8nR5lIykX/cSdQXqUvdsOuiFHHGo8eNL9YXxKJ2ziJEd/R6MZq/wzAp8 8nQ3EDw/1LtM2Q64+LQDMWmqUnUej0M= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JtWbtyj7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731101306; a=rsa-sha256; cv=none; b=d269GbQJn0oAZJDoHa2593kq+mGS4IKVMOcVMEwvjlA+QqDTUkZFACvtUVRkgitWIw/uXa jjEAoXC0GB0WPt06VD5NE6uE9azpUQKP31wFvkZm6eHuG1w/BaCqHvaZwe7ilP02vMjdGM emVSJljfxRfFVO3+hpHwVK8ByO/NRa8= Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e0875f1e9edso3520913276.1 for ; Fri, 08 Nov 2024 13:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731101391; x=1731706191; 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=dcz0dG1cPpUACCNHLbhNPDeGAN7gwrWZYHnMXSk4J1Y=; b=JtWbtyj7jIv/NiEOr2ytK+cPfMLS0bm5jbPuZk8QTJZr84LJADQPvaKE8ZL0mxcn5T zyJzV+m4hTqrNa8ZerZT6YRRfmZT9UDjECwrxPuFz6XehOSgfYL9ncW57mfO+eK5b04o vmEdeoB1OxUV20OKjlk6uv1y6r2KGeoU7UwcC8473SosQBfxfyTAluCGZ5GUjJ6z2nMO RIjwzUxeZDdiL1VkHIKg5j3Doge11NxNUCX7JGNR4ZPf4wUU0VBQF/USdIXRsNwQoZfr 8T5inc6qRtgNjFiB80Ie2L1BeLKeGE7J90JFY297DeaZxxSSZSoW4FhuaE3NBXB45l74 EniA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731101391; x=1731706191; 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=dcz0dG1cPpUACCNHLbhNPDeGAN7gwrWZYHnMXSk4J1Y=; b=C5jSj+ObS9+pC2iLGUNZ0xoFJwOMmqeqpCr44d/76i7FAM6xNWtJ0E9Utx7m/kx/Wz MU2bFqnYuXl497J7O8TKoJsU6YVyR7YQJm6nnI8Rf+2E77fhKrmRNPxF9sG7bjXgZOa0 ITz6YRpJ4r1ulwI0Stef/s2lvcnvnMXzOQ8EXGxYi7X/yPTN6ielmgPlUMdkd8UuAz5I ZYc7Qb7ivlNvHyXkbSyrklgzpApEo2VlE3xfVefmz647lZVfu/dd0+K9o6rYZzSI2PE6 OxN4+u1+RGeUX+MN2fbxAd1zjeNmhjaZyIGgRuWBZBwd05M9inLc0rVdVWHuGWUFAILz ilzQ== X-Forwarded-Encrypted: i=1; AJvYcCXJZCGnx/qEp2osvyycpazcUDT0RXIvliacjOV8ZewhnhA2hFpT9R0vkJqVOptMBxCGo2cVU4Bltw==@kvack.org X-Gm-Message-State: AOJu0YyqiOEv/7nLcXs5JGojX9/XmHrA6o7PaIc/rXQlNkAwthrKLWBF eceqnkSj1jGMeeVYr3loQPj3CTqRWRPTKRSOP3JnblWm1xI7n1Lt X-Google-Smtp-Source: AGHT+IERNM8wQh4xbgTwcMUCkqiXB1m2+0T8XSuh0sv/LdGiPNf/7fQwQby4VwiHvmPjI5CuC9oBug== X-Received: by 2002:a05:690c:6890:b0:6e3:1869:8983 with SMTP id 00721157ae682-6eaddfd3d0dmr42837497b3.40.1731101390852; Fri, 08 Nov 2024 13:29:50 -0800 (PST) Received: from localhost (fwdproxy-frc-001.fbsv.net. [2a03:2880:21ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb90192sm8872727b3.128.2024.11.08.13.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 13:29:50 -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 3/3] memcg/hugetlb: Deprecate memcg hugetlb try-commit-cancel protocol Date: Fri, 8 Nov 2024 13:29:46 -0800 Message-ID: <20241108212946.2642085-4-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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6D74814001A X-Stat-Signature: xcwj6ht8a5jgk487pfkccrkg3q6oss6w X-HE-Tag: 1731101367-587530 X-HE-Meta: U2FsdGVkX1/ulJUKQh0VAtTEl4ORy7/NbK4a6diuf2b4fERRwT+JZE+rG6q+/voodwwcLFxjWcJg/zSYSDVbvEmqQ7EZsyyijdXegvgQCRa/kCMHl/xeZB7b4J9eLsD3bwLB2NKg2a5a+1xKiK0g0j/VWv+YCgNVyAsxfgOAopZpJn5RIEg9eD5sZ0X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PjzpmJakl9tDsPjRGTMWg3ludNXZ84UjrhKjk6yiU/0yCXiZqLie5ZgZDIciC9/Ain5aO0pNd08OG8PPxjbB2tmvohXj9eRWCUz6Am1aiczXfC/WW28cQekl38MB4 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 fully deprecates the mem_cgroup_{try, commit, cancel} charge functions, as well as their hugetlb variants. Please note that this patch relies on [1], which removes the last references (from memcg-v1) to some of these functions. Signed-off-by: Joshua Hahn [1] https://lore.kernel.org/linux-mm/20241025012304.2473312-1-shakeel.butt@linux.dev/ Acked-by: Shakeel Butt --- 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 d90c1ac791f1..75f15c4efe73 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -649,8 +649,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); /** @@ -675,9 +673,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, @@ -708,7 +703,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); @@ -1167,23 +1161,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) { @@ -1202,11 +1185,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 95ee77fe27af..17126d8d263d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2351,21 +2351,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); @@ -2379,18 +2364,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) @@ -4469,7 +4442,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; } @@ -4495,40 +4470,6 @@ 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) -{ - /* - * 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; -} - int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp) { struct mem_cgroup *memcg = get_mem_cgroup_from_current();