From patchwork Fri Nov 22 16:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13883323 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 8BC51E6916C for ; Fri, 22 Nov 2024 16:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9F356B00A9; Fri, 22 Nov 2024 11:14:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C27EC6B00AA; Fri, 22 Nov 2024 11:14:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1C96B00AB; Fri, 22 Nov 2024 11:14:55 -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 898F46B00A9 for ; Fri, 22 Nov 2024 11:14:55 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 31976121864 for ; Fri, 22 Nov 2024 16:14:55 +0000 (UTC) X-FDA: 82814228070.23.6A3A0AE Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf13.hostedemail.com (Postfix) with ESMTP id D78F320008 for ; Fri, 22 Nov 2024 16:13:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Spkop8h8; spf=pass (imf13.hostedemail.com: domain of haowenchao22@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=haowenchao22@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=1732292000; 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=lrbSK43NLfB2e4wOG+aqQWdM/1SYnnFodbzmkkuii34=; b=EofYPTP3gjrI4bGrXvNTtKQ38U3ZrtZF0CRSqLw3pd+DLsUReOE87BKtr+bYbv/YySag4h ukGqQWUlZILfPihoXKEryBXITEUxcCwlekvm25tOXOVELDgwtoGJoGzv7h0GP4j0skSamX b5uAvf+1/7ckZnaSJx/8A6d2Z0ESQhU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732292000; a=rsa-sha256; cv=none; b=QRWd17idrjOrwR6NdpBK6XTwGjjud4GG6hEUu2r9/qgmAs2QtJO0Qgty6JQqxy31auFBhr ANyfl+gAPXqonsYDuc4UYMAEuAfor0OBlE0+psJMyhf97lRuI8iFCHFlOyYuSVFVkdemHt adHXiQnoFZWuZyGKMb61nZkOiIGTrlQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Spkop8h8; spf=pass (imf13.hostedemail.com: domain of haowenchao22@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=haowenchao22@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-724e6c53fe2so626686b3a.3 for ; Fri, 22 Nov 2024 08:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732292092; x=1732896892; 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=lrbSK43NLfB2e4wOG+aqQWdM/1SYnnFodbzmkkuii34=; b=Spkop8h8uE16hrDf4GiPsACbGf/OOwfRvo9iFQ7fP0LrSPLKuiTX2KfnvWNJJlAjHb l+PYy7Pn2MOipznkQ7i5+VydvUXrd5AKv0EyBWOrxq89SL3FZnZ/7moNwjsSu4U8Oxqa +Afni0JD9+7U3HT6Xd4lMPVPn0mf0dVS7QVmxR/uNquGf5hDgNxEgnGWOMC5HNxXqrv7 52uNXwSJVAAgui1ej9FUSVA79/nqX0lzECBcT49Imyq2v2HVHduuT1khdFVbPkWG9Tr8 iwdA1jbo6LCQVFJWV5EqFnNKxaJ2bPhshlc1n80Kuz2JU7VVl9gjrgVVKdu1A4ico2kH KWGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732292092; x=1732896892; 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=lrbSK43NLfB2e4wOG+aqQWdM/1SYnnFodbzmkkuii34=; b=O4/K0eZD27VJxArSPN0BV9zqINV5oErp0p6oRrrtER0QzZ2+E78t/DGIq3/XT7z0CW aTNZTe8qmUe2WIx3oDnvW54soTUkKwgzAlA45FF7A3Vqkl2TkeYMFy8nPT8EehHxgkIe lC/1JzGEKaK2z/mRFq+3mPWce4Xis29LSazpoukdoAWED7JsxK9XTLTULeA1ebnltboL ZpVACv3My2eNsIf00Cu3u1U2V7sz3oGn/MuocGRXU9jCUF5lNeDzmz4RjCIywJCmuInI z2kVvgiryzbVXYsMvHsUWF+NRGt6rCStQQfeBw8JZj68fsc2cm2Q9HzF8AUiy+EZZgXW rG6Q== X-Forwarded-Encrypted: i=1; AJvYcCUiDOE2OpYBXZAXllN2WQqwfyWtiVUkeiSgBxtJLP932Gcz+Cp5qbU7UzTZrGdlcvx6Lav46ZjipQ==@kvack.org X-Gm-Message-State: AOJu0Ywul7lEoL48q3VDJwm8CBmeNpCUdfm8H4NJvjTluCE9uy4+S1aM skIBuBX1pNQzjSxpHqpSr5l9xOmFFGNFyGM8jb1xkKSvs4fZaILF X-Gm-Gg: ASbGnctI3x6Pf8FvFD37gSo0gbg1fLsgl+Vat31m6HzG0Ux4+k1QIavP7kDyPzAmINl wK+nD9+IhV1JNuIttDGD8bng3FpeIM5ptPNxp4KowJFcJs3YWd5U215K6+nnICsANbbCCSC62l1 TkamcuCOIeVRxNctoxZwCh7haIkjng3fs+JEiysD9b925r3GMubIxcwI1XQpi+qxDb17FCbBdMq EqTUE9efeBv7ZEbOpJgMNUE7q6zVgikW175mMIWqPxU0nCiMIZ0r1Yu71I8OlaZMyI9X+TJA1E= X-Google-Smtp-Source: AGHT+IHZBKaTxzynLBARfL0nD6HFNiUz9zQkGuzJbrgfSWXqatNsBKAMj0e4czJDygoyIwHBq0V3Zg== X-Received: by 2002:a17:903:230e:b0:20e:95c9:4ed5 with SMTP id d9443c01a7336-2129f5c3b21mr46128455ad.7.1732292091863; Fri, 22 Nov 2024 08:14:51 -0800 (PST) Received: from localhost.localdomain ([112.2.230.32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc22009sm17890195ad.264.2024.11.22.08.14.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 22 Nov 2024 08:14:51 -0800 (PST) From: Wenchao Hao To: Jonathan Corbet , Andrew Morton , David Hildenbrand , Barry Song , Ryan Roberts , Baolin Wang , Usama Arif , Lance Yang , Matthew Wilcox , Peter Xu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Wenchao Hao Subject: [PATCH v2] mm: add per-order mTHP swap-in fallback/fallback_charge counters Date: Sat, 23 Nov 2024 00:14:43 +0800 Message-Id: <20241122161443.34667-1-haowenchao22@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: ne9peeoim64njr8w5hfanh4mcs41ua8x X-Rspamd-Queue-Id: D78F320008 X-Rspam-User: X-HE-Tag: 1732292033-967849 X-HE-Meta: U2FsdGVkX1/aTaKER/CBEuDm1YL9chqyr0I6mdX0cj6DnOFG3U/ax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asCxxIQoa9/TEecbtZip2jrZrLEcazgJXUNQD62FnkMbN4Cl1scfXUGOMB0E45XxQi4oKwsLbn11E7JR2eH9TcGT4ws5YA0GdkYTt8Ix2NRPXERFMPgoBc9u34jgqiq/JexNYH66K6Dd/BIuj3PzUBEDg267Qh1bC35CdITes/cLvftmo5HW+AeJYW1Ay0gKScV6e6YOR0yhayAzOFtweytyfuChHJs2xHhiapUziHJKD9GrIV/vpw57fVTorQa5faV2b77nLJt3sLmuL69jbDEXeNSNiHWU5IybB+DI= 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: Currently, large folio swap-in is supported, but we lack a method to analyze their success ratio. Similar to anon_fault_fallback, we introduce per-order mTHP swpin_fallback and swpin_fallback_charge counters for calculating their success ratio. The new counters are located at: /sys/kernel/mm/transparent_hugepage/hugepages-/stats/ swpin_fallback swpin_fallback_charge Signed-off-by: Wenchao Hao --- V2: Introduce swapin_fallback_charge, which increments if it fails to charge a huge page to memory despite successful allocation. Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ include/linux/huge_mm.h | 2 ++ mm/huge_memory.c | 6 ++++++ mm/memory.c | 2 ++ 4 files changed, 20 insertions(+) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 5034915f4e8e..9c07612281b5 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -561,6 +561,16 @@ swpin is incremented every time a huge page is swapped in from a non-zswap swap device in one piece. +swpin_fallback + is incremented if a huge page swapin fails to allocate or charge + a huge page and instead falls back to using huge pages with + lower orders or small pages. + +swpin_fallback_charge + is incremented if a page swapin fails to charge a huge page and + instead falls back to using huge pages with lower orders or + small pages even though the allocation was successful. + swpout is incremented every time a huge page is swapped out to a non-zswap swap device in one piece without splitting. diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b94c2e8ee918..93e509b6c00e 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -121,6 +121,8 @@ enum mthp_stat_item { MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, MTHP_STAT_ZSWPOUT, MTHP_STAT_SWPIN, + MTHP_STAT_SWPIN_FALLBACK, + MTHP_STAT_SWPIN_FALLBACK_CHARGE, MTHP_STAT_SWPOUT, MTHP_STAT_SWPOUT_FALLBACK, MTHP_STAT_SHMEM_ALLOC, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee335d96fc39..46749dded1c9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); DEFINE_MTHP_STAT_ATTR(zswpout, MTHP_STAT_ZSWPOUT); DEFINE_MTHP_STAT_ATTR(swpin, MTHP_STAT_SWPIN); +DEFINE_MTHP_STAT_ATTR(swpin_fallback, MTHP_STAT_SWPIN_FALLBACK); +DEFINE_MTHP_STAT_ATTR(swpin_fallback_charge, MTHP_STAT_SWPIN_FALLBACK_CHARGE); DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT); DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK); #ifdef CONFIG_SHMEM @@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = { #ifndef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif @@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = { #ifdef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif diff --git a/mm/memory.c b/mm/memory.c index 209885a4134f..774dfd309cfe 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4189,8 +4189,10 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf) if (!mem_cgroup_swapin_charge_folio(folio, vma->vm_mm, gfp, entry)) return folio; + count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK_CHARGE); folio_put(folio); } + count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK); order = next_order(&orders, order); }