From patchwork Wed Dec 11 20:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13904129 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 5090CE77182 for ; Wed, 11 Dec 2024 20:39:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94FA46B0083; Wed, 11 Dec 2024 15:39:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D7286B0085; Wed, 11 Dec 2024 15:39:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72A7E6B0088; Wed, 11 Dec 2024 15:39:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3E10C6B0083 for ; Wed, 11 Dec 2024 15:39:57 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CD2A78131B for ; Wed, 11 Dec 2024 20:39:56 +0000 (UTC) X-FDA: 82883844120.22.5960FC8 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf23.hostedemail.com (Postfix) with ESMTP id 5C5FD140009 for ; Wed, 11 Dec 2024 20:39:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VVr1DJwr; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733949583; a=rsa-sha256; cv=none; b=gEc6k89092f95KxKSL6EWfg3YomG1xdlU43JlAXfshDXcawwceSQFOwmWJkDxoBrEoSN9Z eCsE8VR32HjUsp+nl2ouosGpeZVi8+200h/2Aa80guhr/M0TjPVjedVRv/MQ3lAL/6deSU k35+/P1XcbObHfzJxWeEajEe8BF2UdI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VVr1DJwr; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.181 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=1733949583; 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=T/fpH6v9netOl4stZyFABUBGIIZaGTv9D9Clx9j8z/8=; b=ipKrBOWLGMNBZURJwM7TQSPWCocezFguFbmxe/M+ekK+d0msR8S78I+AcHhRtwAzmYhiL8 tOR7Sx13D6RAL6wYBRwbDU4wMbFKigFr1AxTyQaN7QaDOw5bxC2TlPhvK+E5xzRFSULxpy tS1I4Nv63uyqQr8aSoG0abl+SRn62mA= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6efe5c1dea4so47320967b3.3 for ; Wed, 11 Dec 2024 12:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733949594; x=1734554394; 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=T/fpH6v9netOl4stZyFABUBGIIZaGTv9D9Clx9j8z/8=; b=VVr1DJwrWWRSkDyHLO5Ls7lyEz2lHxY6Ou2hx0B5/AodVQsHQTCQY3O3x99+qlCpCo K3o1IhzQjdNJWfE2s434lpYAU/sFju8IlooDn/pgVC+5OOyRZtBDt1dYIuhQDFE/hxYw ccjyEa2NPcOQc7dpx6RN+2rndFGnw9afwNcDvfTeHgGTsi83jJ9Vg7f7hm/M77JTRhyT 80t0Wx0oFuLBllC7JneAlZ1QtCsPr+vqYQ7fpik22DPtKMfnPGb+iikj8NUqlVBQynpU zCSDT4/Pw29L56zno5aMq4CR7JC6MCfCxeJRknb9SaGMzRahQNIB7d3an6cgYmCoyNx0 8mVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733949594; x=1734554394; 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=T/fpH6v9netOl4stZyFABUBGIIZaGTv9D9Clx9j8z/8=; b=bV1GDmApxhNtBuAsaO8WMPAJXZwjVCgCUgJANrltvwEvukCjAK6JNMlx7nwz00doxM EsttkJ8eqGICpcb6VIlU0ls+iQ8nP+VJwTf0K+qwsvcpj7x/Yp9KMq+TVLQg0rQvYKcy skl+zOqg0YANRxEBmGClsyN9gzCvVNYuNtp+to00ERxA7ivJaI5RCz3t04r+KR3WKTR2 sUxWIsXrY31oDo3CH7qzcSTOfPxH9S+Q+s1ywHWToofQQNbi6ADoKSJnBxjwb7ma5TBv ulLhX8ofsYCSxj9HsFZVUHF/QCqeYV9fldlBVh1z6PvISlY+WPpQvppsXoIrfVYUaGhs Uurw== X-Forwarded-Encrypted: i=1; AJvYcCULVg/lqMpVGdInzLcbLoPrkP+YX+bB8soT1XEj/75g85uMdFRllXF/QUD1nI/gOil2iLBrtJ81gQ==@kvack.org X-Gm-Message-State: AOJu0YxIyxAMj9u0gmKD0kzoLUF9JBcXXvjb4QtomgenhrA0FyIrgOTu 5+xg3Cr9I089gZHhhPF9b54qw6XqqwaNXbyEx6Kx6AAgCTHs4QlE X-Gm-Gg: ASbGncvre5duM6s3cqKaTgrGUoPFGpsWZiwd+bAUSTGM7IKzSQZjQupbRNizVXzDItV H5vwLaZoiePGm11QeoWlao6veVNsSm5TFgkKfT3n4hMlH0gjS7dKYC4hgbjl/25LrZk/YOr7me+ sUOlyCiN4StCD5a4JZrJbOkZyGllN5Lv3a3Tmh9LwRomCcJYzBT9prWDgxqJcAzyrXWA3jieKBk xFGjRz0VOa15WoUz6TF3w2BvvPKT1Ivowm+0qW6TAEcWkC7n+eSSJhWaZ/Wo97pHJ2VEuYbrOxM 4+LV8a1MYwF/JQ== X-Google-Smtp-Source: AGHT+IFjh1B7FesLgwVZ8NbRhB6v4JhL21WCugQRgRvU5yKBoLTE4Ii4DA6DYdGbfcfCWzLWySHbVQ== X-Received: by 2002:a05:690c:4c13:b0:6ef:6ec2:ac62 with SMTP id 00721157ae682-6f19e4f2690mr11106417b3.15.1733949593961; Wed, 11 Dec 2024 12:39:53 -0800 (PST) Received: from localhost (fwdproxy-nha-006.fbsv.net. [2a03:2880:25ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6f14cebffeesm4012597b3.126.2024.12.11.12.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 12:39:53 -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: [v3 PATCH 1/3] memcg/hugetlb: Introduce memcg_accounts_hugetlb Date: Wed, 11 Dec 2024 12:39:49 -0800 Message-ID: <20241211203951.764733-2-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 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wKcwtwwC5NzR8aBG1ziILZrxDhuOZhCyjKdX DjQsn2A0 VdfQQ2NfRHXMjhyYPSUHo8MirTphYCWOho1EwLU3tP20U3+scFat8i3hZdtFaR5nAYO/lj3FaKb1D0YwB4BZyM+7X8MQhTFPhvBB2gkiWlt+VU4kwMkgJr+yBwd0HxB4bfl7keBRrPDkaetOlGA8ctM4kVCV2adjU6mZe2AO8ci4Xlc4uiml+hPNevxqcTDfDNxYPEn6MZifdCKE6OxJuhId/om+E20r8+9NkhtrvRF93UOKBW96Q7JH+MRBCm6FX+ATPq07JontS+UKhEwIM6GRzHsONPhG+xz2HGm+CoydFxETZV8V4yzEq+q5Q1gXpk0eYarbzqRzSCcEaEnez9gGFVaCSbfZ97Hd3GHAFWiuUz/8eHQnr8oNI8QN65kYPaXkfovnhforvat3mp4HThZwZ56eSCEKy50/PuPqn6t9pXHWZ45je2cYegQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.336282, 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 Acked-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 7b3503d12aaf..b25eab9c933e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1448,6 +1448,18 @@ unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item) memcg_page_state_output_unit(item); } +#ifdef CONFIG_HUGETLB_PAGE +static bool memcg_accounts_hugetlb(void) +{ + return cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_HUGETLB_ACCOUNTING; +} +#else /* CONFIG_HUGETLB_PAGE */ +static bool memcg_accounts_hugetlb(void) +{ + return false; +} +#endif /* CONFIG_HUGETLB_PAGE */ + static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) { int i; @@ -1469,7 +1481,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); @@ -4540,8 +4552,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 Wed Dec 11 20:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13904130 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 9D4F1E7717D for ; Wed, 11 Dec 2024 20:40:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC1316B0085; Wed, 11 Dec 2024 15:39:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B4CDF6B0088; Wed, 11 Dec 2024 15:39:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99B2C6B0089; Wed, 11 Dec 2024 15:39:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 721FE6B0085 for ; Wed, 11 Dec 2024 15:39:58 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D580D141318 for ; Wed, 11 Dec 2024 20:39:57 +0000 (UTC) X-FDA: 82883844288.15.D11EFAB Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 0F0221A0011 for ; Wed, 11 Dec 2024 20:39:30 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=U2zSTmK6; spf=pass (imf19.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.175 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=etyn39dYkYYqxl1MOdPR2a9G+AL/gyYbItp4iRGm6Gk=; b=hpstalAgqhkP4gXuuVGEBi+wobWz6ibfITAWPbCdHWdHXB8MrU/4bi1PyAopEKb39wRvhE j0w8YFp+k451mxZ3RRi4DMWHMRXN6HPGgJmh3v5qitztx15vtKxln34K82ZbXpZxCyjc4c 8GtOJF3LESVtNCE+D5iDrzIjEvOGXaY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=U2zSTmK6; spf=pass (imf19.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.175 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=1733949585; a=rsa-sha256; cv=none; b=k/ADAjLgOweaRGdRCXs/AZCjPdJox7TplB/PZihehMA8SkszsLFbqldGJPuUQD6hw0+sIx gApmlbpBhnQUSp4ZXS+KNeMRvcK4fknhvHd/peQvfmN9j74tqJkaxfpj8owI0hdRBaCmjZ e5ELcn8edMfoi4BDBWguioyEN0IO0ec= Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6eff5f99de4so49854687b3.1 for ; Wed, 11 Dec 2024 12:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733949595; x=1734554395; 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=etyn39dYkYYqxl1MOdPR2a9G+AL/gyYbItp4iRGm6Gk=; b=U2zSTmK69sOMqaYdNa0OSFwyW4zyV/X3p4/DrVfOk1Z0q9kmrkQ8KtBdac0S918CXp 4Rhat6sWJhAwy+dc+pFqKbo/b1q0DcDk5YQu/VTIWD9vywNCfa61HM39H70zkZzZz4vP 2w1cGq7f5UYsuPjpqH/drs1uESwr7jwC2l5ZFj2CqLnwbm8Mb5RTnOxCc+uW90057iwz IgdotrBOcM86vFYZg7n+/cW6sMvdyI06yZygV08m/UQ1i5QRFeG3JjgocBPZY+txHLZL 8aKf92Ewu5zpccxy1AjbUiPgvxdHQzyKVhxDYNmndzHF7lUQL4zwAcKYeAHtePxriUkv P5Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733949595; x=1734554395; 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=etyn39dYkYYqxl1MOdPR2a9G+AL/gyYbItp4iRGm6Gk=; b=tXqQaUEh9xdPS00GlX4m6ZjCu9q3OQLG1qGW367XQcO3WrygZ2d7R7oNcpweZhPxh7 qiuPwj91vTzMMfFzAG+w9a3V8L8j07iTtDLTuAzNumXasiJAV2thzwf0mblNKx/pdR2E zHvsR6+S9X5yzZZORrTTDM7RW+aHHUQcLt7CmhvjmV6Lu+JC77EcvzhiK6jJ2awtVzSD 02rpZNARCgLKFgdkw0+96VCs6NFi0O4FwR2QBF8riASUfXlLPocmUmyG1KeMV5oWjO6c 8h+VWnTspiw9uO3h2eO5pN4sHTt0l8BDKZx7kZGYSsd4pUOMHH/quw+ggDb2lmrnOueW mDMw== X-Forwarded-Encrypted: i=1; AJvYcCUAhRd5zg4Tjnqe7bqQJvj/qwCaxpZYyO5sw/MAQTJfU5Wqe4vnbOKtL5v2jF0l4ePx8R2550Uu8g==@kvack.org X-Gm-Message-State: AOJu0YwOK3O6pH8JabMrAHFMlqdE1cOQHIGvB7GdbnyR4G3U3BOoxZQH tq1o0ozeXYPEK/AjFx+DJcwTgQW1cGk0fLHRCrcvnpN9rbosQrjg X-Gm-Gg: ASbGncvOh1qETWZTSZELVmeD0M/CgqmlPFcsK3ml5kz68DMh1Tpz5CxibYb61klTSrs uWSx9MdrTk7aQSLol1JKSurkva42tbgt/WeIxtaxfKvaisfed6z3+gwq8eiXyadqwOPZa9BG/l0 dA+UIvatNE3G7S9w3dlFccfdrEDs5fjgbMPNfbxWykLpJo7eOX8T6q6ROz59Y1k5/p24nr1f1Ms F0r/BWcPbOQoLXJZoA9M319tbEjBMG1yknTOwPZEAmJ3ryems+tMVwE/5Xf3HQaFU6VpsZPKc+D iIyKkMdlTim4aw== X-Google-Smtp-Source: AGHT+IHiKNGpDGljLutgpDps2QixRf6dKOvZDYWteW4cFSGFlQb0IBB4jIkNpQKhnKnsth+eROjXLA== X-Received: by 2002:a05:690c:9a01:b0:6ef:7312:d05c with SMTP id 00721157ae682-6f1a4f68714mr11743177b3.2.1733949595078; Wed, 11 Dec 2024 12:39:55 -0800 (PST) Received: from localhost (fwdproxy-nha-010.fbsv.net. [2a03:2880:25ff:a::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6f14cebffeesm4012667b3.126.2024.12.11.12.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 12:39:54 -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: [v3 PATCH 2/3] memcg/hugetlb: Introduce mem_cgroup_charge_hugetlb Date: Wed, 11 Dec 2024 12:39:50 -0800 Message-ID: <20241211203951.764733-3-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-Rspamd-Queue-Id: 0F0221A0011 X-Stat-Signature: 1g9ay4kjig6j4t1eo4e1qe3b3kd858g3 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733949570-696967 X-HE-Meta: U2FsdGVkX185CUCw7lQnYNWymYHtTQ/DcwnK0pfVwnXnU6tjT/y4FqKQhvkr38NabcMxoV1G2uDM34dLbs97HvYhpO6Orwxky9CVyrv1ApAUZpM0RDFxQg9g7Zz2BH2Qv+ZuXdTnLqyQNDMf1b6n1DmCIaAjKdci0bTTcNeLF7WUjQdDe+buNnMr5JUv0Wml22bahRIxB0BQVa9YV+VnnTGEPTlACoTeAa7G42saEuU8btB7pE6sV0vqmXXvbXxAx4iOwJX33PfZDpg5q/2g71xagzI2SnH0aeoim5SaagIZnBJ5MAHMG4JNwoJLGBlGR7Zeisx+5tIWumRH1+OvbCw9fjQ8eNbcmf0/oeh4WNQ+QlLK3DObK+06Zl3lv8bOKZ9/nrgY8pSL8JuZ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@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_hugetlb_try_charge / mem_cgroup_hugetlb_commit_charge and removes the need for mem_cgroup_hugetlb_cancel_charge. It also reduces the footprint of memcg in hugetlb code and consolidates all memcg related error paths into one. Signed-off-by: Joshua Hahn Acked-by: Shakeel Butt --- include/linux/memcontrol.h | 7 +++++++ mm/hugetlb.c | 35 ++++++++++++++--------------------- mm/memcontrol.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 5502aa8e138e..f4271cfdba92 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -649,6 +649,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); @@ -1152,6 +1154,11 @@ static inline int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, return 0; } +static inline int mem_cgroup_charge_hugetlb(struct folio* folio, gfp_t gfp) +{ + return 0; +} + static inline 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 ea2ed8e301ef..f0f0ffae30a3 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,18 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, } } - if (!memcg_charge_ret) - mem_cgroup_commit_charge(folio, memcg); + ret = mem_cgroup_charge_hugetlb(folio, gfp); + /* + * Unconditionally increment NR_HUGETLB here. If it turns out that + * mem_cgroup_charge_hugetlb failed, then immediately free the page and + * decrement NR_HUGETLB. + */ lruvec_stat_mod_folio(folio, NR_HUGETLB, pages_per_huge_page(h)); - mem_cgroup_put(memcg); + + if (ret == -ENOMEM) { + free_huge_folio(folio); + return ERR_PTR(-ENOMEM); + } return folio; @@ -3110,9 +3106,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 b25eab9c933e..c903e260a830 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4561,6 +4561,40 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, return 0; } +/** + * mem_cgroup_charge_hugetlb - charge the memcg for a hugetlb folio + * @folio: folio being charged + * @gfp: reclaim mode + * + * This function is called when allocating a huge page folio, after the page has + * already been obtained and charged to the appropriate hugetlb cgroup + * controller (if it is enabled). + * + * Returns ENOMEM if the memcg is already full. + * Returns 0 if either the charge was successful, or if we skip the charging. + */ +int mem_cgroup_charge_hugetlb(struct folio *folio, gfp_t gfp) +{ + struct mem_cgroup *memcg = get_mem_cgroup_from_current(); + int ret = 0; + + /* + * Even memcg does not account for hugetlb, we still want to update + * system-level stats via lruvec_stat_mod_folio. Return 0, and skip + * charging the memcg. + */ + if (mem_cgroup_disabled() || !memcg_accounts_hugetlb() || + !memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) + 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 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-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 09B371A0012 X-Stat-Signature: 3i9gphkrafsy33hmath7fyurdxhsggzc X-Rspam-User: X-HE-Tag: 1733949571-879333 X-HE-Meta: U2FsdGVkX19R7JYZyXh/5cRiv3kqx1GBX3HLDLppq6ZjWxJDGPhThXCk6/O5Ze2UTFqApSKpeEGMOF35yI5mFT+FnjiBlbMxdKdcSLZqlcKc66ITl3zfWp68uhhzH9Db8fDFmsJzkbsCJ2ImUWDUtfNzCpDcRx38TWmOlodHjVkCHIvccJls86E3hmnSs8t4G+izWlfK5GzX4xgPrUXBH6fnHHPJ7vXKdAjmqsrIbvwYYkB68j7qI7fmocEdkKCcTb6rTjp0NfjOFW6JdZ+bOBg2ztxc3InrdzNXZ0zcsaHaSAwTD2HxaxgWJBaduyyBJas3avhoPEgBsSkbEUc3Az47k/9r9v65DnhIwW4xpssS401zq2K/Aha88MK6Kvuuym0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-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 --- 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