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))