From patchwork Thu Oct 17 16:04:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13840306 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 63825D374AE for ; Thu, 17 Oct 2024 16:04:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6B176B0085; Thu, 17 Oct 2024 12:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF44B6B0088; Thu, 17 Oct 2024 12:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA9D26B0089; Thu, 17 Oct 2024 12:04:44 -0400 (EDT) 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 90ACC6B0085 for ; Thu, 17 Oct 2024 12:04:44 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3379B1A14A2 for ; Thu, 17 Oct 2024 16:04:24 +0000 (UTC) X-FDA: 82683566910.27.DD7CBA2 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf09.hostedemail.com (Postfix) with ESMTP id EB55114003D for ; Thu, 17 Oct 2024 16:04:34 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eXTMR1rc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729180963; a=rsa-sha256; cv=none; b=ZpXG0gc/jhrhFGpOCks7FhWbpwBkSn1DVLsBu5i0ZLX+Sq/7gRpkncxIJ6pSG8bWX58JvG KfLyEb6OZmYmoFS/NSsAT28ev87FfdibAcXVa1ATwLvovf222L8pnQ2ee9Mnk2uUVKShMB hN4it/2+qByLtHcBtsPoA6bF1beQpNQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eXTMR1rc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.169 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=1729180963; 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=42xKghtIevUZ4KWCWJ57cGxLc8WtHyRt0bs91p1Be2A=; b=ZieCd8krAUxomn0pBdV6yUMSU7n0urF3y0Fekz/vm2GMZOAlGgdAPhgeofFnF/ICEvgGOj iVUj42DDv1ujCsVvWEZ+reVt3dm16bvn16ZFMWwFJ47EQga9ryO0aZU04Am5/LDAHHyeoQ RlBShWHN17WQs6/QPa165yqhG2wjuw0= Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6e2f4c1f79bso9879847b3.1 for ; Thu, 17 Oct 2024 09:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729181081; x=1729785881; 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=42xKghtIevUZ4KWCWJ57cGxLc8WtHyRt0bs91p1Be2A=; b=eXTMR1rcZo0soFhEG+3vzD8NiZlteq2yoDn12c1+Nv29quaSWsJT+RsmqeBZXkHwEY 86kel/XaS0F2V6yIwCdb0Ekie5sdZ57PIhQuLHhVi3pySugA4kDdX+UStPjLGi9IBzpL 8dzLILyB4sAx5Hbckh9nUzcLSbch9XRYQBA9/u9u+qBL49ZbnqXNJEzhd9D2x9dGl8GD tvwGtD4ZcMzhMbCdn1GLOkCA4kmwcJXG3N4gRCe90dUAHXvUcmvZfh7KvAuXhbbJQd4E tGflanrMBBdiBE1gg9PZNFDculzFAZcUmIuXkWX/lEaJJKMGhPipw+GPF/MtQyz8hWic H1Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729181081; x=1729785881; 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=42xKghtIevUZ4KWCWJ57cGxLc8WtHyRt0bs91p1Be2A=; b=G1/uh8fSQPnsvI+OthREvc3mGldNHUEstWhXicsfE/z5nQViLo21gMm1uG2+/mDsH4 0Od5A08k8RTg84lE59aEHBroOf9e63gQR2BjAWAvFw0pKfR6zM7LmMYYyo/CDiSrx9vC 70OdK2xfbb35n0MJDEkS8qULuoLc6XZRdzWbjKF88kJggzl35roBGG2cpBXsPpsEZ/O+ hC3onsqEXnw5clZhygMwolm0ZwRNZIC7XLg+F+qvwK5w9oyJheG5szNPSWnp+3tr3fxR +IKOddUQtEc7nvk6mZo2h672RNENlB5cdt7Fm/Qvjfmt6De9A4sKljtiXloycgSi3GNx 2fMQ== X-Forwarded-Encrypted: i=1; AJvYcCVenE83KXPDtJ8DTduoz4TtZLOya4SezuAwBFz7gMgvOBpmWd6I4WGnZ64yyCzqjnfsx57AGc0R4A==@kvack.org X-Gm-Message-State: AOJu0YyLhYODz7pRT6+CbWJ6jGhf3BmkJ0bi1+3g96QE33HaMOZKLV4Z FKhko2CcWhdU4eJt5peAuXtnKHzpUfMhU6TYkT7j+WL2DpyYqbMX X-Google-Smtp-Source: AGHT+IGFTgE4dzmkLQsc0IxQJCImcV/K009auCAoScYDCsh1hDfG7buFfBVyhizeG6GJlBICdSbZwg== X-Received: by 2002:a05:690c:9a81:b0:6e3:d4e3:b9ad with SMTP id 00721157ae682-6e3d4e4fb49mr89001187b3.33.1729181081045; Thu, 17 Oct 2024 09:04:41 -0700 (PDT) Received: from localhost (fwdproxy-frc-013.fbsv.net. [2a03:2880:21ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6e3c5ae862csm11867737b3.6.2024.10.17.09.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 09:04:40 -0700 (PDT) From: Joshua Hahn To: hannes@cmpxchg.org Cc: nphamcs@gmail.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, lnyng@meta.com Subject: [PATCH 1/1] memcg/hugetlb: Adding hugeTLB counters to memory controller Date: Thu, 17 Oct 2024 09:04:38 -0700 Message-ID: <20241017160438.3893293-2-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017160438.3893293-1-joshua.hahnjy@gmail.com> References: <20241017160438.3893293-1-joshua.hahnjy@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EB55114003D X-Stat-Signature: je5oeqacg3ba4j6nj3t9cktj743iurc5 X-Rspam-User: X-HE-Tag: 1729181074-122182 X-HE-Meta: U2FsdGVkX1+hM2iKbpUUMuFFWYEsY+DrdTK4JwX1TJILHbMiDNe95Y2z4+NjNT5chM30NAulFNRI5fZUUGebChaprt+CDv8+6lHrhUMyI7QEfzYX6hcGnbWZA0XtOg6njZW7QZU5oLKoCRLBVPsIGjp9lIn1lGud5SPrxTw5ZLsCob64fjQ5/au92hvGRORcpifOXk74iotT6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mR5VQ8jYDeJQJMY3m1aN0j4Ut1oDz5Tqnds0JcsS4C8PG79gqGi1Rz1izuKw19DunzU6A5hyN7ONLVGQgEAb+7wPg2mN3w/o= 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: HugeTLB is added as a metric in memcg_stat_item, and is updated in the alloc and free methods for hugeTLB, after (un)charging has already been committed. Changes are batched and updated / flushed like the rest of the memcg stats, which makes additional overhead by the infrequent hugetlb allocs / frees minimal. Signed-off-by: Joshua Hahn --- include/linux/memcontrol.h | 3 +++ mm/hugetlb.c | 5 +++++ mm/memcontrol.c | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 34d2da05f2f1..66e925ae499a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -39,6 +39,9 @@ enum memcg_stat_item { MEMCG_KMEM, MEMCG_ZSWAP_B, MEMCG_ZSWAPPED, +#ifdef CONFIG_HUGETLB_PAGE + MEMCG_HUGETLB, +#endif MEMCG_NR_STAT, }; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 190fa05635f4..ca7151096712 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1887,6 +1887,7 @@ void free_huge_folio(struct folio *folio) struct hstate *h = folio_hstate(folio); int nid = folio_nid(folio); struct hugepage_subpool *spool = hugetlb_folio_subpool(folio); + struct mem_cgroup *memcg = get_mem_cgroup_from_current(); bool restore_reserve; unsigned long flags; @@ -1926,6 +1927,8 @@ void free_huge_folio(struct folio *folio) hugetlb_cgroup_uncharge_folio_rsvd(hstate_index(h), pages_per_huge_page(h), folio); mem_cgroup_uncharge(folio); + mod_memcg_state(memcg, MEMCG_HUGETLB, -pages_per_huge_page(h)); + mem_cgroup_put(memcg); if (restore_reserve) h->resv_huge_pages++; @@ -3093,6 +3096,8 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, if (!memcg_charge_ret) mem_cgroup_commit_charge(folio, memcg); + + mod_memcg_state(memcg, MEMCG_HUGETLB, nr_pages); mem_cgroup_put(memcg); return folio; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7845c64a2c57..4180ee876adb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -320,6 +320,9 @@ static const unsigned int memcg_stat_items[] = { MEMCG_KMEM, MEMCG_ZSWAP_B, MEMCG_ZSWAPPED, +#ifdef CONFIG_HUGETLB_PAGE + MEMCG_HUGETLB, +#endif }; #define NR_MEMCG_NODE_STAT_ITEMS ARRAY_SIZE(memcg_node_stat_items) @@ -1324,6 +1327,9 @@ static const struct memory_stat memory_stats[] = { { "sock", MEMCG_SOCK }, { "vmalloc", MEMCG_VMALLOC }, { "shmem", NR_SHMEM }, +#ifdef CONFIG_HUGETLB_PAGE + { "hugeTLB", MEMCG_HUGETLB }, +#endif #ifdef CONFIG_ZSWAP { "zswap", MEMCG_ZSWAP_B }, { "zswapped", MEMCG_ZSWAPPED },