From nobody Sat Feb 7 07:55:53 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2E94C85 for ; Sun, 27 Oct 2024 01:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729992019; cv=none; b=OtiREs4oqpOOSEgg3oUd1MKsZgousEy4g9NrLUF3+SL8rjreVr7a/2QM498XqBwIBcGPvvrIDAqWs0uW/pvdAVEqO0b24W9YK71NF1Pf3zpxuhvI0Lwla+Safi9ZXhKGegYSkvdZy0ooqBi5NB8KWpSMZePOwodaxNMJF6Wy5bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729992019; c=relaxed/simple; bh=aoGOW9UMQu3eHbNSLgmSRaBhzUUjb5RcXfatKTV7/3U=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=WcgULrU3qyqYlgWH9yqQu/Spm30PfDwrKUI+l7B1H08CO2ayR0A0RfGZGsgHQixvZu4Mqgq17LzX0dlMfwe6h1TPsrQvBjP+/EoIvUMYoaCIIMWx8s87Yr7ASmU7OFKx882WH+HxVuidlBGct2QfRO6xUa+/CFqIzes2C7bTQHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ynz/jgae; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ynz/jgae" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2e2dc61bc41so2289983a91.1 for ; Sat, 26 Oct 2024 18:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729992017; x=1730596817; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PC+F0uXppq0my0Enu0GUjnL3zjI0FTc8OpigtshywaQ=; b=Ynz/jgae2WXckGSPUTgOoQHCCNwICDOl5Qf6oM/KgQ+tOnpXERqqLYaFOF/q/jKHOh Z8ZuTafrtPUlylhHilSW4tOuSoqXij1d/EFnSpt45XY+tN0GPwL7ENm8ZyPvmDYEM3Ke SFcgmJb6SjQB4qrRjJGBzgY1Dg5ConIsyShvypuKVx7peoZNxRxcGmW6qqTvF+zPhITa ufR+ZW7hU7M01EaozvYHUfJmeGA8O+q5UogtIsUzjHxcu7htkBBqEMWy9DSpisQtLv0M YAAGzVKjoULVbg1/pKz/hcgGPyfBLMSfdyPgnFBinHRdP+mlAw89Vlp81pZ1O2AWhTyy UWPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729992017; x=1730596817; 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=PC+F0uXppq0my0Enu0GUjnL3zjI0FTc8OpigtshywaQ=; b=n6GyJYiQHOhBLVLukk45al1YmLBEoPSBNUnUHU0UdIQ7D0KVOA3BoJDSuybZgtmHMz HS4TIoCT18/9acMqQVC244TEPb13Vem3ovsOaHrT6r+/XIx08IBYEIyjuoIOmfmtQaYI RjgMoUZlo9qnOKpPr2vdxH5NfaOy0ghXp9y07sP4o+G48O65q2jFbozvHmzSTqg7gYjg ZLQMeWQzZ7VJSvPt3sc+uMXhMIdirlYhHiho/yZRWRtEakBDyVzyAlPmARsioZ1arzD/ KE7/FOzRBVDlo1KBHETPkaktoqV7GgPvvUlM+fCuhwfQ+ZlM0FQ15HyGMVKOUZf/2J20 YgOQ== X-Gm-Message-State: AOJu0YwtkH6h1MyCmuyV6IhWVzniVJ+AivQt9Q5MrOPGMIAZU0RaHUpk i3rqhxmr4Obq8NL8reXLPcFaHfImxR7MmT6k/CAJSN5GaOlTyKNK X-Google-Smtp-Source: AGHT+IEG22nqSr90rq439P2EfIDTm8P1FSy/cp8zFJqQJiDLfrSlxzYAvColiz62KcHhN3XpYvDaOA== X-Received: by 2002:a17:90b:1202:b0:2e2:d1c9:95c with SMTP id 98e67ed59e1d1-2e8f105f207mr5062395a91.16.1729992016932; Sat, 26 Oct 2024 18:20:16 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:dd3b:f946:8c2b:40fb]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e48bdfesm6204592a91.10.2024.10.26.18.20.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 26 Oct 2024 18:20:16 -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 , Usama Arif , Chengming Zhou , Yosry Ahmed , Nhat Pham , Johannes Weiner , David Hildenbrand , Hugh Dickins , Matthew Wilcox , Shakeel Butt , Andi Kleen , Baolin Wang , Chris Li , "Huang, Ying" , Kairui Song , Ryan Roberts Subject: [PATCH RFC] mm: count zeromap read and set for swapout and swapin Date: Sun, 27 Oct 2024 14:19:59 +1300 Message-Id: <20241027011959.9226-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Barry Song When the proportion of folios from the zero map is small, missing their accounting may not significantly impact profiling. However, it=E2=80=99s ea= sy to construct a scenario where this becomes an issue=E2=80=94for example, allocating 1 GB of memory, writing zeros from userspace, followed by MADV_PAGEOUT, and then swapping it back in. In this case, the swap-out and swap-in counts seem to vanish into a black hole, potentially causing semantic ambiguity. We have two ways to address this: 1. Add a separate counter specifically for the zero map. 2. Continue using the current accounting, treating the zero map like a normal backend. (This aligns with the current behavior of zRAM when supporting same-page fills at the device level.) This patch adopts option 2. I'm curious if others have different opinions, so I'm marking it as RFC. Fixes: 0ca0c24e3211 ("mm: store zero pages to be swapped out in a bitmap") Cc: Usama Arif Cc: Chengming Zhou Cc: Yosry Ahmed Cc: Nhat Pham Cc: Johannes Weiner Cc: David Hildenbrand Cc: Hugh Dickins Cc: Matthew Wilcox (Oracle) Cc: Shakeel Butt Cc: Andi Kleen Cc: Baolin Wang Cc: Chris Li Cc: "Huang, Ying" Cc: Kairui Song Cc: Ryan Roberts Signed-off-by: Barry Song --- mm/page_io.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 5d9b6e6cf96c..90c5ea870038 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -226,6 +226,19 @@ static void swap_zeromap_folio_clear(struct folio *fol= io) } } =20 +static inline void count_swpout_vm_event(struct folio *folio) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (unlikely(folio_test_pmd_mappable(folio))) { + count_memcg_folio_events(folio, THP_SWPOUT, 1); + count_vm_event(THP_SWPOUT); + } +#endif + count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT); + count_memcg_folio_events(folio, PSWPOUT, folio_nr_pages(folio)); + count_vm_events(PSWPOUT, folio_nr_pages(folio)); +} + /* * We may have stale swap cache pages in memory: notice * them here and get rid of the unnecessary final write. @@ -258,6 +271,7 @@ int swap_writepage(struct page *page, struct writeback_= control *wbc) */ if (is_folio_zero_filled(folio)) { swap_zeromap_folio_set(folio); + count_swpout_vm_event(folio); folio_unlock(folio); return 0; } else { @@ -282,19 +296,6 @@ int swap_writepage(struct page *page, struct writeback= _control *wbc) return 0; } =20 -static inline void count_swpout_vm_event(struct folio *folio) -{ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (unlikely(folio_test_pmd_mappable(folio))) { - count_memcg_folio_events(folio, THP_SWPOUT, 1); - count_vm_event(THP_SWPOUT); - } -#endif - count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT); - count_memcg_folio_events(folio, PSWPOUT, folio_nr_pages(folio)); - count_vm_events(PSWPOUT, folio_nr_pages(folio)); -} - #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) static void bio_associate_blkg_from_page(struct bio *bio, struct folio *fo= lio) { @@ -621,6 +622,9 @@ void swap_read_folio(struct folio *folio, struct swap_i= ocb **plug) delayacct_swapin_start(); =20 if (swap_read_folio_zeromap(folio)) { + 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)); folio_unlock(folio); goto finish; } else if (zswap_load(folio)) { --=20 2.39.3 (Apple Git-146)