From patchwork Wed Oct 30 23:34:23 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: 13857310 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 7667ED6B6B4 for ; Wed, 30 Oct 2024 23:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D03F8D0002; Wed, 30 Oct 2024 19:34:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 080B88D0001; Wed, 30 Oct 2024 19:34:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E61C18D0002; Wed, 30 Oct 2024 19:34:36 -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 C88458D0001 for ; Wed, 30 Oct 2024 19:34:36 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7891B810DB for ; Wed, 30 Oct 2024 23:34:36 +0000 (UTC) X-FDA: 82731873588.20.A4B64AF Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf27.hostedemail.com (Postfix) with ESMTP id F332740003 for ; Wed, 30 Oct 2024 23:34:07 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eUETNDgZ; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.182 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=1730331230; 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=XLinXQ+6cmEN16o8u5D/vD9Sr8m7QjMLrxE4k4mlIMI=; b=eeYPEKu4PcpQE2IdLjJVq3J7rIM4g347z4pe1Mp745EhT9j+WNSbP0g2n+nUwI4uzqHn7S eHBDcTAuzz3QzItn7SSeCAKH2K68VVwzOyLi+eNO33ZzpXp6jKoSKVv30t4Kjdll6c2+4M 0xxwz3FOXDopbgndEVoElelNsw0xwU8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730331230; a=rsa-sha256; cv=none; b=RopNx7g2aNGxR/cJ1QEUVZzX136ZOmwzRbSBy84PZo7w7leEbpOFIXn50uF7p31S+S5MHn l2tg2N2sANeYtBxZ9kWNrIQ9GcVU86w5Xunl/zkvv8v2fuJTjiOXqEUN5xsp9k506U6e4L hsH/JFIjNm++MH1q95Tm6Uf3tMEbByg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eUETNDgZ; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ea0ff74b15so312101a12.3 for ; Wed, 30 Oct 2024 16:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730331273; x=1730936073; 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=XLinXQ+6cmEN16o8u5D/vD9Sr8m7QjMLrxE4k4mlIMI=; b=eUETNDgZUjLJhtqv/3vJWMxjx494U/9r2K4c/wTLZycDX2z2BNbk6oQy6V4KNVXx7X ZqD+JaEtmrEJMC1gu7oc51Z2G3U7ryX2uthXbvMOE8WaLO9/thrpYZAMaykK+uvOpgjm yb2QgiyOe7suOpDJxn80WnKOWVUiuQ2hMd6hI3Nq2vp4fPNaGngbe9pWwFlxhl8lK5C3 Ej1476eVY+U26RgenVsbphwPGFUI0YDcOD6Du6fU7JRICA2SCTScFHQGfb9vABkJ8qJc 78tcRo4oId9WV0tspnhsh3HwcgwhsswMuLl66WcyHjX6qOvO32YFCIasC7CLWe4oT+uv +DWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730331273; x=1730936073; 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=XLinXQ+6cmEN16o8u5D/vD9Sr8m7QjMLrxE4k4mlIMI=; b=PYeLxiKpKL1Rd9vTmissEV5JNBZTUU9KvVWca2iF1ppMfL69ZIRtj3b/CD/zsS70t7 LouUh0KY97oJ5bwiGh3rOC6LqlohXMnX6qYSM3h1s5g+Yeget3ZLOmnb6NfbzHQLOuLL jpRe9/ihBxhkZmj7XRvB3STePjA5as275vi5vQLSRo/DyryBuc5CUayziqMwYHohehva NlINVUItFparlIrYnsVVdJhE0mNXZKZrDxOTlvxO7pUD54YayYkk18v/Oy+TE11XKtVx 5ib7CF63ISx6M6iJ38EQbnjTtRTMgJTzjJ2druJFrm4bFqL5wRGU6IBk4HfmF0kLZAHs SlpA== X-Forwarded-Encrypted: i=1; AJvYcCXzhJeXLHvbQqXQRTMo4sIiTMONealTb3akX9kOL0OCT6oHO0wFMuSicmR0A+Jfwowvx6FdKendzg==@kvack.org X-Gm-Message-State: AOJu0Ywi7Yqq97RUr53w32HE0y0ial543Ge26Y8pdDnrFXdkRdKA3m+j gPlakfeIItgZ+HLBB9dsgH9nhDtvJY2TmRWrrIP12j8F2FDRmRye X-Google-Smtp-Source: AGHT+IFMBQ6hOXENoU4C2iQdnIx5Tbzd8Kqz+qFUsHY4NTcdFkrpcKXbX7bk1SCdDQv21XVjwd/UCA== X-Received: by 2002:a05:6a20:43ac:b0:1d8:a759:525c with SMTP id adf61e73a8af0-1d9a851df61mr22390033637.39.1730331273060; Wed, 30 Oct 2024 16:34:33 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:3db0:5853:dba9:51af]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ee45a11cbfsm129307a12.89.2024.10.30.16.34.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 30 Oct 2024 16:34:32 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , Baolin Wang , David Hildenbrand , Chris Li , Yosry Ahmed , "Huang, Ying" , Kairui Song , Ryan Roberts , Kanchana P Sridhar , Usama Arif Subject: [PATCH v2] mm: add per-order mTHP swpin counters Date: Thu, 31 Oct 2024 12:34:23 +1300 Message-Id: <20241030233423.80759-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Stat-Signature: a4mgn9mcbxnhqsq9m6wjzocd6m55jj73 X-Rspam-User: X-Rspamd-Queue-Id: F332740003 X-Rspamd-Server: rspam02 X-HE-Tag: 1730331247-412294 X-HE-Meta: U2FsdGVkX196Q7XnHqi2dRaUJEOY+1lYetv4+6S6wuyyjVTQt5C5HUvSfVKNnrOyGrKF2FwZa0Kqiqi0pQ+zwWlHA69YDq9qt9f0brEHRnl0HqmSbeVLP57jqZ8hokZCp8ZPDK1joY5PydepVSg7kD/p42GHtx5LiO0916co9fgPYL4aX3dl3hXdqyamVQl7xuMSTDT2byB6D4Zg5XHh0Qp2EuQDG1iNHzLkSS5ZXFIabdWEG1hFt3a4jEYcQoUb7H/4GAiJUk4B7iNUkLp85f4yXoKb0nxbFpd/PptJR29J6F1xtjVOoZ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Gzy1WO6jR6hMafIkk+m69fXscoPYXS7gqgWqCItSQ9c+5zA/07pf9jQASbh4q4x0OMUt2LaegcsBHlt1fnh4Ocg0h/aVDqmcABr1JfT1Lgl1QUoYEayGTSF8IZoEzK1/J+G2tQICqfELCdyzv4u/dzXbXBcyYgt4m63gBa+j83BQx97Rfx8fzyd6GO2AuERQJ0+vVNSm0/K7dGXfRo= 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 This helps profile the sizes of folios being swapped in. Currently, only mTHP swap-out is being counted. The new interface can be found at: /sys/kernel/mm/transparent_hugepage/hugepages-/stats swpin For example, cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/swpin 12809 cat /sys/kernel/mm/transparent_hugepage/hugepages-32kB/stats/swpin 4763 Signed-off-by: Barry Song Reviewed-by: Baolin Wang Acked-by: David Hildenbrand Cc: Chris Li Cc: Yosry Ahmed Cc: "Huang, Ying" Cc: Kairui Song Cc: Ryan Roberts Cc: Kanchana P Sridhar Cc: Usama Arif --- -v2: * collect Baolin's reviewed-by and David's acked-by, thanks! * add some examples for the interface in the changelog, Per Huang, Ying. thanks! * add a blank line in doc which was missed in v1. Documentation/admin-guide/mm/transhuge.rst | 4 ++++ include/linux/huge_mm.h | 1 + mm/huge_memory.c | 3 +++ mm/page_io.c | 3 +++ 4 files changed, 11 insertions(+) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 2a171ed5206e..5caa3fb2feb1 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -534,6 +534,10 @@ zswpout is incremented every time a huge page is swapped out to zswap in one piece without splitting. +swpin + is incremented every time a huge page is swapped in from a non-zswap + swap device in one piece. + 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 c59e5aa9b081..b94c2e8ee918 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -120,6 +120,7 @@ enum mthp_stat_item { MTHP_STAT_ANON_FAULT_FALLBACK, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, MTHP_STAT_ZSWPOUT, + MTHP_STAT_SWPIN, MTHP_STAT_SWPOUT, MTHP_STAT_SWPOUT_FALLBACK, MTHP_STAT_SHMEM_ALLOC, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b26c6503e993..f92068864469 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -616,6 +616,7 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_alloc, MTHP_STAT_ANON_FAULT_ALLOC); 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(swpout, MTHP_STAT_SWPOUT); DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK); #ifdef CONFIG_SHMEM @@ -635,6 +636,7 @@ static struct attribute *anon_stats_attrs[] = { &anon_fault_fallback_charge_attr.attr, #ifndef CONFIG_SHMEM &zswpout_attr.attr, + &swpin_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif @@ -666,6 +668,7 @@ static struct attribute_group file_stats_attr_grp = { static struct attribute *any_stats_attrs[] = { #ifdef CONFIG_SHMEM &zswpout_attr.attr, + &swpin_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif diff --git a/mm/page_io.c b/mm/page_io.c index c69fab5060a1..5d9b6e6cf96c 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -487,6 +487,7 @@ static void sio_read_complete(struct kiocb *iocb, long ret) for (p = 0; p < sio->pages; p++) { struct folio *folio = page_folio(sio->bvec[p].bv_page); + count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN); count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); folio_mark_uptodate(folio); folio_unlock(folio); @@ -573,6 +574,7 @@ static void swap_read_folio_bdev_sync(struct folio *folio, * attempt to access it in the page fault retry time check. */ get_task_struct(current); + count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN); count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); count_vm_events(PSWPIN, folio_nr_pages(folio)); submit_bio_wait(&bio); @@ -589,6 +591,7 @@ static void swap_read_folio_bdev_async(struct folio *folio, bio->bi_iter.bi_sector = swap_folio_sector(folio); bio->bi_end_io = end_swap_bio_read; bio_add_folio_nofail(bio, folio, folio_size(folio), 0); + count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN); count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); count_vm_events(PSWPIN, folio_nr_pages(folio)); submit_bio(bio);