From nobody Sat Nov 23 21:30:25 2024 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00CC91D433B; Fri, 8 Nov 2024 21:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101391; cv=none; b=JnvjsHexTLVLXg0fSvJtjHkvCG+5y7Vg6AfKkMfkBprloqxS6ZiIZ4CKW4NXvvFwA8uSfEeSQHuaDzzNvWkv3ZmxY+lvPVUrh8I5Azk0zRfK23Nuyia/pC9JrToUGuUL58Wm9pnLs/9wV385hWFnuGxGEnb6x+Ok+5IxK/E0DSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101391; c=relaxed/simple; bh=uDe75mGVAgR4Zl0Pa84zl9hX5eEEU4/X5U/C46L3p2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=irCebkknP3/TR9ongfq2lzTgMsLzTiFSbyQZHwG4rhLk9wW4HZXTDKiH9QjWHNaiRIcjapLCdVdWRTta8AAzho+Iw3fpPZSU76wK15PdS5LUGEajTOeURlET57xTq+oza/29a0pkLze7IWPJCkOlQXk9tRGLkcnyFMuU32F6FgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TcC9T+S6; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TcC9T+S6" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e2974743675so2488069276.1; 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=vger.kernel.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=TcC9T+S6FU/OzQ/8UcBg8Od32LjzcrByNFCShnKvaS+TGhMJXscXM0MCdx95xT+gt5 c6qBY28GOghb6IHO/jwg5q8N3oqzCoPkr+hLqu2AQTRWL3eGrLA/VVbU/a0bp+59DCcX Q6d1SYxYPAsZQRMJcSoHWrdROXfu/UUbhgjEaTs1cEYLAehdu0HXEmmsVjnX4K45oDp0 ddRp+p/hLQcnRCrm3wYcXRvDm+wx2zQ7J5VivdtK4pitjoEUvWogewKx+UTI8pbvz+oX yhXXVCnRB+k5FVS3dattK/sE8ZSeQ5M+P+C4rOlXbJjrCAV+aZOFMuSjSei/dJNmtajD dMxg== 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=KclNXfk0VL7kRZx+M5ASolEt1YOR2aK4N0UBKouiJHGStEGERBVY6NQT3NCE75mwyB JIjNFq4nUqv/xQ80RO10GI6qjnUKPE5216EdoZCteoLlimpNJ/JMmFGKBKfFe2ioodtW H+0kr19amH/ZEx3Ds23HZIDtgckYZ3uKUx7IufVnARk5mZ+STjDG3WpcwFwDqcw6UNTi K3eXiXCiCZDzFX9WYjnLOxkrewocECY5/kQnZzhJVC4fQ0TzhLj1xE0xLXGd/IT2b26m 7ra0qOXKVx5cKqm4kxdRATmrgkyApaSyf/7g9fE+OiZl2cxzNatUkXdLQMTuQXYXs8IZ 2W3w== X-Forwarded-Encrypted: i=1; AJvYcCUhJ4sLVpOTyArNCeE8UvRpzcd2Y0rrvOqXdl3cw09B3OP/epg3tJkZfyBo/XBwD3pQWBdKFX7+WfVf0Ik/@vger.kernel.org, AJvYcCW4bUzPz5eUHIxvKMAoSKNjteeQr6MfmDaPFVs3D2cADP8MlTJxaXKCGQvMRTyV5dazS/PmZWma@vger.kernel.org X-Gm-Message-State: AOJu0Yx7wLK3GdHgAZufNVSdi4A1+LsoPsS57iBbZ0YsnfSpx39lZ5hR CINRMd80tXKDHvNhE6tVS3LoDVXIO9C6Wo3sW+JcH4DrxbyipAHhUkSpxw== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Suggested-by: Shakeel Butt --- 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 me= m_cgroup *memcg, int item) memcg_page_state_output_unit(item); } =20 +/* 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 *memc= g, struct seq_buf *s) =20 #ifdef CONFIG_HUGETLB_PAGE if (unlikely(memory_stats[i].idx =3D=3D NR_HUGETLB) && - !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING)) + !memcg_accounts_hugetlb()) continue; #endif size =3D 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; } =20 +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 f= olio * @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; =20 if (try_charge(memcg, gfp, nr_pages)) --=20 2.43.5 From nobody Sat Nov 23 21:30:25 2024 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF5E41EBA03; Fri, 8 Nov 2024 21:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101392; cv=none; b=QW7GAqaI9Pu/svuWsAhSLD5yUVm9zGZJlytiOfI2DWHZSH+/trQ7VpozPCMEiRemzs2nLtFf1i7WeW+4l+Aykk6WuQAngKuUwmS2odlyOLfNA5cGgrnQX3M/LYh4j1BGWkJOA2aL0gHpERYODJTGio6lLMMqG4iYRBzfzb3zqgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101392; c=relaxed/simple; bh=ZJ/UGoRVCAIi7MimytzM5Vb9VB7NvIybOtmXOb1iUVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KbUfSSKDRldZzGwY5u4yQOAktyGIdumX8iQiU9oRk04XU08pM9USeXl6MhO/nD1/+zWtS1o5bL8PECoDxcIq6x4CKA/EljeWn2E0DbwWDXqWIPUtzUDtaBqjV0/sjo+lB+X9CO0MznG3YqDOe0XJdtEqLLHWOLjjFaF2CyJRNf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C3Aj9CbV; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C3Aj9CbV" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-e28fe07e97dso2801841276.3; Fri, 08 Nov 2024 13:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731101390; x=1731706190; darn=vger.kernel.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=SlQ3sjJT81bsTmwr1uay84sXlsybFvKefjGpPF85ZWQ=; b=C3Aj9CbV1gkEOZV6ZPN/J9mq7/XY34uGApN0wY3ufRgCl/N+lJzNOYNOaDiQ1cceMH Ne3NexeV6YJkRm868syV8heXJkySKW5HLiyyVnTNtT9d5OtrakDLc3/Tcn0CDSHMFxyo MalY5TZvi1h9cyV5ZTkoJ3je+kRW0Iz8pFi5JRuoqJrjynh+wJBZ46mjNoqgKIr3Ozvg 3VPeJnpCMSTrCwn5wazFwAARhHUHyVROcKxq654RkdxGqS371ppNSlCKy9kO0axziAAB v90OK7VL6hs6WEnGc6TOQ4gNlneDf/nwxy1O9h8HvtSnN0DsVpR/C+imhXFyI8JjRigX xNqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731101390; x=1731706190; 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=SlQ3sjJT81bsTmwr1uay84sXlsybFvKefjGpPF85ZWQ=; b=Ra1MmG/eJ5H7kwHm8ESKTevHv6YKyru9Cf8098IEhXycXmci+jR6Ep+W6cLc9nHLX/ 2pfJbpeK4a1jkvc03AcjieBKcOjFiIKFkHsD6xeFLd8t1k8J0YNbd+z9Bwhj26mvs2C0 h8z885n78is3wLGWVSHP2kXsFLzxnpnbOvUt6fVSTUmfkweZgQYu9BsYe4LmF5+5OqKn S+mpRY/YEzbqZ2ji3BwYMxArL4YlQXqQ5wurda/kTpMiOhAZ8mLwcStkwOtkWu0ga5HR VNUQK2wvoaDHSEfPRld03zDseVudqXTJNIKSWCXPkkA+hzfdIxjf2wOOz+4fTuWfWCzr Yuhw== X-Forwarded-Encrypted: i=1; AJvYcCUrBtllv2VYw37X70ESG3Vr/HgMt9glCmBZ8DX+lSbwzVZ5fTXtMGAWN2TFaul6nCIWZ+vX7qRe@vger.kernel.org, AJvYcCXeWM4T0/ppMNkySJDZxDAzphXnKuFDetpOyfgTX7kwkFEbcx/t7aMDurxAWz+3SAw1IFY2oWUAkAZkWVzg@vger.kernel.org X-Gm-Message-State: AOJu0Yy67D8hxEJlcSnYTOgDcYa4+H3YL4GmQ6C2L5520B1QEdHJQRx0 jkJlhD4BKYo7D71Xr8yMi1V2YaLeMO7gIk5Qy6q64lcz73G2mR0F X-Google-Smtp-Source: AGHT+IFYGeqK9WHN6tzmVfn8RrbnYZR+fESmtaRa7GS9uP5CtuQHP1PNtDJrSMzfXRi9Cqzl4/l5eQ== X-Received: by 2002:a05:690c:7308:b0:6e3:3521:88ff with SMTP id 00721157ae682-6eaddd9507amr55794997b3.18.1731101389891; Fri, 08 Nov 2024 13:29:49 -0800 (PST) Received: from localhost (fwdproxy-frc-005.fbsv.net. [2a03:2880:21ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8ee1c0sm8850617b3.28.2024.11.08.13.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 13:29:49 -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/3] memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb Date: Fri, 8 Nov 2024 13:29:45 -0800 Message-ID: <20241108212946.2642085-3-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces mem_cgroup_charge_hugetlb, which combines the logic of mem_cgroup{try,commit}_hugetlb. This reduces the footprint of memcg in hugetlb code, and also consolidates the error path that memcg can take into just one point. Signed-off-by: Joshua Hahn Suggested-by: Shakeel Butt --- include/linux/memcontrol.h | 2 ++ mm/hugetlb.c | 34 ++++++++++++---------------------- mm/memcontrol.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index bb49e0d4b377..d90c1ac791f1 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -678,6 +678,8 @@ static inline int mem_cgroup_charge(struct folio *folio= , struct mm_struct *mm, int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, long nr_pages); =20 +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); =20 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index fbb10e52d7ea..6f6841483039 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2967,21 +2967,13 @@ struct folio *alloc_hugetlb_folio(struct vm_area_st= ruct *vma, struct hugepage_subpool *spool =3D subpool_vma(vma); struct hstate *h =3D hstate_vma(vma); struct folio *folio; - long map_chg, map_commit, nr_pages =3D 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 =3D NULL; - struct mem_cgroup *memcg; bool deferred_reserve; gfp_t gfp =3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; =20 - memcg =3D get_mem_cgroup_from_current(); - memcg_charge_ret =3D mem_cgroup_hugetlb_try_charge(memcg, gfp, nr_pages); - if (memcg_charge_ret =3D=3D -ENOMEM) { - mem_cgroup_put(memcg); - return ERR_PTR(-ENOMEM); - } - idx =3D 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_str= uct *vma, * code of zero indicates a reservation exists (no change). */ map_chg =3D gbl_chg =3D 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); - } =20 /* * Processes that did not create the mapping will have no @@ -3092,10 +3080,15 @@ struct folio *alloc_hugetlb_folio(struct vm_area_st= ruct *vma, } } =20 - 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); + ret =3D mem_cgroup_charge_hugetlb(folio, gfp); + if (ret =3D=3D -ENOMEM) { + spin_unlock_irq(&hugetlb_lock); + free_huge_folio(folio); + return ERR_PTR(-ENOMEM); + } + else if (!ret) + lruvec_stat_mod_folio(folio, NR_HUGETLB, + pages_per_huge_page(h)); =20 return folio; =20 @@ -3110,9 +3103,6 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *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); } =20 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 97f63ec9c9fb..95ee77fe27af 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4529,6 +4529,25 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup = *memcg, gfp_t gfp, return 0; } =20 +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp) +{ + struct mem_cgroup *memcg =3D get_mem_cgroup_from_current(); + int ret =3D 0; + + if (mem_cgroup_disabled() || !memcg_accounts_hugetlb() || + !memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) { + ret =3D -EOPNOTSUPP; + goto out; + } + + if (charge_memcg(folio, memcg, gfp)) + ret =3D -ENOMEM; + +out: + mem_cgroup_put(memcg); + return ret; +} + /** * mem_cgroup_swapin_charge_folio - Charge a newly allocated folio for swa= pin. * @folio: folio to charge. --=20 2.43.5 From nobody Sat Nov 23 21:30:25 2024 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E23D91F26E0; Fri, 8 Nov 2024 21:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101393; cv=none; b=HUaD6T+6dobwFj9taKp6SUkRII/ZR4NEm0ibVaYRmnYZwTqbzuReuKP85eUEQKwisFdLJ/tqt2spYtSnXNJBWfK/nPUsD8lC4o5MU8tDpLuof6L/yaU4GnAd+cMTcTcp27ENPH28uIOb7obJ+qg7ba0ZPwiwCnt58uBw0GEsFoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731101393; c=relaxed/simple; bh=n/ekMca5sJkKEIQjCNmx2lVdFdZLj+8yltjIR9nyNcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EEXvkW2Vw19QUEH/3iAJvOSY4tSg/b1krVBN7KUCRekRo9y1YIYP/X9nleK5fvQi1gRRdmYTxcZRgIfoqm5vZE7IrKe34c8S/6zdyjaiv/Ef4hc/lAtj7X0I9JEg/q//leqUdRW8WoJu2y1ju2Y2QHsojISOkJY77lpCx3WrMXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CzZNLJT/; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CzZNLJT/" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6eacc99a063so27489937b3.3; 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=vger.kernel.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=CzZNLJT/lsEvRHEVnpDpRDYU6CtmC1lyd4l6vSxHlao3JjPuUOCHjaEM1B7Amms7UG Sy3XNIA9X5vSNlMM7OUOFNzNN5wIXi0GVvrreAdbWhNnGt6iGxIGai+VJFi5pV2zw91J ra6re50yrI8r9TyJ16zbdM/4ovCn981X3mf1v4ak+/jFsWY+Dpnja8B3oF241jTuag/+ qBcq9JlMsql2XmUvjFqrSO3/QJM6dTrEThlCi+y8DL7syBuNrrdFpTKRTBOYX9KB7JP9 oojBUFgkrU6v8Tm1a3xDlP3b4q/PkloE+H2O/oLhCZKuAcUF+V3C9HtGNLRclQ8c9svz Ikzw== 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=aPNKDXdL1JFu5l4k35Z3oPikMnRFJW/tzpPHUdLFhc2hITpZecyrJK78bUAsrTGDCb I9+CfeG9fxA8RWIjVcFbeNJR0WGWQb1sCxaIcW3EWBkkV4aixRQB/yPa+8reRGoO5/Ss sEx8CU9rMJLIh0OaWQm+YRZL/6Pxwgv/e1cNpjsqhp1VG1dUFYGcAjsISOl0u86hVXnu Imk6IYEgxHpXJ++yNn7xzgLI9G9tZdGHV3z/UnN/p8Ym/MBPtnTH+PvMvV0F2MWafUoy phfiN06jTdVxD1Z+dObuOI2vBtRTqCkY1so4nAs73iA5t4+MplDX6IOYTHjtXY1VU2YX 6TNw== X-Forwarded-Encrypted: i=1; AJvYcCUnfXkvXLl+jBuFaQp/dwT+bxFZxVf6ms6USh47TT1pRPa+7hmnyMYcdeuVBiEDHdSfUDXO+WpcVd8rSJoA@vger.kernel.org, AJvYcCXCCObboNMgWdiCJSVYl2Ehtpb89xZw13746zjcLsAZ/MEzRstnqLUT60vlyrEixYIXaYWVQYdP@vger.kernel.org X-Gm-Message-State: AOJu0YxlZP7Y90u1BJPLtMuzFEAuGYdmZQCS4E2jUWGbD2iFhSIWJ14e ZZm6po2gGVAlu65YvbujZOkc8G/5K0w9SfA0eYSmnKZl8AB0ufR3 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Suggested-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_cgro= up *target, page_counter_read(&memcg->memory); } =20 -void mem_cgroup_commit_charge(struct folio *folio, struct mem_cgroup *memc= g); - int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t g= fp); =20 /** @@ -675,9 +673,6 @@ static inline int mem_cgroup_charge(struct folio *folio= , struct mm_struct *mm, return __mem_cgroup_charge(folio, mm, gfp); } =20 -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); =20 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 fo= lio_batch *folios) __mem_cgroup_uncharge_folios(folios); } =20 -void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pa= ges); void mem_cgroup_replace_folio(struct folio *old, struct folio *new); void mem_cgroup_migrate(struct folio *old, struct folio *new); =20 @@ -1167,23 +1161,12 @@ static inline bool mem_cgroup_below_min(struct mem_= cgroup *target, return false; } =20 -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; } =20 -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) { } =20 -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; } =20 -/** - * 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_pa= ges) -{ - 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, struc= t mem_cgroup *memcg) folio->memcg_data =3D (unsigned long)memcg; } =20 -/** - * 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 *memc= g) -{ - 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 m= em_cgroup *memcg, if (ret) goto out; =20 - 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 } =20 -/** - * mem_cgroup_hugetlb_try_charge - try to charge the memcg for a hugetlb f= olio - * @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 t= he - * folio, we should instead call mem_cgroup_cancel_charge() to undo the ef= fect - * 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 allocati= on, - * 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 =3D get_mem_cgroup_from_current(); --=20 2.43.5