From patchwork Mon Dec 2 12:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13890553 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 8CCAFD78318 for ; Mon, 2 Dec 2024 12:47:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E84276B0082; Mon, 2 Dec 2024 07:47:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E32D46B0083; Mon, 2 Dec 2024 07:47:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFAAC6B0085; Mon, 2 Dec 2024 07:47:52 -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 B1A5D6B0082 for ; Mon, 2 Dec 2024 07:47:52 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 451E51C75D6 for ; Mon, 2 Dec 2024 12:47:52 +0000 (UTC) X-FDA: 82849995438.19.4CD6294 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 5899114002A for ; Mon, 2 Dec 2024 12:47:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="OUPtfzS/"; spf=pass (imf09.hostedemail.com: domain of haowenchao22@gmail.com designates 209.85.214.178 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=1733143662; 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=qCzMoMCswwZtYXZlSm324faiWhRkG3dwRJTSsFPFn9M=; b=3a17GfH7J7trGgqjAYJlfllxY9D1lZMbrFXNltYGTiXO51WHh9GrrstAgWJKCfSN+HuDl8 NSdi3CFv4vqVDTpf3n/xAKPPbSQ2tswa5FfsYB55FdWe6nVImHhdnlxwMgUR4vHAdGa9fl aR4GPhRmv/BTOz4IegSKqXa/e91FIDk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="OUPtfzS/"; spf=pass (imf09.hostedemail.com: domain of haowenchao22@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=haowenchao22@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733143662; a=rsa-sha256; cv=none; b=0JmMiiK1aRr3Ws4wkt69J7fuxLY18QTbidvsVbqFTz6P3FpXqBWL0VJcmueXr7V2cl/bBy YNvhhDlWnmbqf4BRhENQ0mh2dYMdMLMzuMMcazyOyRi6JFwaNTWgXE6/sZWyeoK1sx3TKD tUC4TrNvdtJOY2BkWhuHo+K4folvurw= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-214d1c6d724so31414375ad.3 for ; Mon, 02 Dec 2024 04:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733143669; x=1733748469; 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=qCzMoMCswwZtYXZlSm324faiWhRkG3dwRJTSsFPFn9M=; b=OUPtfzS/S4F6EM/PlSYm8/NxsjEkL2U7vLD9CYGr3+8nKyzwAApIyHoA32NYMOCooM mgZwCLexoHhSgplfTNgKvBb/1WK7Qdn8q17hDx6NS/w6I3fNR02Cb2kmznWRt+Im7f+Y wyb5LKcep1tp2tCnkWooJ+Z3fU9gI3Xsm37gT13p1lG2unDIvSbMQJSwjWLH6m0L0UQd nPn+MDbaBTRLDHrUn+1SMgVjRfQhMHIJK/QVstaCrrMEuuKmi1o+6QG2hysA2yVqP5qp Lh+Rcl3+SECbw5JtqFwf8wQc4MH843IaX2NEuyf66Q9QUCdJ5Cfpm/DVqSqnPsJ1FZfQ Rwfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733143669; x=1733748469; 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=qCzMoMCswwZtYXZlSm324faiWhRkG3dwRJTSsFPFn9M=; b=UVA02gEAK+em5JQ8nEjkc9ufZhMoCE2hgPL2HPVtcXgHah8GsaKpqR9fkAq+7Aah5M O40FjzFQclFr37rdjoM6E5lUgMjYVT/u4qE1x+VOsFjg5ryHUV1sQSUoIlbUep8EcsZy 0QmZ0b6B7/F+wgwZRH9CxS19v9Rv+SwOUmn5SyTJcOEaquiSFOhoIKITiOM+uSdjKyh8 1GD2wTkcPkUpGd5LQlNSmndPHlXvTpmZUgYv2Tq7y8cweZDD/vkqowUXjfgjWLLKfLa6 mZadzL4yu2giZ+dfn4YxLvzzqb1pbTI6SxPOiZo0JAmlz2ne0+4Jv03/7Fzi95K8J1C9 e2Fg== X-Forwarded-Encrypted: i=1; AJvYcCXh59yA2jk5EnEkwUFTdX3R4Xs8gIlMiTrr8mdQwEQ3lLAYcImbegJWn4RKzUiE+6Tzx6mUH/yJIw==@kvack.org X-Gm-Message-State: AOJu0YxJSG70aomn8X/CU/ylqcFVXL2adJ2w5tT1e4KDos6sH6DTzRJR Kv1eIY+JNBTRKFbPxvUaeLWchMuFBvPLWT6/WShO2fVYd7Rw9vKUhRlN+vJslsE= X-Gm-Gg: ASbGnctR8lg7QTTYE/NSfykShSvCjjarU9fOSmpvvwxT2zZ7Mio1fUn2oqlBh7PfGRx 2lve/pHKLiM+4yVWtGSSfTME3g6UAYD7bxI43lAD7yeIjROjZMS2fYjuiKzsH1kahH9rswxfJul kyshGUsih4TCtSjbFBmblbXoGY7/ZkXrcEuN+viv7E/hheFCPu005U4ngkG2+Oiz3J5PlL/j1yb VtlQQaUKgY555nG8IUTY24kEiWgtsRZrseD3Hwis1je2soj3HnZQUqnyyS6gO4= X-Google-Smtp-Source: AGHT+IGhTGeEW3OAHtQJ3zwilcLHoZEoDFMHHB9GCJ19gCSLGgHx3RTLysE7YXX4PPyCOI/CS1zTAA== X-Received: by 2002:a17:903:1c3:b0:215:8ca3:3bac with SMTP id d9443c01a7336-2158ca33e29mr68764465ad.16.1733143669041; Mon, 02 Dec 2024 04:47:49 -0800 (PST) Received: from ubuntu.mioffice.cn ([43.224.245.227]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215218f22cdsm76041275ad.36.2024.12.02.04.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 04:47:48 -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 v3] mm: add per-order mTHP swap-in fallback/fallback_charge counters Date: Mon, 2 Dec 2024 20:47:30 +0800 Message-ID: <20241202124730.2407037-1-haowenchao22@gmail.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 4fhydbo6tsp71zq8cqqeedumi3bu9pna X-Rspamd-Queue-Id: 5899114002A X-Rspam-User: X-HE-Tag: 1733143662-319057 X-HE-Meta: U2FsdGVkX198Vx5myls8/FUPI+l6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ou7RFKioIqDm4sFmTGxrdZGN+ZuzIl81swgIP7egGd/5al+8p7lXNIJe1ZR2kqbVIrsQjMFHFIP/WGDkYqJ+5w/JQG01vpKAr+hSfGiL0e+m57J1vby+fr4cgeSU3rRbkUmnjRHEfCMuwIP1AOngVRLJ0nLXytN5VD/eXcfpdUQv0y/pprK0xtjzF9/R7u5iHyejRvTiYrWw5nM/npIBLm08vX+1IzaqxP0LQtcQGM5KKcDJukFbT0WwTqf6mWOwuNABUO3S9xlJU6dXfaZATH0mhhf9n52F03vEKZWtrqDKd2g8kywf06oUWVhKOlmw6IDGGOH79Q= 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 --- V3: Update description about swpin_fallback and swpin_fallback_charge 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 333958ef0d5f..156a03af0a88 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -591,6 +591,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 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 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 ab46ef718b44..d062b257376d 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 d5a1b0a6bf1f..a44547600c02 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); }