From patchwork Thu Oct 31 07:53:25 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: 13857673 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 86099E6895A for ; Thu, 31 Oct 2024 07:53:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA0036B0083; Thu, 31 Oct 2024 03:53:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A50E86B0085; Thu, 31 Oct 2024 03:53:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 917406B0088; Thu, 31 Oct 2024 03:53:39 -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 759B56B0083 for ; Thu, 31 Oct 2024 03:53:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EC71AA0ACF for ; Thu, 31 Oct 2024 07:53:38 +0000 (UTC) X-FDA: 82733132202.12.368FF9E Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 03AC840009 for ; Thu, 31 Oct 2024 07:53:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aBVbO7wC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730361055; 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=sU363tB9SzeZJUVZs434e5usD3yu6o22dmX8GcOkH+o=; b=N1iSwypJNaL8T9O+GverPnVZk9ZoHmOYRKCq5UKL4kjpuU1gs9v3qK+8/u4w6+XELwIpgY Qbjj47w0U4hRzjyHzNWNwSyY7cREaB52cPT8QTAjUFOHD6xJzVHh0jN8JyF1hCBK+rfYc1 SxMiE7HTStLs83ris8Axbqq38YoPRT0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aBVbO7wC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730361055; a=rsa-sha256; cv=none; b=EG+WfIx9tGoxllViHH110nTJo8scscNKRVbyNTIQ29HivFfcgDSlZb+knwbpFFoTYJqqc0 Zi3mLU7eIBJwcYmqyaU3wYmfUlR7tv+qFCR689tXKHZvFWFt6H1/gqKal6/O66dF2He+9S ASBn+kSB77Oeosc0ko0nQrvywkbKW1s= Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20c693b68f5so7393085ad.1 for ; Thu, 31 Oct 2024 00:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730361216; x=1730966016; 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=sU363tB9SzeZJUVZs434e5usD3yu6o22dmX8GcOkH+o=; b=aBVbO7wCcjEmhAL4npQKs3G6BLGerT/erjhDXZnB82G4TnuaUQ87ZRbnR+cl0vdMAJ l2Al2+xJnnl3AbywrF0sUySj/kc59VX4AcrMoS1amPwpZhJ8GHvMMjJmf84AzDu5xZej vKGyRCvJGz90/O7UZrObXKQzGXVTiLY6Kf2wyw6dUVtGrx3V5xqPIVS8jFMSUUrtpjrd frpD4TY9wr8VrYu28IiAO7X2fvxbj1u9QRH84kKiDF4GiucIUOk68EcSIBPQhQmxGf6a zsMC6GpwkfpmfepqBGUiW+VqorC2ZPFXoNtVJnl+Zcuz3Tr4SrFzMOvxSEiYTg8TUkD+ BaEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730361216; x=1730966016; 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=sU363tB9SzeZJUVZs434e5usD3yu6o22dmX8GcOkH+o=; b=scZNw0qkDBLCO/JB3RypUDtlBJXEZN8hgMxmfwylbt8ZZV2Ive5gVllR8UuuvVwbU1 SGp3iM23c/1iMBJ5BaaJKaLhHiWHm+crAVKY7KQvbBLsfwB9uzyYWdK6d7FLdKZfnVyO UlncvtsIDBTyAaGAcYTYxN6sftG8d9pRhIvqJzV3D5mFKsDSu1KvuRZ5fXCgraKxymsl s70AtRdYCCtyrCiOyBK3lUIi0SM6NHYMHjl80E7qGjV7zEEMO8G5QPBIhujn0tXQwhbw v8MXT7TWdqpnYeMkYq9i81ltzwr6Uh9qJXuzp5uHkc16hzARqdx8IGSuS5bU/m6gDzNb x8Jg== X-Forwarded-Encrypted: i=1; AJvYcCUgsImlBp4mIzpV+CGCI3wKmzrT8xfj5kKKUso0PtBsyaCgcbvN3p2fmtoKOOkdieTQismvN0xQDw==@kvack.org X-Gm-Message-State: AOJu0YzsG0Yo2nNLeUlchOx9L3ICDH4+HkcD6s2eK73KXbibc/v3WuS5 5aMIzNWNVVBJR9cRIAV9y+tcCRsA2/KrBbS7zIJhSy74+Xm8HgQv X-Google-Smtp-Source: AGHT+IEMaIacrNEzQWnP3x9A3xtQPUa6GNLwSJqzoZ3Y7vWC+lCf1dGa/O/BBvY5QcpAwJ+ZZ1m4eg== X-Received: by 2002:a17:902:c40c:b0:20c:7d4c:64db with SMTP id d9443c01a7336-21103c7bfafmr24112375ad.49.1730361215675; Thu, 31 Oct 2024 00:53:35 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:a0a1:9dd7:69ac:8730]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057063f9sm5415695ad.65.2024.10.31.00.53.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 31 Oct 2024 00:53:35 -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 v3] mm: add per-order mTHP swpin counters Date: Thu, 31 Oct 2024 20:53:25 +1300 Message-Id: <20241031075325.1037-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 03AC840009 X-Stat-Signature: d3i9181cuh85m7fujsrup8mcgx984ux8 X-Rspam-User: X-HE-Tag: 1730361189-236560 X-HE-Meta: U2FsdGVkX1+3cms1/o/POOeGhC1A2Sk6q88h5dyGlHtLtkaewcLOAtfiLHApl2nhN+5LMwf0+m8/wNi4Dnivj6ljsqnuOD6ouYiQqXc+LmP39w1eor3Z4yvKWhJB3fJPiwBcSPMR+uhxuXDVd8WMH52uqtcJzvmmMJjEC/oHq0SmXNDVWx8PK+VIz4EdLyJyYmFVBzpNhxKas+IVJ8i9FSMFo2EzdI7/syX2Jo1DdcE6mwFVSqPN1T633PaMTpZQ/2fFNOD0zgGjWm4FW0BBnVjEhVR30F3H8FSP4J/gYHQfGFKkMCO+/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IWpswQCYIKJlsbShPUQEa3t9t8o5l1uXGIM5QYi9jNrylanqRvkzZckLPPOY/a7JsKWeVE++cRpPR+Hs0WW73+sE/Q3AWvBLglRpsKAiT+jfKH0pEIbN3gz4HkF1tqMc5xtMzGdJf0H4JNvJN8w4TwXPD9MjO9U+V7TXgkL+SYCjIUt24CKg/fVp8rHCoPEqyxFwoM6P3My5uQ27miwDCYFmhfv3a8EBa5Vjz9yZdqWg9Vno0cQ= 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 Acked-by: "Huang, Ying" --- -v3: minor refine changelog per Huang, Ying. thanks! 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);