Message ID | 20241211203951.764733-1-joshua.hahnjy@gmail.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 1CD1DE7717D for <linux-mm@archiver.kernel.org>; Wed, 11 Dec 2024 20:39:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 815406B0082; Wed, 11 Dec 2024 15:39:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7770A6B0083; Wed, 11 Dec 2024 15:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F0F46B0085; Wed, 11 Dec 2024 15:39:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3C6716B0082 for <linux-mm@kvack.org>; Wed, 11 Dec 2024 15:39:56 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E532B1C82E0 for <linux-mm@kvack.org>; Wed, 11 Dec 2024 20:39:55 +0000 (UTC) X-FDA: 82883844288.11.F35EA7E Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf17.hostedemail.com (Postfix) with ESMTP id 382C140002 for <linux-mm@kvack.org>; Wed, 11 Dec 2024 20:39:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Rr+iCNnB; spf=pass (imf17.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.169 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=1733949582; 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:references:dkim-signature; bh=Qpv4gbVjIHmmmrd0tjmZ84YUQmgZGdnFqXfZCW5dIrs=; b=JrJxXs+tiFaEZIwCt/QkqqVH3eOOSSTK3SCD0Hdn79sLz2YQunH3ulloOzaLwstALd3Odp 6h00J/D+io/vA0vlxKNXPtd0LDfgnV0oataYwNM++nCnQfC6rrAkoHxkMirQq+3LR2BGsC VYN7N7OpSejlLfnGU/wyRgPm642rqrc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733949582; a=rsa-sha256; cv=none; b=ZwV4n5rz5JRqCxsTxB3/iDl2I4+cfcs0X1dqe2oTzHy3Z768zpwKh+3o+NvZIki2hwUM9x 6s4GdYBoR5i6BW/AWvAUkfi9SJg6FnkgXZQScpboijuJP9GR+e/It4pltDfqUU2L/xUXsS YSWR+2QCPgHPjfxVAX2UqeEwOffyIik= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Rr+iCNnB; spf=pass (imf17.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e39fb8548e2so5775436276.3 for <linux-mm@kvack.org>; Wed, 11 Dec 2024 12:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733949593; x=1734554393; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Qpv4gbVjIHmmmrd0tjmZ84YUQmgZGdnFqXfZCW5dIrs=; b=Rr+iCNnBo4WkBXeUrLerCGsqTdWGyWxLK6zMa4SFn1qzAm6A9BoqWWVUecoLtbX+nD 52yeG7o8NpG7Inc34Kv51AgIb3I2fIVIl7bZubTszuU99TsKIxv75azehM1fJHOSongH QN8HGqPVFrNvD3deqXQM/eHJp1D41fs2IAkpkTtULwPlGc+FldVqKKQlhs8sCN1zBo5x JK7vTs+edAhFYbvusQKgHwz8IVH2Y+d44JxheSOzwxIeLFmslsISCtqMj8D9ocht9R1s WdFD/y1bCxeH1Mo1ksa4HZ4pU/+RFdsDT4SoIHAkNyUb3oQBh7MS49tYaQ2WdPJTVYl9 Rlaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733949593; x=1734554393; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Qpv4gbVjIHmmmrd0tjmZ84YUQmgZGdnFqXfZCW5dIrs=; b=NrdSksG5FI5ZBcAorsSX5lKKyXXQ6R4fDSMUSIYLDOzVL9YRnWKvDhFAU6QiplFI+9 920pa76wh6FzmQ+sysgStDJrCBru+5R+LUCLtDgxHItLC3Azsw6SBOBC3PZAU9sCL++G rD8s3dGlrTJezDqCEHCxDtSX75B9kTCKyooVYdyc2a24dm7tP5R57FGTi7D/+Wi7ZM22 7OG2QjC8T3jwxBV288ORT7BZQL3XfjqBhisSbRRyGm1SLiLkjWVOk8eMZEc/qG6x+0Zr yqRzvYplZ40DCPwPMweUUKj3ZyZipjuQFJwG0Ow6h+PRws0/5Ob59fU7ivuXEF/qE/Is 2jkQ== X-Forwarded-Encrypted: i=1; AJvYcCVZgtRPP7AVBhajyHNT7IMQ3JHojoIPsHl8qIC63nW6rt8L5N5LXrWPMMzODF1flEa3VB1z9AED1w==@kvack.org X-Gm-Message-State: AOJu0Yz3U0s2O4U2VJpP1Im74rzksnzcj9e+VPPc37WCDoK3PU389SLj nuOCqvsDrMdwIIP5sbtWvfM0S+1TjTy39BWwO4Dd9IAWONGA8NJ/ X-Gm-Gg: ASbGncvr5S9C9P7Pua43CK6dg91iK4jjBQLLT1N9MiStMTftPRY9ASeuVAIlKdWRreT oJPnKObFrGu/diBB6h22WhZarqGYJlq7c7CpIWNSdXhwbNodDwBBwqGFdt3vm8Ah/SG+er8DIjU 1k17s/N/ts2r1fn4GtDKrV14GBMmr+FT865VSwD6RElks917cjP9UmpiRKOfIyigDqpgcUsNvLc eGG9IiZ1lZfwoIenbl/jS46uyiRXy1Cac7f6R4UDdqowkCAo6d2Wfko8SnPGaSTCVoL2YnpLcnx CA3TGQMRTtsgK7E= X-Google-Smtp-Source: AGHT+IHbf62wVMPJS0UI+IgyDaQhHsKZkWwBm5K0XGEL/q3qn17Z/C6mJh+RR0ftqbG79OOrbQ+WJA== X-Received: by 2002:a05:6902:2309:b0:e3a:9d9:bf59 with SMTP id 3f1490d57ef6-e3da324c3femr626276276.40.1733949592992; Wed, 11 Dec 2024 12:39:52 -0800 (PST) Received: from localhost (fwdproxy-nha-113.fbsv.net. [2a03:2880:25ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e3c949c7022sm457262276.23.2024.12.11.12.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 12:39:52 -0800 (PST) From: Joshua Hahn <joshua.hahnjy@gmail.com> 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: [v3 PATCH 0/3] memcg/hugetlb: Rework memcg hugetlb charging Date: Wed, 11 Dec 2024 12:39:48 -0800 Message-ID: <20241211203951.764733-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam10 X-Rspamd-Queue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wb2 juEwoUqDrPjEUY2DP7Vxierz21VvMLrqxNIzn1f/oJj3tVbjy855ZtSXp+7sZT+45FfHrrkde3ZSW/6bh4uUlBnvrUhC+8mITLpmn5zuqXTcxbITmmRDbHfdehxsVcC58Lv7bL9ftkgsRYD6P6mYMhuApcrVvQtkAPX9TsuN6pnapF0vh2CQ29hkPzzQheaZzdIt7HoEbUwPFavH4BlrgcSTh5bZc3ejlxyCzrt97T5S+/qFSNtZYu5vtDLju1vvg+/OSXyUjp6zdG3+xMGUjRYpSedwXOyOkF8hboK5opYkF7kUv4SPKJnmeRagY7RxHGqykFFY0lL5D4eE77wIxH/VPVJKYX0wz5FAGH8e/lDfGgAX1AohGqhJQ5L3o82bxyA5u X-Bogosity: Ham, tests=bogofilter, spamicity=0.005750, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
memcg/hugetlb: Rework memcg hugetlb charging
|
expand
|
This series cleans up memcg's hugetlb charging logic by deprecating the current memcg hugetlb try-charge + {commit, cancel} logic present in alloc_hugetlb_folio. A single function mem_cgroup_charge_hugetlb takes its place instead. This makes the code more maintainable by simplifying the error path and reduces memcg's footprint in hugetlb logic. This patch introduces a few changes in the hugetlb folio allocation error path: (a) Instead of having multiple return points, we consolidate them to two: one for reaching the memcg limit or running out of memory (-ENOMEM) and one for hugetlb allocation fails / limit being reached (-ENOSPC). (b) Previously, the memcg limit was checked before the folio is acquired, meaning the hugeTLB folio isn't acquired if the limit is reached. This patch performs the charging after the folio is reached, meaning if memcg's limit is reached, the acquired folio is freed right away. This patch builds on two earlier patch series: [2] which adds memcg hugeTLB counters, and [3] which deprecates charge moving and removes the last references to mem_cgroup_cancel_charge. The request for this cleanup can be found in [2]. Suggested-by: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com> [1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@gmail.com/ [2] https://lore.kernel.org/all/20241101204402.1885383-1-joshua.hahnjy@gmail.com/ [3] https://lore.kernel.org/linux-mm/20241025012304.2473312-1-shakeel.butt@linux.dev/ --- Changelog v3: * Fixed build error where mem_cgroup_charge_hugetlb was defined inside an #ifdef CONFIG_MEMCG. It is now defined in the #else case as well. * memcg_accounts_hugetlb is no longer forward-declared, just statically defined earlier. * The #ifdef is moved outside memcg_accounts_hugetlb's definition. * lruvec_stat_mod_folio() is now called only except when memcg charging fails. That is, even when memcg is not supported or memcg does not account hugetlb, we still update the (global) stats. * For this to happen, memcg_charge_hugetlb no longer returns -EOPNOTSUPP, just returns 0 when it is not supported. * kernel-doc comment added for mem_cgroup_charge_hugetlb * s/deprecate/remove in commit messages for clarity. * Thank you Shakeel, Yosry, and SJ for your input! v2: * Removed declaration of memcg_accounts_hugetlb from memcontrol.h * Moved second call to memcg_accounts_hugetlb from 2nd patch to 1st * Changed error behavior in alloc_hugetlb_folio: v1 included a bug that uncharged hugetlb_cgroup twice when memecg's limit was reached * mem_cgroup_charge_hugetlb no longer called with hugetlb_lock held * Moved mem_cgroup_hugetlb_{try, charge} deprecation to patch 3 * mem_cgroup_charge_hugetlb always decrements memcg's refcount * Fully cleaned up mem_cgroup_{cancel,commit}_charge * Fixed typos Joshua Hahn (3): memcg/hugetlb: Introduce memcg_accounts_hugetlb memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb memcg/hugetlb: Remove memcg hugetlb try-commit-cancel protocol include/linux/memcontrol.h | 21 ++------- mm/hugetlb.c | 35 ++++++--------- mm/memcontrol.c | 92 ++++++++++++++++---------------------- 3 files changed, 56 insertions(+), 92 deletions(-)