From patchwork Fri Nov 8 21:29:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13868972 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 0D5C9D6408F for ; Fri, 8 Nov 2024 21:29:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B99F6B00C5; Fri, 8 Nov 2024 16:29:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 769EE6B00CA; Fri, 8 Nov 2024 16:29:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BCD66B00CB; Fri, 8 Nov 2024 16:29:52 -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 3BD876B00C5 for ; Fri, 8 Nov 2024 16:29:52 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AD638120F7F for ; Fri, 8 Nov 2024 21:29:51 +0000 (UTC) X-FDA: 82764219426.18.71C1022 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf02.hostedemail.com (Postfix) with ESMTP id 70E5F80011 for ; Fri, 8 Nov 2024 21:28:39 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cGacy6yP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731101264; a=rsa-sha256; cv=none; b=3FealC6rFNoU6D4884UMR78Mciim/JS2VhPYsuLfd8e67R7otuzK2M1cuNhaiyrWr7Gw+4 WdsulyKN2N793zeLbXItT/x3BuEvWeziARe5rfKtwl+zHlxOZGE18e/01yxaiV0s48VNm/ 8Pj9fYiHSQ+gGywQTJcMygBdDDR+Qms= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cGacy6yP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.178 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=1731101264; 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=fN+w5UJnH1OJ63mHkAqq0SxDq06prIp4qqjizUvyrVU=; b=L9wNZyqHkaQZURjUvqSTQTJ8Yn/n430Wc0FzQy4k4vvddf9ff1NzPvxOYMMcCYYBoFAZYr k8eOl/0vNdSWhHSA0SnZEzvZR9M8L9UujfiJJzpi9FAqDFMmP4/HY6c1kVmyO4Fsukzh09 tyg9MgRe22/LLf9x6YhXEJ1sI5lPkHY= Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e28fe3b02ffso2555764276.3 for ; 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=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=fN+w5UJnH1OJ63mHkAqq0SxDq06prIp4qqjizUvyrVU=; b=cGacy6yPdc14x8BzeCslBbwWSISutLf1xRug/JyV0z6pCxNP/JMLRHljoKtFw1nF/y gDf7j69BpInQ9vDrOz7G7MA9BqqI/Y26Xpop6MXQnfGm4iKma0216Jt/7JADI2wE6cfR tVCFW4kjhKpaQ8+DlCJDberwDHlPm4jNQp7qMvR/XVM8nQGBKk75d80EPsieoj0q3szZ Yxw/GYpvbP06oZO4fZ8GRzPr0l/C2ul1M+vpgrY1wiGafSuE3y0Cg1PttXcfF5Irjtwl qQyxosPZrpQy+x7/rVn54d4LY+cXVZ/WYnw8x891Ch0UZEPreLAPTzRaTKcQck60dmMR u7XA== 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=aLvAwEY5bHswgBzeDMEBLfNVrQBKjrxAkfeRrnAqIIUgy9xQgOXTitWEB3x0kxK8J5 yFiuHr5FvAjzXY1cGrURVLs6TGTZKejx7GXMAX4NI43j3v2vq+rAcQEpPfnU8Oi3o46p n6DzCCBgKVNAQSsQllvF6UU8wpvfaBLo/DSYPhL+FdXa2GiSA+YuS67bIy82KOPB8lhN xUjVjD/JfnALIRmnG3bFNQrgVk9NLJYr6bSm+fXHQ8SFlflhVsaNZ0g/JqjYjpXwuTlI SC+YDynXZiDXltyhXoQSixOTGrKFhyRlmLS7qa77uET/mPZpku/bb38fCO0mCtUIHdG6 Z6+A== X-Forwarded-Encrypted: i=1; AJvYcCVTbjsHiTV8ElXqWisRPcGXpuwJu595lrCfu1LLcIudq3mK4Dn0265fnaD7PluudnxQU78oe/8Z4Q==@kvack.org X-Gm-Message-State: AOJu0YzkDjAMV3WYqqYR2Wu9+6yS7PuzAnWpgLaK4pv4FAMqoMvuJGk5 0xnn/zflWhzqvwtkZ1gJKAdE2i95snt8BvwL6U5cezblWvZ+6t3W 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 70E5F80011 X-Stat-Signature: ywp3e1qtwby65np4nw6dwp19awnynkyz X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731101319-533557 X-HE-Meta: U2FsdGVkX18VDj6PxNPAciG7m2EJiAA0S1FjOGpXJIC+jsne8IZK9RQxgYW5qpBAdo9cC6C4LgdIyP1lxe0tLM8RxgEI5xbv/kGSzwEzXbRvVGyzHIJwjNilZrEZGPNm3EHZkintE8aa7u3CrcuwuZT1DQvm/uNyYoP5/KVRfzK/OU3y9AUYn6JCd4nTG/W+mrjjNzPotKvMsn8phZrLrQSaP9VCnsrk8N0HSdnh0xHrVwQanIvGBg3CK8Md+it6+pxNlkNt3E66c8yJsZ7pm5u39bc3cYiQB6Zo/HDHjdMw+2v7OtujUS7Wbz1VllgR6L3JVh8HlBO3LLCp8qvhTehDELLL2u4GgwufelFhjFu9k2CJXTBkIiSAbZBk0hEA4qNH6MmFfwJCM0olNkZJDPvVe4MW4Gl07+SpFQwXH7OK/xtRWU91y6A+s3hwnvQ6VWOVAm07QNMYjPfQJOkoVmUFYDgMvYu2YXPjwYqtftDP1p1WIGTayaKAv+5nVWFETZQWEIOuv7LEdgBj/s4cAbDSabt6E9vo0pczZBr7yBdnIbiEMBmO88VV6MkiwQIrVONvIvFVQ8orgjomMtx0pDqG0EDC3rLakkhvjgd+EWcaDQGxUUS1UhyBEu/y8WmIhoGn8sJJBEHc7X40cCXfGA8tvbNcMZoqO3UbUufHG9YMybopaWYRwwdFkF2LnlmSV5CEvoPQ/Fjy4We25kSPosTSJnF9TXjFXC5h+DhMP1JCJtcrFLdPImq8IjZ6kVCiIYvrdUjQ5OsaJC/6ACa+iqiro5tYdcjE66ruXUZFA3PD1x4tyTOinRslgBOg5S5GCJLCjpvrcASVUeLVWQF/j8FpVI242K/tnPzElRlMYiyMo0pPZVN1DIWjTvqkvUw6GGubFreRb0zpWGYFgY41pp1izPTQk6wl+aSGW4e/+Orv07W7Dd+qk14SXM4/m0tfftWVC9K5sVE+/6oMYyF ws5obTL+ C0cQUOTjfSk1O9yJ8rmHnKVKauTOBJKlKNZZlXgCpuhJcPBw69LJsJRBN6gYw39InblgBRIMN8444PI0W+ccUL4mhj5RImnekBuKjOnd1hnMmHYXUMyntSuNUHYG97fnJVUEfBvTMlyfFKvEUUM/pvKsiez7rvs6uUEbrVWe3N/VRfyOTy/uW0zE4WMhIlIDVoH0+TWSquGAdAbWBWUMRkg2fUdRRzVyVmjqgBhNr1/iMBzOCzzVNFH4JAfogbaW7KJdDTWm3o62T99gvZZy5sOuaxEHvvmGpMMB8LKnfKVEB/MFOttLsyrmZfcXVIpoIqcoSzDMYh6RTYN4THn2zKP7WnisEu/dYlQ01ui/UUZjhQw6Av54+PN/18oJtn50c1e8eUdY73+txuyDgClGQgmpCPTvo4Uvh5f1HbcysmfSiI61VuRaa4SvpLQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000017, 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-off-by: Joshua Hahn --- 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 mem_cgroup *memcg, int item) memcg_page_state_output_unit(item); } +/* 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 *memcg, struct seq_buf *s) #ifdef CONFIG_HUGETLB_PAGE if (unlikely(memory_stats[i].idx == NR_HUGETLB) && - !(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING)) + !memcg_accounts_hugetlb()) continue; #endif size = 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; } +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. @@ -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; if (try_charge(memcg, gfp, nr_pages)) From patchwork Fri Nov 8 21:29:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13868973 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 E02A3D6408E for ; Fri, 8 Nov 2024 21:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E5E28D0001; Fri, 8 Nov 2024 16:29:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FB59900007; Fri, 8 Nov 2024 16:29:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D7718D0001; Fri, 8 Nov 2024 16:29:53 -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 F24496B00CA for ; Fri, 8 Nov 2024 16:29:52 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A79911A0A89 for ; Fri, 8 Nov 2024 21:29:52 +0000 (UTC) X-FDA: 82764219048.10.B04DD14 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by imf12.hostedemail.com (Postfix) with ESMTP id E75064000B for ; Fri, 8 Nov 2024 21:29:33 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dTMX9tUR; spf=pass (imf12.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.178 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=1731101202; 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=SlQ3sjJT81bsTmwr1uay84sXlsybFvKefjGpPF85ZWQ=; b=Vf60yLGgoRzvjZ8Lz9kLCy1JYNxkLG4aII/xNLCwWfBSge37p8K79VOjle3fBlN6ZChIgF 9c2bGkYjanxfaUBNvveUn+LfQ6ynDx6mHZnca1vd/BmrKG96N0G3i4a4hcnzT59/PUh9hG mKTTN6IMomRChmglDyRAyQqhLNU953M= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dTMX9tUR; spf=pass (imf12.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.178 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=1731101202; a=rsa-sha256; cv=none; b=UVX/z5Cc5tJfBXxB0s9lfFIhGeUlEfDfUHX4FMrE+AH6HHcOlECDrTxEt+KbE+wqWxQuaN jBQmeixcmPn3mWzHV4ondzlLPtfCOyX6L27iMnt8S/lY86PzqL8iVy692bGq0BMxSgXnMT KuDUpK+am58o6FTPrg8kxkvPPnULRy8= Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-6e38fc62b9fso23438587b3.2 for ; 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=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=SlQ3sjJT81bsTmwr1uay84sXlsybFvKefjGpPF85ZWQ=; b=dTMX9tUR/sOzHWLgwM8mVKW8wl66HtiTSoXH6Vcs3v76oz9HWte1e25G+bgKFwfixU IQRMwq3qhNPgmPWWpQbmngFXrihK6oxvJ1Wu3/w/HYpzv27u//2Jx74tuCrAcrr+Z4ef z56hfLAfSwA4PalIZkMW0dzOTFdq/mVxxfNr0+SyBoqamJjIN4PtWEihTzQ0tIdOBAXL WPkztx6Ji+iyd1NP5bRz8pqLFvcNTMOhiLr6JfzXL+DVylz6+ED+onWId5SlR8Ecaju9 zGp33qiXjQEV/n7d5Ws53KNfOI3tlu506kOYceupFxjLjWE/3j3+L4E05dzGDpsgqf/9 xtQw== 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=B+MANEaNVbtyVfjCeXdEEbxZvMqtUjZkpaZfDWimL/OrWN6ikpX0I5++RRpeNRGDcI uVNneX3UrmIul5eyY3Hm6TvycPeNmyZv+HfOYb09XZNPYkY6JitLkFQx7tRKz71rOIV0 6YsQObA5MXLuIBX/IaaXa87eWuQBh7PgmNTIXxFLkJAMTYazKTerIm2p2X/IZ4EJ58Jk n96OnRAcS1vv1Ni3AeoKxcp/AF8wQtz9KacxUyUeyDOaFMPBeWgFGBojaSkgKnDzss2S wuNv6wi/loGC7yHqV6i4KvGXtUJHin+7jbO0cTVNq5jxIuVMSGTSMQMqsssCRjakvgsv u8lQ== X-Forwarded-Encrypted: i=1; AJvYcCVCHTb5ng3V6x/VrmohfhQ63+d0x27HxA45oerjJ8WLBm7AgzE/nJwZN+UM5/2QEPwtnfFUlSNGYA==@kvack.org X-Gm-Message-State: AOJu0Yymq/SQ/fX4qJ+aWCM6pugaF0g/pN6VmSDpi9MZexItArNiFWNL NV+HyHSbZBRy+j0RUBTdqXMwcvPg8iUVIj4N/Y1/rmcIcD/0qO57 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> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E75064000B X-Stat-Signature: k4fs3ndnc4bae5rrsi986g8yco79hjhg X-Rspam-User: X-HE-Tag: 1731101373-403313 X-HE-Meta: U2FsdGVkX1/wjd6NTTt8fKcKZGWy6+tLai0l70ffV1EjavOtLB3s7uBgKA/Hb+7ZdGVJqcmiXpjPnMyKMsUCG0qkIifvOplUlyTXGt7elNale+gcvqDnH+jsp/QZZsK5deXi5s2DrNJZGae3P5TONi2S4Y/YYwz1+rBvBf2auPD6o1RrUbcgeezOxDvxe5JVmfKR6JAHsYieS2dGh+lsJUHVRUHvwBKA9B/sG+yNKjBZ9/KmsTXmlYkv4/T+0tx7wrCXdLrJ17FabLuIoiJ6BtFG+OyUer5qo854TZsm0n4/rChEDol4gDY9Cylsx9pZHsTZstU8m31wibchGc8+7/6n6P81iQPIo6fLwCV08IQ7TAd3Di7qni6mubuYb+YIYFRTHfOz+jOiWiZgB6hnfNPtT4LU1i3NHw5pYROoyO7liNFE0HDtAVL8duXal6xlVNFhL0qSE37VMqYkRdbpraxr3MLrA4L9g0tNJf9w5Xkk3I3IT2VCYl+Zt7HCRE2CZRT9nJZWm6/XDPPr4UtoRl8WUBVQUnPhjlOhbWcHPPp556j4WCK6cgO09DSa9AkaROh+qg4UhRG79dMwQ3uTLwpd8SphI92skpDITD3d+pbLdZ5Wx+4Rew7klyVaC5x3O0+/iYgcgjPuq4Y5rGYPuiKPMizsqoscstzBld6jJ/wceAODD0eLaNirdsJygWA9tY6zjYf95iqUavBT2NKhJPHR/GdtSSp5Sk3td/Z3/HSc5AKbGkaUeggHFPu9ro55FcyJfUHYs5nI2GzEXYVl5LQlENVNdx7joWuMYQIDMX0LtDdmZGOjdVCS/z6Qd3AiwOX6153scc9JnCfqj/LgB9mjVb36jZvCEDz9C0yEngKK3O2edN+h3Fx2NrBPmo9SmmxErx6zfExxVdFhdylIJL/mPVVO9aJtoGAFd3xPaOXS7dESsrLpl/12sC0IKLB1H/qBynF7ahukzFe/iQh v3/HMonG fnsk3HFbtwSr4igQcjdSY8nZk/UOqc+6vj9A2ZXELlFjlCHLR5lv8lwHZxCasj54XLuz8Lcz6LVaEDsevqqWqZfF0McyIM86HbbyvBxh7kKGdqgL0rf159k2E0lemC3AdiLpfdbOol8rhIc/t655lB6/fLl4+3MW/LkQ9tPKXfV7/v2RZsHv9gVeBwut1skjBhDK81Dp9g1Hh9YwNNWlu2OAaDSf2TkhUI/Awl8/4H4v6AR0LxJKsg6fEfsfHP2jQpoJ/rYAauJ4vAi6HlxMeU2YSai98NDLgBvWTkaN57gPSTkOuA0ExFc8xfkoPdpwIslSKi+BUtdL1fCm+MX6UNA8pjBeJhouPF/3roZglToxLZSlbrJpQY86+8MS0ROKxIgmPsMCNArl6tchT/LtRYa3RCgmaArmKgOREAaY5fu2EF6DzUebV5vsKNw== 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 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 --- 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); +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..6f6841483039 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 @@ -3092,10 +3080,15 @@ 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); + ret = mem_cgroup_charge_hugetlb(folio, gfp); + if (ret == -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)); return folio; @@ -3110,9 +3103,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 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; } +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp) +{ + struct mem_cgroup *memcg = get_mem_cgroup_from_current(); + int ret = 0; + + if (mem_cgroup_disabled() || !memcg_accounts_hugetlb() || + !memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) { + ret = -EOPNOTSUPP; + goto out; + } + + if (charge_memcg(folio, memcg, gfp)) + ret = -ENOMEM; + +out: + mem_cgroup_put(memcg); + return ret; +} + /** * mem_cgroup_swapin_charge_folio - Charge a newly allocated folio for swapin. * @folio: folio to charge. 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+YCgNVyAsxfgOAopZpJn5RIEg9eD5sZ0XWU2XnA6tDO5hLwD+rsSf0G7/WgTph3bZpuj4oXTBngSOvC1L8P7EN+ehpb13dtBqCILWdos++M+7XMvrr8z+JDAX4xSUirlTjPQ+W+73/CcxL0v5nWpnyxoFT10f3zgQvAP28e+PjPqIv/1woBJlVPfCCqK6R+ADeZgIUlFsOvx61NDbMrPC3VL0S1EKpjZ0B1OH8Eyzvcr6S+Turho52Lb4eWolt045JIIieagXWv5ss0ZicBH+CgDuEh+ZRz77en9ukTzj9J/xLqk939NL0WOom4BdiwbkRlKPf7rJzVvYbwUldy3fBxLeGae7B/rwbucfkpArkA3e5Q9nvieK4aU1q6syAnr8Xe+nFcuMMtsMxW6waeUboqsXSacxatQCVKbSuiFinu4SA8nzGkqmL4MVvZLio6bjKZmNlQY8UT325kAqHM9MJKfU1WDuFedKCNlOt347x7lVMzDnVpewHXBaNpZ2YSuaDSENg98YaACWeiQS3wMzeRF9vZUMHVaNh5WbSFsUtdMUU+6IPKFjy4d38q1gH8hF15NAD6wwm/y3XR5qta7eqbm55pvrZXfl4jbb4kBD6GoyS80Vs4ugyvnJMJ2n/c4i1YTxojPDcQcWmLDKOROTsSstHeSrHo43x+G/nhJ8/we9KZSHVJ2godngEb8dr4I64SPxSSuz5+i2Sp5pnFdAyD7ZfwwIP4N32lVIsMU5fCxq5FkUh35rpDUSwV+mt9KFAEWCOhNCJ1wiHWKRkMklYXlJgPtMHrRYraV4R5NBt+XLjDE/cGYbmAUU Kk5vLSaX Au1Kft4r9VhacWh7wQbcL64P9U2X0hf3xkDRIZSNdnyK7/s8wNq/93il0jmWAs53w3vaCKivsslaElc3V7034mWOjoPE0ryf4sIYR01LIJX4egVjhoC//1s668qKvsdsUdvrIYRiite0CAj8LRw+9hed1YDyRqvu2ftfxs+kcmNtRqFQa57R3HhWTUgVlyDgj7bVY0a4GVmysJTKpqL3hTbnSq+N/le+Gs3VbOXtRGN1Zw+afAOZW2IKwGEfr83MKavegaFyLk8wr1jH6qK76sEV5x9aqgz9kMAyK2p1PjzpmJakl9tDsPjRGTMWg3ludNXZ84UjrhKjk6yiU/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();