From patchwork Sun Aug 11 22:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13759903 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 8A9B5C52D7F for ; Sun, 11 Aug 2024 22:50:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19CFA6B009A; Sun, 11 Aug 2024 18:50:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D876B009E; Sun, 11 Aug 2024 18:50:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 014F06B009F; Sun, 11 Aug 2024 18:50:11 -0400 (EDT) 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 D81AE6B009A for ; Sun, 11 Aug 2024 18:50:11 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9E8741402C4 for ; Sun, 11 Aug 2024 22:50:11 +0000 (UTC) X-FDA: 82441459422.06.38AE2BF Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf22.hostedemail.com (Postfix) with ESMTP id D85B0C000D for ; Sun, 11 Aug 2024 22:50:09 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AdC3yUlC; spf=pass (imf22.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723416575; a=rsa-sha256; cv=none; b=FPZ8J36wVlHZUBnGiF+eSKpQkEvGKFY61SSdwFEVn3G6rIJooVkz9nqwGITSAiyywp3g71 JNkrCZlrCFqIx9/SpoaBsh+ZIcv7G49mZwHDpiDrRFERzrqZh6FD2w1jWo/D501o1oYnaW M3Pj3mZsz/F3N9t6rO+iNH5xO3fmeWA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AdC3yUlC; spf=pass (imf22.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@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=1723416575; 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=Tw0JgRH12Wo8KdGqNK+rncsTqLHooD07nmRGRawWDls=; b=vrie93W4f8gGvdDoD1QWR0SoX0uxmCQCOpY55rra3xwtKDKQ9hI7KUt7Qd8E+bxG4kw2ye V1fKz+xb/nErMMuVR5ihwTGCOACb42AICVgdrgsdIaFe4rTP580FGPIVAsRceOKzITWVMh 0uivkQwNjDrKjkUYX8TJXw9HtgMRtj0= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70d1cbbeeaeso2650468b3a.0 for ; Sun, 11 Aug 2024 15:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723416609; x=1724021409; 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=Tw0JgRH12Wo8KdGqNK+rncsTqLHooD07nmRGRawWDls=; b=AdC3yUlCVq9mJn5xQDPSWUsgJHpHnwUU1mdgBaJbGB2DNE3+yWCcfzYuVGgV1G7XrZ CuFu+66FojbA7udfE/lwpt6GNA5YGFiaDWP7tOSphPLjz1jkLyLPtMZaLPcUp9hiyd6K mEJaZDF4QUcPzd4zbJPJ2kgJjWkd21Dy3CWzGj1EBSufJRmlETxuBwffQ/9do3EWdm97 ooNRwxdaqh7j0CYQwJoSUTie0TLRcOEGLrGMeEVUjWYoRanqkaZMmFMpegMwXryiPsN3 l3kt9LRqTx+qa7EK0DogrxCy84e8PT1Nh6UYDJ+iXyoY189sIOmF3jbM93dzJgcBDXzp vJLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723416609; x=1724021409; 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=Tw0JgRH12Wo8KdGqNK+rncsTqLHooD07nmRGRawWDls=; b=bVFZDxFMkqnGoziIYJtztd/mahXhHiibbBLnPFKJxRTDuNAGLCgx/iBuacl/CvllhA Ih+btZH/5JLnoorMK9xjqOHm53PtKqhoFuc1lZe584Ck7tMtZ+3Rt1mPpBUhirhTORuS K0sNy9gpGn5qOOSXk6Rt8EucZy2UYbGcm0t3ZYDYJA+YcEgT+NGoaeMtNgahp815ull6 bYSi2i/2WMt9KDijBdHY9JCw8T6Epjn61YbIJ6M4gsLEFkTe+67xoYftiZJVebpQaOa4 vhioPmnbazfx5vBQ8NSXXjMCD5eSVkgci/7cmJqycqM1/9QskQCS5lCrryfhTsLbj2S2 RoHA== X-Forwarded-Encrypted: i=1; AJvYcCWKB29St+gid+GGBm7OyAXEDtvN0fmBTbPuDDVw2ZsuQax4X92SIqvOg2ZaJ4AlzpaBZfOEcp+VUA==@kvack.org X-Gm-Message-State: AOJu0YzGXXG5H/BJtPaZEUYQyrNU6Ia6wwMozugpslbXbGqOrErWTdPq VFLvEnPtWvyFF1Ha8tmNncUWjmbi4XJPFX2yc2QFLx7Wg6O0RrIO X-Google-Smtp-Source: AGHT+IGAQoUx/mSmccF5tcTHEJNHLzHr1Ne7T77+kVl0PpmsVLNxjtn54anVGm8f20OzojHM35fnSQ== X-Received: by 2002:a05:6a00:2e17:b0:705:9ddb:db6b with SMTP id d2e1a72fcca58-710dc6e549amr6012262b3a.13.1723416608551; Sun, 11 Aug 2024 15:50:08 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710e5874ddcsm2822993b3a.28.2024.08.11.15.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Aug 2024 15:50:08 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, ioworker0@gmail.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, v-songbaohua@oppo.com, ziy@nvidia.com, yuanshuai@oppo.com Subject: [PATCH v2 2/2] mm: collect the number of anon large folios on split_deferred list Date: Mon, 12 Aug 2024 10:49:40 +1200 Message-Id: <20240811224940.39876-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240811224940.39876-1-21cnbao@gmail.com> References: <20240811224940.39876-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 9o4dcohr6depjj884odbz8uy6wrs74yu X-Rspamd-Queue-Id: D85B0C000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723416609-961275 X-HE-Meta: U2FsdGVkX1/GGQJTrCmfucJ0Z58DO/CcE9ro17bpIrZu9Lz1Y3mQju2bxPsRRDogsQy1TR22B8fMoyIyWKfcrCgBQ9kvZbqV/0cXoSENig9ir/OWS2RiMmwSZAWFaatApsH4PY3Z+oieeRZkMSL0D26dbetfJZ4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UyxyONdGJskI8kN1r3Q/Nj1guwIhYZl05CuREcGw2TaIR6hfNv+V96HAbbeSSnq1UpJrNknQT0wlby/4x73/kCd2gHC2uQnPh2+Fp7rHQhlec+xSejLG1+fVkUdgR0/NECy7b0dLWHQPhnE2XPLT+d3EncAsbVRztaaA0AE8q7MGKUYz4c8aY6DLqPijybZZ76JN2y7Vra0dAKBgVaspsQVp5Dbe2ecp9w50xeiaNP8IGVNAV8n75Hy 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: From: Barry Song When an mTHP is added to the deferred_list, its partial pages are unused, leading to wasted memory and potentially increasing memory reclamation pressure. Detailing the specifics of how unmapping occurs is quite difficult and not that useful, so we adopt a simple approach: each time an mTHP enters the deferred_list, we increment the count by 1; whenever it leaves for any reason, we decrement the count by 1. Signed-off-by: Barry Song --- Documentation/admin-guide/mm/transhuge.rst | 5 +++++ include/linux/huge_mm.h | 1 + mm/huge_memory.c | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 9fdfb46e4560..7072469de8a8 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -532,6 +532,11 @@ nr_anon These huge pages could be entirely mapped or have partially unmapped/unused subpages. +nr_split_deferred + the number of anon huge pages which have been partially unmapped + and put onto split queue. Those unmapped subpages are also unused + and temporarily wasting memory. + As the system ages, allocating huge pages may be expensive as the system uses memory compaction to copy data around memory to free a huge page for use. There are some counters in ``/proc/vmstat`` to help diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 2ee2971e4e10..1e2d5dbe82c5 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -127,6 +127,7 @@ enum mthp_stat_item { MTHP_STAT_SPLIT_FAILED, MTHP_STAT_SPLIT_DEFERRED, MTHP_STAT_NR_ANON, + MTHP_STAT_NR_SPLIT_DEFERRED, __MTHP_STAT_COUNT }; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index afb911789df8..1a12c011e2df 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -597,6 +597,7 @@ DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT); DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED); DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED); DEFINE_MTHP_STAT_ATTR(nr_anon, MTHP_STAT_NR_ANON); +DEFINE_MTHP_STAT_ATTR(nr_split_deferred, MTHP_STAT_NR_SPLIT_DEFERRED); static struct attribute *anon_stats_attrs[] = { &anon_fault_alloc_attr.attr, @@ -610,6 +611,7 @@ static struct attribute *anon_stats_attrs[] = { &split_failed_attr.attr, &split_deferred_attr.attr, &nr_anon_attr.attr, + &nr_split_deferred_attr.attr, NULL, }; @@ -3359,6 +3361,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, if (folio_order(folio) > 1 && !list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_SPLIT_DEFERRED, -1); /* * Reinitialize page_deferred_list after removing the * page from the split_queue, otherwise a subsequent @@ -3425,6 +3428,7 @@ void __folio_undo_large_rmappable(struct folio *folio) spin_lock_irqsave(&ds_queue->split_queue_lock, flags); if (!list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_SPLIT_DEFERRED, -1); list_del_init(&folio->_deferred_list); } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); @@ -3466,6 +3470,7 @@ void deferred_split_folio(struct folio *folio) if (folio_test_pmd_mappable(folio)) count_vm_event(THP_DEFERRED_SPLIT_PAGE); count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED); + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_SPLIT_DEFERRED, 1); list_add_tail(&folio->_deferred_list, &ds_queue->split_queue); ds_queue->split_queue_len++; #ifdef CONFIG_MEMCG @@ -3513,6 +3518,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, list_move(&folio->_deferred_list, &list); } else { /* We lost race with folio_put() */ + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_SPLIT_DEFERRED, -1); list_del_init(&folio->_deferred_list); ds_queue->split_queue_len--; }