From patchwork Sun Oct 27 01:19:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13852393 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 5619DD10C07 for ; Sun, 27 Oct 2024 01:20:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD2C66B0085; Sat, 26 Oct 2024 21:20:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B81AC6B0088; Sat, 26 Oct 2024 21:20:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A496A6B0089; Sat, 26 Oct 2024 21:20:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 866396B0085 for ; Sat, 26 Oct 2024 21:20:20 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 43DF91A198D for ; Sun, 27 Oct 2024 01:19:42 +0000 (UTC) X-FDA: 82717626348.02.BE758A7 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf18.hostedemail.com (Postfix) with ESMTP id F3B551C000F for ; Sun, 27 Oct 2024 01:20:08 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AFRxBKXT; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729991939; a=rsa-sha256; cv=none; b=tt0UWDvj1z2TdR/9H0UtEk8R7u1+gXNcdKLpJwHPoehCevvJS6cWUSyvgIBLc0kcbknfBf 5afdTzdYS3z0GYahI7LdD1jI2isvWRK+6OUkziru8RA9gzryDMBmnWmScjTSyyVGw0EbiM BRtrpUPnMfBwefOLn9VRvjTINddLJ2g= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AFRxBKXT; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.49 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=1729991939; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=PC+F0uXppq0my0Enu0GUjnL3zjI0FTc8OpigtshywaQ=; b=yNzJ1wEqvbDhnIv/Ep9wJr7DaZ/qW7qcW0peXouAQHMCTS0VFLHX1ukqTXpJRHTYM+dd0V BbVVhm37XLtVxkwi3L1Vm8rNpLW0Vs6XJQOdU9fYlgltF+d28fKrKHgMdDqDTL+a2CXAUh PNDLAmVHK0wcHw3UYnY9ruo9/5dDm9s= Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2e2dc61bc41so2289984a91.1 for ; Sat, 26 Oct 2024 18:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729992017; x=1730596817; 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=PC+F0uXppq0my0Enu0GUjnL3zjI0FTc8OpigtshywaQ=; b=AFRxBKXTanIZ9xki+KfFxMUIhSOuJ2HGOttIudpa9Kd9gfd6p56iUexiPFkUbJC/Ca Grsvnv5dKNxKJocRudtrZ9jwLOFcLJHbB/ubchXCgcB7k4EYd1D9irPZscewgBFeDJUj TPpr16xDlkgLdrvTEPeWX+58M5amo6zZgLOx+b4Vt2wYTwUII+FvK/1FGkTuHJs/MYl+ 1LlBoVFaar07giSMVQJXagcUIYtkAJ/RRBcZgxcpHSTV+kME+5M3UqoRScpRB2k8pO7Q JKkX6Ubkco0KpkNl1z/w9rZLIlSEg7l9P4SD0YjPiDI9MlxPxbWZgG2Uxn4BHgjArMyq FMLQ== 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=GUKTV6rHKZiA1yxyt6YPO7fqe20X+cmOYCH0tgDvN5bUZZGT86HVqdOjl8FuzbZcW6 NLsGKp2hAOmKfPc0mCDT7/DuSNuafUcx5OYqR1er+OOO3OVvARbmJNPd8xTJDbC7nEtV 0Bh7Canxao/Ek8W9fKuLAW34z3+g4rSKI5CuJ3fj0UepbWQXTdkMbVm0uAu+PGE/fnH2 aaHqcC0FVHKPN2f5bkxuU5szBZq51R12anQjL5b/fdZOis4v8PN1xdTD4jKVNZ+iM3AZ PLzJ0UwFJMsAIi4n+xD6+8QW1tf5/ddaY8ZTYw44ce2iJXFRvD4pxucttCgkMSZj0I5m X+rQ== X-Forwarded-Encrypted: i=1; AJvYcCXMYNbnVxhaobBZaVHyqGZjzGX6FwL9PVZtasdOKPggAmSB/zfEtojo8iTfttSKh5rMYM5q2tLmsA==@kvack.org X-Gm-Message-State: AOJu0Yym9TpPKYTCDYEbMoBiwT5p1Q/9FwvoKtQDq5eBd6aG9V4Aw4Wi xoBgaAMYwHg9oPmMvIfOhu0sVIyEK3U7Rj8eRJ92bXXU4kJAscKR 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) MIME-Version: 1.0 X-Stat-Signature: ug6pc3fns8p7sik7o6h5865w6asc7hfp X-Rspamd-Queue-Id: F3B551C000F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729992008-860830 X-HE-Meta: U2FsdGVkX19vmLxQ3yK+FMGrfta+FV8cZPRQFw/M4FpNwnsy+Ug68zwjDFM5/1N9vMr0qyc+kHGgwD8NaGKEu64/zlimcYUfLJ95SlBD1z9DkxqgzD+xCFSTdbBxc1QyrIJ3txTnZbQjBSrqltPehdhktVGga5kfb0xkY6IWpdgbpeKjVZsOeO4+z3cp9lKW/OmT4HFMQyJiRPpcwHS/Igr6E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xM/7OLZccP4LC7wo9InfXAJBxLacFdqzalfOySees2i11SRU7l0kzkajMJMcePNe2HIPH5FKQ4FHNfBJODJMhD3PfCNYhbVdkBzS7tlQRCyMlcwSaEYp59IBt/guVnSeKbiES2sMfFC9W7UkGvWYsyxdL3vrlsKXPtd9Kz0ApWLdRc3UvgLlyxLbxFwiHv2TDUwpOxy5kBHqmJIMTXJzSCsyJQDRCvunfqqCkWR7uso4dbJJeDoF0hvkmmtzHLP5AcxJ48OApIxahbBKcl44XPIfWwA2ETvHXLupmRRADncS1XTh5YZC/cUBJEvK1PfsJEU9ewEkqwKmKaVNLGFxYuDZXBI2nGJwq+iq1jeiLQVNPO5nHpLB28wuywvt9ijq9BoLuMhKZHF/oVJahO6memLdnyiuYUrXAIyfiCp2E27p5zWlTEVdsjHP390mvw6pkaum 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 When the proportion of folios from the zero map is small, missing their accounting may not significantly impact profiling. However, it’s easy to construct a scenario where this becomes an issue—for 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 *folio) } } +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; } -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 *folio) { @@ -621,6 +622,9 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug) delayacct_swapin_start(); 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)) {