From nobody Thu Apr 2 14:06:31 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 08564374726 for ; Sat, 28 Mar 2026 07:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684714; cv=none; b=k5ga0BvUZyY1vYHdiZpm4aMnb1HAP8AAKI35mUt7B77YD62BBTwD2XWKrth8xozzlKOcUj5UEAPrQF8GVEB8rYzEm3EasE/1NsRLEPwXvehPlOsZwB8hrFVUpRyvSilDCRdF5Qh+sWMMyn33RURU0j+szbQXfCNtBNaAyCtLZbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684714; c=relaxed/simple; bh=19C5N3WdmSPNf9+It0MrfQdjb3oCxMbo1AM2Ip1gqpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IaLNWQctntQg5x3/gF995gFCOxE5ExJBQwE6KlCUR/R2F+PliYJwF/FTwDa89SqIzxk6dZGbcexgAwGbgfdjmem5qcFA2qJTvSrmuCgYNngoUaVzCYupJHliX5KI82rBcjcdR6A+hYlnPOj9IUx9tbKcaopTWwOxiXbcziX97gQ= 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=R9lBg/Hw; arc=none smtp.client-ip=209.85.210.178 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="R9lBg/Hw" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-82a07738118so1709212b3a.0 for ; Sat, 28 Mar 2026 00:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774684712; x=1775289512; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zKpGcstS/0r6pcN7g7yDWWC+rizREJIM53YHk6Swx4o=; b=R9lBg/HwkWaRu17xGh1HBgtaXnszuj1r/zCn+UnGcWLlPhCvOv1whuJtFw589CLTWo mgJ5Yf6qzukUMnyZ1Wj7cCFgTVClDSjshmYC2Sns/YjhQJuhMlrgpczCZ0SAC8USXgWm pIdPWJbrx9Nn46862Vv5kkiSgdISYsO8sC6/1KN+qfMLIjzrTi73jWu/yG+5Acyo54dF z/+bmxBhdc0SC9MXxDO9/b7/AV7O3HJP7TJ2iAk6l7ws+sCfyIdbRv91r41x7Bslkafy BupABTfC3+p9kc6283buQt9/5rCUl7kVpzV670vmEvm/Tk35kZRSJbTTUI/R61umlUJE srZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774684712; x=1775289512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zKpGcstS/0r6pcN7g7yDWWC+rizREJIM53YHk6Swx4o=; b=dhz7GO9NOOUuhZ7bi1QIwEEMu88snjiQflJkwbnCfuGWL5PJtCCMCWDsi//DEXG507 wkLq9M9e381ez49fcz1PIVXbd0VYxTtFq9senM50bAfXr4tyIcMw4ikX9I7cJJRAJdfy WW4IoP8js6T8Yw+URazymai7RnrtpDnSgvGcieq+U4TJOwWoBmwkL1l/HqCfIsIW4T1o I7f3j4g/kNA2e6S4hrOlsPyW026Gfo4dTr+OsWAfix0N2qI8VH8GOSp2fDXaPPuFzrUp AATLhmy02fvC9JmbUUxwkg4xqXuu0/44AO9TQg3gAbuCiGwNOSJB79Exd7axIUKLTkAJ 8syg== X-Forwarded-Encrypted: i=1; AJvYcCUJfzIEFMywvtysqabHxc9g18yl91ch8Sb1/3sWjvGvPxQ9w5Ktt1Tb7ecONGbTzvG16TOCBTFVtNVNCwc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9vm1ZYrNIUZN30ywrq9tSThFL4oVF7s4puOPhjkd5vNB8jBlu UdmGgZRO2xGlJ4atZgNdG35mNd/0fSHsgdhwQPAloquUOaUyIGrSrbmA X-Gm-Gg: ATEYQzwDwW7cMOzw+5RYwxGIM3Cv9NPBKEfbCuCCVOkJItScBf9J3b6ZA6dIGpu9iqK X4q77Gv/iScKWaMA58UpyNxQ/bVnonZYHZP/jULE8Tf4bcgnP5lX/bHYLSRuUqazpxN8Axba0VN TBMFQi0pQoYlb3QmyWUa84iFgEwBOMyFRIgnJgPlkYV04sd/6LoTofkXaLwPG04SGDLZz5RkO3M r75+vmNLTRNDtZNqyNY8ZUtDVNsOEgvfiXduAMCmY00f+Kk7VAvi2kuwVqlj40UjRBO/RcUFkUA wLSM3aGbIAMvGhptrKERManZu98eR/HLaW8MSy4TUyw1ZFHMPHMqu5XW/sVlRyVMZq07oddGGUD 5IyAWLFeK25s59fklxUjHYcSo+urB4nsD9AlKpnQjFyL7YqHSayeGbABQIyxkqAMhszgcUF+Wvb jtrJNPAFd+MVqy5DiShOfZxZ4EKaPMDf0snVznRp0Jqaz5yabTJkK5J6laL9aeZM3+QkUfUAk26 4KKrpD7c+8dTlfn X-Received: by 2002:a05:6a00:2d27:b0:82a:1337:493c with SMTP id d2e1a72fcca58-82c95e9559amr5362098b3a.14.1774684711943; Sat, 28 Mar 2026 00:58:31 -0700 (PDT) Received: from Barrys-MBP.bbrouter ([2409:8a1e:2e90:6fa0:903d:bf86:180e:c711]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca84644d9sm1448312b3a.13.2026.03.28.00.58.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Mar 2026 00:58:31 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: bhe@redhat.com, baohua@kernel.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] mm/swap: rename mm/page_io.c to mm/swap_io.c Date: Sat, 28 Mar 2026 15:58:10 +0800 Message-Id: <20260328075812.11060-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260328075812.11060-1-21cnbao@gmail.com> References: <20260328075812.11060-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Baoquan He Codes in mm/page_io.c are only related to swap io, it has nothing to do with other page io. Rename it to avoid confusion. Reviewed-by: Nhat Pham Reviewed-by: Barry Song Acked-by: Kairui Song Signed-off-by: Baoquan He Signed-off-by: Barry Song Acked-by: Chris Li --- MAINTAINERS | 2 +- mm/Makefile | 2 +- mm/swap.h | 2 +- mm/{page_io.c =3D> swap_io.c} | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) rename mm/{page_io.c =3D> swap_io.c} (99%) diff --git a/MAINTAINERS b/MAINTAINERS index 16874c32e288..bb7c1031886d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16915,7 +16915,7 @@ F: Documentation/mm/swap-table.rst F: include/linux/swap.h F: include/linux/swapfile.h F: include/linux/swapops.h -F: mm/page_io.c +F: mm/swap_io.c F: mm/swap.c F: mm/swap.h F: mm/swap_table.h diff --git a/mm/Makefile b/mm/Makefile index 8ad2ab08244e..a65ac900096a 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -75,7 +75,7 @@ ifdef CONFIG_MMU obj-$(CONFIG_ADVISE_SYSCALLS) +=3D madvise.o endif =20 -obj-$(CONFIG_SWAP) +=3D page_io.o swap_state.o swapfile.o +obj-$(CONFIG_SWAP) +=3D swap_io.o swap_state.o swapfile.o obj-$(CONFIG_ZSWAP) +=3D zswap.o obj-$(CONFIG_HAS_DMA) +=3D dmapool.o obj-$(CONFIG_HUGETLBFS) +=3D hugetlb.o hugetlb_sysfs.o hugetlb_sysctl.o diff --git a/mm/swap.h b/mm/swap.h index a77016f2423b..161185057993 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -214,7 +214,7 @@ extern void __swap_cluster_free_entries(struct swap_inf= o_struct *si, struct swap_cluster_info *ci, unsigned int ci_off, unsigned int nr_pages); =20 -/* linux/mm/page_io.c */ +/* linux/mm/swap_io.c */ int sio_pool_init(void); struct swap_iocb; void swap_read_folio(struct folio *folio, struct swap_iocb **plug); diff --git a/mm/page_io.c b/mm/swap_io.c similarity index 99% rename from mm/page_io.c rename to mm/swap_io.c index 70cea9e24d2f..91b33d955e63 100644 --- a/mm/page_io.c +++ b/mm/swap_io.c @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 /* - * linux/mm/page_io.c - * * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds * * Swap reorganised 29.12.95,=20 --=20 2.39.3 (Apple Git-146) From nobody Thu Apr 2 14:06:31 2026 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 DC089374E74 for ; Sat, 28 Mar 2026 07:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684717; cv=none; b=A1PM16re7mwfCVbpc7ZaS4oaN+4vVdGn0N4qB1fscwm3YsAreU4a9yExZL41ebsMpD3yUHsrkmGWAZ9JG8YHF00NnKYpkB8snF6wEJ0ZN7DLK7hxTfSIY81HORNE+uxfRlF/ox9gKP64AZo3RLdBfEjFVu/7qAebGqNL6jkRce0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684717; c=relaxed/simple; bh=LLlANcpebkc/yWOhqNzvV+5Er/rhh543CuOupDcj9o4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=thgv8SJ9h9YxYgvwi7dn44toW8WNfWp9akDUjBY9ZSHFnyRpbbZZNmtIF6HY4uPrp0A/vnuSffEmR4YLKxGS6q3LlWXWU2wsD8Sq455Me10+ZSDMDZUsA0JaRQaEBlZ61A5IX0+zI6wAA1ijoEhw/FMEg2WOCzvB6UoM14rGMHQ= 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=kFtZSDoC; arc=none smtp.client-ip=209.85.215.173 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="kFtZSDoC" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-c76864f4e58so638407a12.1 for ; Sat, 28 Mar 2026 00:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774684715; x=1775289515; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tv2uVA1Otfe2EI/MF1jtBSFIcG71WSWINz1C06meVug=; b=kFtZSDoC2NAQ69NfbN0KxXrIc/pBimi27RmLFE4O0GD/4Me/lbnkaZK20jt1QJH442 kgsCiwotxqO11bRtkDns+QgXK5sMoxoDeiY0ZMq4eK0b40U2Aq2Wwfh5oKebrNEAqxvr ME0R/7vIIzm9cQT4/D18MWwkmcbbgukR5MNaguAgaKti59mNZOE/3zNu+r5MPp1AEhkc 8K42q3sA0zozgtYO91KwYc+OuS6VwS7pu9BS6Zfi83//xJVQeFltKZSr85JijzR6h8o5 SPWKTbP6iAU2Xc0pMnIeVtvXlTFBm2JYzJACWUkQlwBEreWQAxeC40nuZhRqGR7dkakF 40hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774684715; x=1775289515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Tv2uVA1Otfe2EI/MF1jtBSFIcG71WSWINz1C06meVug=; b=dXeGTVxFUwmTGHfFprxqg2JiYzYEqq9RoEPv77sq4ykxrYhTC56JdExSDXRz8vy2sL gizj+uJFnh9BFStSybPhxEwsNdTaJYzKJ9br4gulU/YJf+vyv4UEB6u/GU/oY2fGocb6 Y4+dIlA34qr8iN3FbTpVU321mkil6ynP/13kxrBA6LeIKwp8OjFiijpOX4zEKravMjPr wxYWkiM6L9+kGpKhWu++72qHyGanjFJumGBCkvRAPYi6waCyQmzjeTTB+S499FVuIHlI kMMROp2n9bWElxEY9jpa+upBKS0FMnq85AYEEGSLfzoK+dj7uYv+18tgkwlUKnqUT6f1 WL5A== X-Forwarded-Encrypted: i=1; AJvYcCWVYjdNyfdHDsBi4QgUrEF87wBxsAQhPHmmppOiRNygCs+mgRyrcT3lhkNuroDTfEpmwWNbjHC4c3gwMkI=@vger.kernel.org X-Gm-Message-State: AOJu0YwpBVKBhfYAp3AeAVevR9kpEttKB2v/bxk+ODUkmv3KOJjZFBzn hrVuScCf+1krKvl34AW0/AdeDuDH+g1BQtD/tExr7pjflO1wR2CcsyP1 X-Gm-Gg: ATEYQzzaUwYMqUjWLH1HzUdSoVr4ymLqcA4crAvS7An7lVMaKBTUBXRqEyVr6Bmu2J+ GdVqYkiuqi2/L8l5vCMGvQQCm7ZWkIrecq9SCrweFUcfHMlBD3LFQnKtvzN6LMWLBAcHpJalVvy P+L6nHCDDK6HV3Q76bx5HbnR9LugZYqz3km88LuWvFgeYXbOR1tIHa7GXQ7Blh1TcR4MiTu9Zmu q8jEw9HB/E42RBZS6O6rXslCftLUaHMNmGkBrZOFszFCEoRLleeJ3Oylx0gdpdPSNEQb5ok7lo8 FCD91KIhCLO7rFCWMT6Uga09/EIsUU7x/vNLUFOFlRBqRUlqvnxzAtqJWi3RbVKUDm7TCndMSWy r890RMvjMnlVAeqfcaNWP4WHRkwbGOKUBUJibYe8uTQ+FoY34G+veZ6DbXkL0EpFbzzM+OtwzHl H7RB2aZAOM5Pt2O9Dp9mFACCIP0ZW75JrTceolBwbScyKGg23yfzZ8na/eiHcJV2qsaHvP2lQEl PtCXzmwl9yiZwol X-Received: by 2002:a05:6a20:72ab:b0:387:a311:3825 with SMTP id adf61e73a8af0-39c87b7c686mr5583794637.61.1774684714881; Sat, 28 Mar 2026 00:58:34 -0700 (PDT) Received: from Barrys-MBP.bbrouter ([2409:8a1e:2e90:6fa0:903d:bf86:180e:c711]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca84644d9sm1448312b3a.13.2026.03.28.00.58.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Mar 2026 00:58:34 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: bhe@redhat.com, baohua@kernel.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] mm/swap: use swap_ops to register swap device's methods Date: Sat, 28 Mar 2026 15:58:11 +0800 Message-Id: <20260328075812.11060-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260328075812.11060-1-21cnbao@gmail.com> References: <20260328075812.11060-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Baoquan He This simplifies codes and makes logic clearer. And also makes later any new swap device type being added easier to handle. Currently there are three types of swap devices: bdev_fs, bdev_sync and bdev_async, and only operations read_folio and write_folio are included. In the future, there could be more swap device types added and more appropriate opeations adapted into swap_ops. Suggested-by: Chris Li Signed-off-by: Baoquan He Co-developed-by: Barry Song Signed-off-by: Barry Song --- include/linux/swap.h | 2 + mm/swap.h | 10 ++++- mm/swap_io.c | 99 +++++++++++++++++++++++++------------------- mm/swapfile.c | 1 + mm/zswap.c | 3 +- 5 files changed, 70 insertions(+), 45 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 1930f81e6be4..b52f30dad72b 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -243,6 +243,7 @@ struct swap_sequential_cluster { unsigned int next[SWAP_NR_ORDERS]; /* Likely next allocation offset */ }; =20 +struct swap_ops; /* * The in-memory structure used to track swap areas. */ @@ -283,6 +284,7 @@ struct swap_info_struct { struct work_struct reclaim_work; /* reclaim worker */ struct list_head discard_clusters; /* discard clusters list */ struct plist_node avail_list; /* entry in swap_avail_head */ + const struct swap_ops *ops; }; =20 static inline swp_entry_t page_swap_entry(struct page *page) diff --git a/mm/swap.h b/mm/swap.h index 161185057993..219dbcb3ffb1 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -217,6 +217,15 @@ extern void __swap_cluster_free_entries(struct swap_in= fo_struct *si, /* linux/mm/swap_io.c */ int sio_pool_init(void); struct swap_iocb; +struct swap_ops { + void (*read_folio)(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug); + void (*write_folio)(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug); +}; +void setup_swap_ops(struct swap_info_struct *sis); void swap_read_folio(struct folio *folio, struct swap_iocb **plug); void __swap_read_unplug(struct swap_iocb *plug); static inline void swap_read_unplug(struct swap_iocb *plug) @@ -226,7 +235,6 @@ static inline void swap_read_unplug(struct swap_iocb *p= lug) } void swap_write_unplug(struct swap_iocb *sio); int swap_writeout(struct folio *folio, struct swap_iocb **swap_plug); -void __swap_writepage(struct folio *folio, struct swap_iocb **swap_plug); =20 /* linux/mm/swap_state.c */ extern struct address_space swap_space __read_mostly; diff --git a/mm/swap_io.c b/mm/swap_io.c index 91b33d955e63..ad0895af6ed8 100644 --- a/mm/swap_io.c +++ b/mm/swap_io.c @@ -238,6 +238,7 @@ static void swap_zeromap_folio_clear(struct folio *foli= o) int swap_writeout(struct folio *folio, struct swap_iocb **swap_plug) { int ret =3D 0; + struct swap_info_struct *sis =3D __swap_entry_to_info(folio->swap); =20 if (folio_free_swap(folio)) goto out_unlock; @@ -283,7 +284,8 @@ int swap_writeout(struct folio *folio, struct swap_iocb= **swap_plug) } rcu_read_unlock(); =20 - __swap_writepage(folio, swap_plug); + VM_WARN_ON_ONCE(!sis->ops || !sis->ops->write_folio); + sis->ops->write_folio(sis, folio, swap_plug); return 0; out_unlock: folio_unlock(folio); @@ -373,10 +375,11 @@ static void sio_write_complete(struct kiocb *iocb, lo= ng ret) mempool_free(sio, sio_pool); } =20 -static void swap_writepage_fs(struct folio *folio, struct swap_iocb **swap= _plug) +static void swap_writepage_fs(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **swap_plug) { struct swap_iocb *sio =3D swap_plug ? *swap_plug : NULL; - struct swap_info_struct *sis =3D __swap_entry_to_info(folio->swap); struct file *swap_file =3D sis->swap_file; loff_t pos =3D swap_dev_pos(folio->swap); =20 @@ -409,8 +412,9 @@ static void swap_writepage_fs(struct folio *folio, stru= ct swap_iocb **swap_plug) *swap_plug =3D sio; } =20 -static void swap_writepage_bdev_sync(struct folio *folio, - struct swap_info_struct *sis) +static void swap_writepage_bdev_sync(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug) { struct bio_vec bv; struct bio bio; @@ -429,8 +433,9 @@ static void swap_writepage_bdev_sync(struct folio *foli= o, __end_swap_bio_write(&bio); } =20 -static void swap_writepage_bdev_async(struct folio *folio, - struct swap_info_struct *sis) +static void swap_writepage_bdev_async(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug) { struct bio *bio; =20 @@ -446,29 +451,6 @@ static void swap_writepage_bdev_async(struct folio *fo= lio, submit_bio(bio); } =20 -void __swap_writepage(struct folio *folio, struct swap_iocb **swap_plug) -{ - struct swap_info_struct *sis =3D __swap_entry_to_info(folio->swap); - - VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio); - /* - * ->flags can be updated non-atomically, - * but that will never affect SWP_FS_OPS, so the data_race - * is safe. - */ - if (data_race(sis->flags & SWP_FS_OPS)) - swap_writepage_fs(folio, swap_plug); - /* - * ->flags can be updated non-atomically, - * but that will never affect SWP_SYNCHRONOUS_IO, so the data_race - * is safe. - */ - else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO)) - swap_writepage_bdev_sync(folio, sis); - else - swap_writepage_bdev_async(folio, sis); -} - void swap_write_unplug(struct swap_iocb *sio) { struct iov_iter from; @@ -537,9 +519,10 @@ static bool swap_read_folio_zeromap(struct folio *foli= o) return true; } =20 -static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plu= g) +static void swap_read_folio_fs(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug) { - struct swap_info_struct *sis =3D __swap_entry_to_info(folio->swap); struct swap_iocb *sio =3D NULL; loff_t pos =3D swap_dev_pos(folio->swap); =20 @@ -571,8 +554,9 @@ static void swap_read_folio_fs(struct folio *folio, str= uct swap_iocb **plug) *plug =3D sio; } =20 -static void swap_read_folio_bdev_sync(struct folio *folio, - struct swap_info_struct *sis) +static void swap_read_folio_bdev_sync(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug) { struct bio_vec bv; struct bio bio; @@ -593,8 +577,9 @@ static void swap_read_folio_bdev_sync(struct folio *fol= io, put_task_struct(current); } =20 -static void swap_read_folio_bdev_async(struct folio *folio, - struct swap_info_struct *sis) +static void swap_read_folio_bdev_async(struct swap_info_struct *sis, + struct folio *folio, + struct swap_iocb **plug) { struct bio *bio; =20 @@ -608,6 +593,39 @@ static void swap_read_folio_bdev_async(struct folio *f= olio, submit_bio(bio); } =20 +static const struct swap_ops bdev_fs_swap_ops =3D { + .read_folio =3D swap_read_folio_fs, + .write_folio =3D swap_writepage_fs, +}; + +static const struct swap_ops bdev_sync_swap_ops =3D { + .read_folio =3D swap_read_folio_bdev_sync, + .write_folio =3D swap_writepage_bdev_sync, +}; + +static const struct swap_ops bdev_async_swap_ops =3D { + .read_folio =3D swap_read_folio_bdev_async, + .write_folio =3D swap_writepage_bdev_async, +}; + +void setup_swap_ops(struct swap_info_struct *sis) +{ + /* + * ->flags can be updated non-atomically, but that will + * never affect SWP_FS_OPS, so the data_race is safe. + */ + if (data_race(sis->flags & SWP_FS_OPS)) + sis->ops =3D &bdev_fs_swap_ops; + /* + * ->flags can be updated non-atomically, but that will + * never affect SWP_SYNCHRONOUS_IO, so the data_race is safe. + */ + else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO)) + sis->ops =3D &bdev_sync_swap_ops; + else + sis->ops =3D &bdev_async_swap_ops; +} + void swap_read_folio(struct folio *folio, struct swap_iocb **plug) { struct swap_info_struct *sis =3D __swap_entry_to_info(folio->swap); @@ -642,13 +660,8 @@ void swap_read_folio(struct folio *folio, struct swap_= iocb **plug) /* We have to read from slower devices. Increase zswap protection. */ zswap_folio_swapin(folio); =20 - if (data_race(sis->flags & SWP_FS_OPS)) { - swap_read_folio_fs(folio, plug); - } else if (synchronous) { - swap_read_folio_bdev_sync(folio, sis); - } else { - swap_read_folio_bdev_async(folio, sis); - } + VM_WARN_ON_ONCE(!sis->ops || !sis->ops->read_folio); + sis->ops->read_folio(sis, folio, plug); =20 finish: if (workingset) { diff --git a/mm/swapfile.c b/mm/swapfile.c index ff315b752afd..c9eb95141c8f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3732,6 +3732,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) si->list.prio =3D -si->prio; si->avail_list.prio =3D -si->prio; si->swap_file =3D swap_file; + setup_swap_ops(si); =20 /* Sets SWP_WRITEOK, resurrect the percpu ref, expose the swap device */ enable_swap_info(si); diff --git a/mm/zswap.c b/mm/zswap.c index 4b5149173b0e..9bacb1733e1c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1054,7 +1054,8 @@ static int zswap_writeback_entry(struct zswap_entry *= entry, folio_set_reclaim(folio); =20 /* start writeback */ - __swap_writepage(folio, NULL); + VM_WARN_ON_ONCE(!sis->ops || !sis->ops->write_folio); + si->ops->write_folio(si, folio, NULL); =20 out: if (ret && ret !=3D -EEXIST) { --=20 2.39.3 (Apple Git-146) From nobody Thu Apr 2 14:06:31 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 CE75E373BE6 for ; Sat, 28 Mar 2026 07:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684720; cv=none; b=nvGBpOh57B7fguvs+CQHx0qlHV6pSWUOtX8qMysgAGjOZBESfm2g/W/9Ay86uAHSfqFHPegbCw7HycnmuCTLyB7ptcYn2QYEzzT9Ig2EQ6cl/bNqIPOFngjCbFMH9FomrSOyW0H7WFnh8wsSjB83UfTmjit/Tx6DH1onVtL/1Yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774684720; c=relaxed/simple; bh=VGYr9QL8KedU2uGP4M1/9xYgs+NqdfqvLklxyTJjkU0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z+MtFQxoCxiFzoOXmRyOUFW+DZbptdhg5211Vgkt+NtmnTTweH+1WVnLos/nQ3qL07lGFH0zDM+0iLRBgQLRFVjRuvU06oeV2t6fOUf5+gb8oOT2PfGxVmP4csYVxjGXi4q4MhaOWddMCzJjABbf1pJzeBJODm9LJ7vEFCbBMbI= 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=ao3JQYMx; arc=none smtp.client-ip=209.85.215.176 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="ao3JQYMx" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c6e2355739dso1211485a12.2 for ; Sat, 28 Mar 2026 00:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774684718; x=1775289518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VXhhgvgv1HNQy5Jtoy0WEWOi+G2ao/2SwUeB+IPvwPk=; b=ao3JQYMxWvjTows9kdHjn/0poxcODSIIa4RTPhwB3tHdsgEI7HVz6wZovvSI7HbK9d B0eYCKSSZhtg7wMq7iGPtTCbhKyCOvyoDwFfnqE3iWXIjwoyKEmba/+EanIbDeOdXjON mIDYu5lKvuZ3WCK/5gFc5zPbbLuwKxWpy83WOmxFEeBG6wSuYvnmIHOWOtEpcN4hhNPL IXmQVnIcrUemWNmECPcKJE+TxqUfOmMPxrWUV+CT3c4urkCmsMjSHiyoB3knKn2kwgB7 uu6gje2GEdxg3ITeTSh3ePjgU9C1D55i5CVTUe6ONHyC6Zat80rA/CFp7WnzXFXwvJ9V CTcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774684718; x=1775289518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VXhhgvgv1HNQy5Jtoy0WEWOi+G2ao/2SwUeB+IPvwPk=; b=Gc5U0qe/JVNIL5EGUgR+Z+SmOdcC1w2WUGCCOrDDqnzHmwSHztpQl6/7BbYiGSeWle u4Ag5N6RE4+kPlIPi8h4W70siIXr0Yoxvy3FEpZ0GMiPt/jeKUY02YK7euvjLs5Lm/Ns Lf4pLSTKhIDQb1U1uwOouA1fTznphtiHa1A3ChtuCVXfIpsIa3134gcq6vsdlNER+Nzm CX/2a2236HhKclCXxXVaOr90FHlD6LAEnQNA11S87h1VUREyH0ir6dwz2H2BxflLKGRw 1NaHxFA9NL0ZlL6zikFgEJzbMGcIwm0n7mKqtELq/orkb4r7FoTEJUjk5v/XA/gqOtiK cggw== X-Forwarded-Encrypted: i=1; AJvYcCX5jfCs7LljtND9KFnZ+VdIIeccyTi4YeG0wgaz/Vy8Q33U1DJtI2WTGt2XUTGoGuz+8GEXfPCqdifY1ak=@vger.kernel.org X-Gm-Message-State: AOJu0YyA+hfZx2T5+vtu6RHpYuFJoVWgFl8YgVu997o9UG8o/E27oEm0 9CLxm3CN0yZIpV6wnSSLhFZ+wgQiSYrKwLzfKXuxei4zyNycS4dCGMyL X-Gm-Gg: ATEYQzzq4nrYSIi0SyxrqM+9i0J3V0rDxCzgsSODxKSgaN/oU/hGtJm/F+uFWcoTE05 q9/maBkjHygZYcYzHtmk7FC1KaOjExNu1VnB/I3Z2Us3eHqBgoxf5WNeoRTRw/7uyuKX7Fhr8li 9dxym0J6umEvFuvL19PD0ppN6lyXBsr8f7s4KrUlHnks4bmUm8qamHYpQxP2GRuanYmF5Frv5qJ N1n6yewAPFHkuI4isaY7MByvsxrQFiGYtwehO6whqFMzgKJRjg3noDjwxMt6TFZFrUi3rz2nqY/ KHN5srbxgydSXCk2ns+qmoBoHXfrGFV7sVKwrDJ3rOObBQjuEZgDZibG4jECmJKVfRgCsTcg6Bv GdhEIXG8LLVud3PSCSLQDzogtfEvdPGmSlf8zXW5ZnKUupMZHPVuJgdMIFNSGKxVaOo6HpF+B+B /tqJhe/kctJ3zofQdIyGU9kKU5+UE24hzXm7u1IDhVwrHA7Pv2+lYNzP2UMEM3Qk8k330Sixh94 s2s6iy5M2brVK6p X-Received: by 2002:a05:6a20:3943:b0:39c:50b4:cd50 with SMTP id adf61e73a8af0-39c87c4adcamr5626144637.61.1774684717861; Sat, 28 Mar 2026 00:58:37 -0700 (PDT) Received: from Barrys-MBP.bbrouter ([2409:8a1e:2e90:6fa0:903d:bf86:180e:c711]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca84644d9sm1448312b3a.13.2026.03.28.00.58.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Mar 2026 00:58:37 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: bhe@redhat.com, baohua@kernel.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] mm/swap_io.c: rename swap_writepage_* to swap_write_folio_* Date: Sat, 28 Mar 2026 15:58:12 +0800 Message-Id: <20260328075812.11060-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260328075812.11060-1-21cnbao@gmail.com> References: <20260328075812.11060-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Baoquan He All these swap_writepage_* functions are hanlding passed in folio, but not page. And this renaming make them consistent with the their counterpart swap_read_folio_* functions. Reviewed-by: Barry Song Reviewed-by: Nhat Pham Signed-off-by: Baoquan He Signed-off-by: Barry Song Acked-by: Chris Li --- mm/swap_io.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/swap_io.c b/mm/swap_io.c index ad0895af6ed8..063cd005ca0d 100644 --- a/mm/swap_io.c +++ b/mm/swap_io.c @@ -375,7 +375,7 @@ static void sio_write_complete(struct kiocb *iocb, long= ret) mempool_free(sio, sio_pool); } =20 -static void swap_writepage_fs(struct swap_info_struct *sis, +static void swap_write_folio_fs(struct swap_info_struct *sis, struct folio *folio, struct swap_iocb **swap_plug) { @@ -412,7 +412,7 @@ static void swap_writepage_fs(struct swap_info_struct *= sis, *swap_plug =3D sio; } =20 -static void swap_writepage_bdev_sync(struct swap_info_struct *sis, +static void swap_write_folio_bdev_sync(struct swap_info_struct *sis, struct folio *folio, struct swap_iocb **plug) { @@ -433,7 +433,7 @@ static void swap_writepage_bdev_sync(struct swap_info_s= truct *sis, __end_swap_bio_write(&bio); } =20 -static void swap_writepage_bdev_async(struct swap_info_struct *sis, +static void swap_write_folio_bdev_async(struct swap_info_struct *sis, struct folio *folio, struct swap_iocb **plug) { @@ -595,17 +595,17 @@ static void swap_read_folio_bdev_async(struct swap_in= fo_struct *sis, =20 static const struct swap_ops bdev_fs_swap_ops =3D { .read_folio =3D swap_read_folio_fs, - .write_folio =3D swap_writepage_fs, + .write_folio =3D swap_write_folio_fs, }; =20 static const struct swap_ops bdev_sync_swap_ops =3D { .read_folio =3D swap_read_folio_bdev_sync, - .write_folio =3D swap_writepage_bdev_sync, + .write_folio =3D swap_write_folio_bdev_sync, }; =20 static const struct swap_ops bdev_async_swap_ops =3D { .read_folio =3D swap_read_folio_bdev_async, - .write_folio =3D swap_writepage_bdev_async, + .write_folio =3D swap_write_folio_bdev_async, }; =20 void setup_swap_ops(struct swap_info_struct *sis) --=20 2.39.3 (Apple Git-146)