From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796335225; b=bK0sJzDVfY4yPhBu86ycPSJzkkIOX80pFgu2whagv5FyXXHKM+MODvdXfd2QbG1jaLZx Z5gPe24Myd+YaFp7M6dyEb+gm7gXZanrzWpTeguyDTlJo8xFS2JsB6KcykKMPMXYiTMW8 ZmV07Pap4KMN9pX0dU7V6K0AS59Y62L/Cf11bbpGGX2sP34IBGpbCtqAseNnrtwbnOA4V Bwf8Dfwy8vtLwTLtWPbbGuf4Lm47laiX2PyOp+oIkgtXQa9mKzLebhQZEqkuetzTkxhq2 DNl6OxDPT1WwY4OV+7fo/Fl5J7ZGMIaSFvcmYQcMDGulWcpVZh0leHppkUH7C5FECNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796335225; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=EcI0k9l+i0RrB5mb15Me4TNV7F2nbc4miUVUIy4Sn3A=; b=eqmDsn8zh8guJ6RN4/CvA6Hdqv0Uobrv6XHPcCb4G5nhfML2p440XOuMOni7moyuVSEB R4q7ormgCRCpPWfAXRhWt5Pj0vIECEXe8lUhcacP6CfRlnF+UrvmAZ3rBQ8f/lk9Y8zjv jv3Q8zf5AAju4qyiW8yPJferZUylGnCrfzATV5W3TcnabiTQO8HiH+Eos5xlJpeRzk2UG uGnUbX0lZ82wKAp3lVF6Ezb8sTzSCMQkPkcDjNIY0DpNP4ewFzHbN953YwImLM7fWObDa BoTJGiblMre8dgpNAwPBZcdC8NzBrRWJP6pn5TKxh1PsY8mNKy+v97hVgyVjZ2c/MCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ncRhRlOS; arc=none smtp.remote-ip=209.85.128.169 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F237606A689 for ; Thu, 3 Dec 2026 22:00:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3F237606A689 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.a=rsa-sha256 header.s=20260707 header.b=ncRhRlOS Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-8b4fb5d96b3so5348697b3.1 for ; Thu, 03 Dec 2026 14:00:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796335223; x=1796940023; 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:content-type; bh=EcI0k9l+i0RrB5mb15Me4TNV7F2nbc4miUVUIy4Sn3A=; b=ncRhRlOSs5XggyTglJczarPWhHgxYYbV2EjhaATv6iL0NB07L578segSxNB7UR0g7Y 3tugeHxs+/oII0NDumiH8BBoNnCtM8y+N/Q9qDdnioFZimBVYwiZDYy7HC5KphGehIXy f8wnkoY89Uj5lOuWZq8mfuDK/y3znaJ7aj7lu7cUwCOZoFOwkf7L6o0VPJV7JypEjso7 RGEardJ/gXONCtcU5ryxmmepUNz429LKzsSWXZLCZB4PM7qvKjC29t0byWaKaneC3sDg 79hT7KSwF5X8PoySpBjGFRjUB9cu8M/Cf9qygrAIL+tNTe/4NkAnAu+9nzjfOZYnXYBr 0x7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796335223; x=1796940023; 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:content-type; bh=EcI0k9l+i0RrB5mb15Me4TNV7F2nbc4miUVUIy4Sn3A=; b=YWgSXbu3rOhP4LSfk+s24HezRRgipqKtoZFSkV45HbpqAqUUqmiqm2tmErEyQqBnX9 yQ8gtPO0YXQorm6mzDLdXaOmkhyLcQxz4ToJhU8jrTlu7RbpchnoBB40aLK5DkhSOslj Aqfl+RjhdgOnEbbfa731FVCeWumKH1eubrEM864BjL2n7167nytnNHM0dz/jgZbPvTRL lcDihbEttKEJwHf95XtwhbNlnvooGjMAgWr88Tzpq7N7OzhTG+nFIQrX1v+CTt0QXbt/ S1tNnM/xYh7PSZ3ssbNjshjoxMd8tqoOQgD17fkZc7TDJ7IF99JbfspIYOvee/JhBFYh GJBQ== X-Forwarded-Encrypted: i=1; AL+hErGoDEot1y4Qj2IP0Zw9NEG+j7lfRYTSebbnKKGyQz8KdrYVCsE5rjH0QrB+yR+WhnkMm68CWiBn5dA=@vger.kernel.org X-Gm-Message-State: APuU4Z89h8e//LlVb3N9g22/xxePqHmdZlIJAWXJle++z/1ZLkrbTGNC 8n8jcHFXx8bQ2UKv9/ptTtfhXq0+XY+0lB75uinKFyGzqARLM5cUaH0I X-Gm-Gg: AZFdTZf5bfBnrm2jXaZwBC8/CJIlpPqaWXTfG90qMjv7MHOZfLPN8yi4dbTkhnJigG+ dMAQdfhXdZ2kvstluD10QEkKvzx5muWP6Vwn3P1DP1eBjBEJGE+rz7FGa6BBvXmsxdZVUwyFdtx pSce7i2UbOtmuoZ1hBoKpwIfZg/9tbbgPMGuoayIn0n9EGre170TWxsICp5/C2/3qPlVqeRR3rl AC6TP2UvzXRO8XPVMkO4e99Gb/w4o1T/JvjmLXo3eo0OF4Wns9jzPStVAqXGobQBdL56ElPzGHm 4JHEcReKDfxWQRrmVSq7YAFennKTHNF1e9m27z06rZWqqGhKfBZQAYyTZ34YIHgU5l7GqgcXZjg zTtZzDjan+K/dUoDt4mxq1t+vNrXRpKiPR3Twms1jVfcbWCivYWlIyRniF0VnRmZf4w0duXosXj ijc5MV3U4w2ITNQZtpfSyqFYEU+OlEiUkq4Sw3k8uJVXZ7SzSFM+n5Zzu+YsTkdBD0SOmXoRpls BPZ5YQpfx9ALLass9jQyn8rjFl0loQRn+4cEWO9bNeZeH5JQ3rR5A/8OTG7iCk9IhRimU2qnxnW /ZFZUKhcNVqw8EURkhqSR9Ol+huCG+0D/TuLLZElpHdNQ4XeYthbPMeRRhT/61yEdrqxOVeS8Ru lblOeFufTHuXTyfiG68BiH1zsCqkFkDSJ1gko X-Received: by 2002:a05:690c:288:b0:8b5:4dbe:283b with SMTP id 00721157ae682-8b5f596ef09mr17776017b3.4.1796335223004; Thu, 03 Dec 2026 14:00:23 -0800 (PST) Received: from localhost ([2a03:2880:10ff:1::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b66086625dsm1054747b3.14.2026.12.03.14.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 14:00:22 -0800 (PST) From: Nhat Pham To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Baoquan He , Barry Song , Youngjun Park , Johannes Weiner , Yosry Ahmed , Chengming Zhou , Qi Zheng , Shakeel Butt , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baolin Wang , Michal Hocko , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Hugh Dickins , Jonathan Corbet , Shuah Khan , Randy Dunlap , Roman Gushchin , Muchun Song , Arnd Bergmann , Karl Mehltretter , Dapeng Mi , Marco Elver , Ethan Nelson-Moore , "Borislav Petkov (AMD)" , Jeff Layton , linux-doc@vger.kernel.org, cgroups@vger.kernel.org, Tejun Heo , =?UTF-8?q?Michal=20Koutn=C3=BD?= Subject: [PATCH v7 06/20] mm/swap: resolve physical backing for reads and device flags Date: Thu, 3 Dec 2026 13:59:56 -0800 Message-ID: <20261203220010.1302207-7-nphamcs@gmail.com> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261203220010.1302207-1-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A virtual entry does not identify the device that holds its disk data. Add physical-entry encoding and lookup to the vtable, and use the lookup for reads, synchronous I/O, stable writes and filesystem-reclaim checks. Prepare these readers before writeout can install physical backing. They must resolve the physical device when the physical backend starts writing virtual folios to disk. Direct physical entries retain their existing device selection. Signed-off-by: Nhat Pham --- mm/memory.c | 15 ++-- mm/page_io.c | 21 +++++- mm/swapfile.c | 2 +- mm/vmscan.c | 23 +++++-- mm/vswap.h | 184 +++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 228 insertions(+), 17 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 9ba6ebd58132..3eb1841530bb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4754,8 +4754,11 @@ static inline bool should_try_to_free_swap(struct swap_info_struct *si, { if (!folio_test_swapcache(folio)) return false; - /* A vswap entry holds no physical slot, so keeping it saves no IO. */ - if (is_vswap_entry(folio->swap)) + /* + * Non-swapfile backends cannot be reused for future swapouts. + * Free the swap slot unless backed by contiguous physical swap. + */ + if (!folio_phys_swap_backed(folio)) return true; /* * Always try to free swap cache for SWP_SYNCHRONOUS_IO devices. Swap @@ -4763,7 +4766,7 @@ static inline bool should_try_to_free_swap(struct swap_info_struct *si, * are fast, and meanwhile, swap cache pinning the slot deferring the * release of metadata or fragmentation is a more critical issue. */ - if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) + if (swap_entry_backend_has_flag(si, folio->swap, SWP_SYNCHRONOUS_IO)) return true; if (mem_cgroup_swap_full(folio) || (vma->vm_flags & VM_LOCKED) || folio_test_mlocked(folio)) @@ -5109,7 +5112,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) swap_update_readahead(folio, vma, vmf->address); if (!folio) { /* Swapin bypasses readahead for SWP_SYNCHRONOUS_IO devices and zswap */ - if (swap_entry_synchronous(si, entry)) + if (swap_entry_synchronous(si, entry) || + (is_vswap_entry(entry) && + swap_entry_backend_has_flag(si, entry, SWP_SYNCHRONOUS_IO))) folio = swapin_sync(entry, GFP_HIGHUSER_MOVABLE, thp_swapin_suitable_orders(si, vmf) | BIT(0), vmf, NULL, 0); @@ -5268,7 +5273,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) */ exclusive = true; } else if (exclusive && folio_test_writeback(folio) && - data_race(si->flags & SWP_STABLE_WRITES)) { + swap_entry_backend_has_flag(si, entry, SWP_STABLE_WRITES)) { /* * This is tricky: not all swap backends support * concurrent page modifications while under writeback. diff --git a/mm/page_io.c b/mm/page_io.c index 9397ef83a60d..956c3ffc1039 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -493,17 +493,32 @@ void swap_read_folio(struct swap_io_ctx *ctx, struct folio *folio) struct swap_info_struct *sis = __swap_entry_to_info(folio->swap); bool synchronous = sis->flags & SWP_SYNCHRONOUS_IO; bool workingset = folio_test_workingset(folio); + swp_entry_t phys; VM_BUG_ON_FOLIO(!folio_test_swapcache(folio) && !synchronous, folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_uptodate(folio), folio); + /* + * Resolve the physical slot to read from. A vswap entry keeps + * folio->swap virtual, so map it to its physical backing; a folio with + * no backing has nothing to read. + */ + if (swap_is_vswap(sis)) { + phys = vswap_to_phys(folio->swap); + if (phys.val) + synchronous = __swap_entry_to_info(phys)->flags & + SWP_SYNCHRONOUS_IO; + } else { + phys = folio->swap; + } + /* * A batch this folio can't join is submitted before the pressure * window opens, so that each batch is billed for its own read * rather than for the next folio's lookup and decompression. */ - if (ctx->sio && !swap_can_merge(ctx, folio, folio->swap, READ)) + if (ctx->sio && (!phys.val || !swap_can_merge(ctx, folio, phys, READ))) swap_read_submit(ctx); /* @@ -532,14 +547,14 @@ void swap_read_folio(struct swap_io_ctx *ctx, struct folio *folio) if (zswap_load(folio) != -ENOENT) return; - if (unlikely(swap_is_vswap(sis))) { + if (!phys.val) { folio_unlock(folio); return; } /* We have to read from slower devices. Increase zswap protection. */ zswap_folio_swapin(folio); - swap_add_folio(ctx, folio, folio->swap, READ); + swap_add_folio(ctx, folio, phys, READ); /* * Synchronous devices do the whole read at submission time, submit diff --git a/mm/swapfile.c b/mm/swapfile.c index fa315389399b..d9e8c9365c44 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -247,7 +247,7 @@ static int __try_to_reclaim_swap(struct swap_info_struct *si, need_reclaim = ((flags & TTRS_ANYWAY) || ((flags & TTRS_UNMAPPED) && !folio_mapped(folio)) || ((flags & TTRS_FULL) && mem_cgroup_swap_full(folio) && - !is_vswap_entry(folio->swap))); + folio_phys_swap_backed(folio))); if (!need_reclaim || !folio_swapcache_freeable(folio)) goto out_unlock; diff --git a/mm/vmscan.c b/mm/vmscan.c index 3ad66f2a16d8..5bf20b57fe45 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -70,6 +70,7 @@ #include "memory-failure.h" #include "page_alloc.h" #include "swap.h" +#include "vswap.h" #define CREATE_TRACE_POINTS #include "trace_vmscan.h" @@ -1029,17 +1030,26 @@ static unsigned int demote_folio_list(struct list_head *demote_folios, static bool may_enter_fs(struct folio *folio, gfp_t gfp_mask) { + swp_entry_t entry; + if (gfp_mask & __GFP_FS) return true; /* * We can "enter_fs" for swap-cache with only __GFP_IO unless backed by * a swapfile that requires GFP_NOFS I/O. */ - if (folio_test_swapcache(folio) && (gfp_mask & __GFP_IO) && - !(__swap_entry_to_info(folio->swap)->ops->flags & - SWAP_OPS_F_REQUIRE_NOFS)) - return true; - return false; + if (!folio_test_swapcache(folio) || !(gfp_mask & __GFP_IO)) + return false; + + entry = folio->swap; + if (is_vswap_entry(entry)) { + entry = vswap_to_phys(entry); + if (!entry.val) + return true; + } + + return !(__swap_entry_to_info(entry)->ops->flags & + SWAP_OPS_F_REQUIRE_NOFS); } /* @@ -1583,7 +1593,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, activate_locked: /* Not a candidate for swapping, so reclaim swap space. */ if (folio_test_swapcache(folio) && - (mem_cgroup_swap_full(folio) || folio_test_mlocked(folio))) + ((mem_cgroup_swap_full(folio) && folio_phys_swap_backed(folio)) || + folio_test_mlocked(folio))) folio_free_swap(folio); VM_BUG_ON_FOLIO(folio_test_active(folio), folio); if (!folio_test_mlocked(folio)) { diff --git a/mm/vswap.h b/mm/vswap.h index f64b1543e01f..c4f0670c9b5c 100644 --- a/mm/vswap.h +++ b/mm/vswap.h @@ -19,6 +19,7 @@ struct zswap_entry; enum vswap_backing_type { VSWAP_NONE = 0, VSWAP_ZSWAP = 1, + VSWAP_SWAPFILE = 2, VSWAP_ZERO, VSWAP_FOLIO, }; @@ -41,8 +42,13 @@ static inline bool is_vswap_entry(swp_entry_t entry) /* * Virtual table entry encoding for vswap clusters. * - * Zero represents no separate backing. An aligned zswap pointer - * has bit 0 clear and is stored directly in the vtable. + * The architecture-independent swp_entry_t leaves its top bit unused. + * Shift the entry left by one to leave bit 0 free as the physical tag. + * Aligned zswap_entry pointers already have bit 0 clear. + * + * NONE: |------ 0 -------|0| + * ZSWAP: |-- zswap_entry pointer --| + * SWAPFILE: |-- swp_entry_t -|1| * * vtable[i] = NONE does not by itself mean "free". The swap_table entry * and the per-slot zero flag carry the rest of the state. The full @@ -56,6 +62,8 @@ static inline bool is_vswap_entry(swp_entry_t entry) * NONE | * | set | zero-backed; cached if PFN set * ZSWAP | PFN | clear | folio cached + zswap entry * ZSWAP | shadow / NULL | clear | evicted, only in zswap + * SWAPFILE | PFN | clear | folio cached + physical slot + * SWAPFILE | shadow / NULL | clear | evicted, only on the swapfile * * Locking: the caller must own and lock the slot's swapcache folio to * stabilize its backing. The cluster lock only makes individual vtable @@ -75,9 +83,17 @@ static inline bool is_vswap_entry(swp_entry_t entry) static inline enum vswap_backing_type vtable_type(unsigned long vt) { + if (vt & VTABLE_TAG_MASK) + return VSWAP_SWAPFILE; return vt ? VSWAP_ZSWAP : VSWAP_NONE; } +static inline swp_entry_t vtable_to_phys(unsigned long vt) +{ + VM_WARN_ON(vtable_type(vt) != VSWAP_SWAPFILE); + return (swp_entry_t){ .val = vt >> VTABLE_TAG_BITS }; +} + static inline struct zswap_entry *vtable_to_zswap(unsigned long vt) { VM_WARN_ON(vtable_type(vt) != VSWAP_ZSWAP); @@ -119,6 +135,33 @@ vswap_lock_cluster(swp_entry_t entry, unsigned int *voff) return container_of(ci, struct swap_cluster_info_dynamic, ci); } +/** + * vswap_to_phys - resolve a vswap entry's physical swap backing + * @entry: the virtual swap entry + * + * Context: takes and drops the vswap cluster lock internally. + * Return: the backing physical swp_entry_t, or the null entry (.val == 0) + * when @entry has no physical backing (NONE/ZSWAP/ZERO). + */ +static inline swp_entry_t vswap_to_phys(swp_entry_t entry) +{ + struct swap_cluster_info_dynamic *ci_dyn; + unsigned int voff; + unsigned long vt; + + ci_dyn = vswap_lock_cluster(entry, &voff); + if (!ci_dyn) + return (swp_entry_t){}; + + vt = __vtable_get(ci_dyn, voff); + swap_cluster_unlock(&ci_dyn->ci); + + if (vtable_type(vt) != VSWAP_SWAPFILE) + return (swp_entry_t){}; + + return vtable_to_phys(vt); +} + void __vswap_release_backing(struct swap_cluster_info *ci, unsigned int ci_start, unsigned int nr); @@ -170,6 +213,102 @@ static inline struct zswap_entry *vswap_zswap_load(swp_entry_t entry) void folio_release_vswap_backing(struct folio *folio); +/* + * Walk nr vtable slots starting at voff in ci_dyn. Returns the prefix + * length of slots sharing one effective backing type. For SWAPFILE, + * the prefix is also restricted to contiguous offsets in the same + * swapfile. + * + * Effective type per slot: + * vtable=NONE + zero flag set -> VSWAP_ZERO + * vtable=NONE + swap_table PFN tag -> VSWAP_FOLIO + * vtable=NONE + neither -> VSWAP_NONE + * vtable=SWAPFILE -> VSWAP_SWAPFILE + * vtable=ZSWAP -> VSWAP_ZSWAP + * + * *typep returns the effective type of slot 0. Caller holds + * ci_dyn->ci.lock. + */ +static inline int __vswap_check_backing(struct swap_cluster_info_dynamic *ci_dyn, + unsigned int voff, int nr, + enum vswap_backing_type *typep) +{ + enum vswap_backing_type first_type = VSWAP_NONE; + enum vswap_backing_type slot_type; + swp_entry_t first_phys = {}; + unsigned long vt, swap_tb; + int i; + + lockdep_assert_held(&ci_dyn->ci.lock); + + for (i = 0; i < nr; i++) { + vt = __vtable_get(ci_dyn, voff + i); + if (vtable_type(vt) == VSWAP_NONE) { + swap_tb = __swap_table_get(&ci_dyn->ci, voff + i); + if (__swap_table_test_zero(&ci_dyn->ci, voff + i)) + slot_type = VSWAP_ZERO; + else if (swp_tb_is_folio(swap_tb)) + slot_type = VSWAP_FOLIO; + else + slot_type = VSWAP_NONE; + } else { + slot_type = vtable_type(vt); + } + + if (!i) { + first_type = slot_type; + if (first_type == VSWAP_SWAPFILE) + first_phys = vtable_to_phys(vt); + } else if (slot_type != first_type) { + break; + } else if (first_type == VSWAP_SWAPFILE && + vtable_to_phys(vt).val != first_phys.val + i) { + break; + } + } + + if (typep) + *typep = first_type; + return i; +} + +static inline int vswap_check_backing(swp_entry_t entry, int nr, + enum vswap_backing_type *typep) +{ + struct swap_cluster_info_dynamic *ci_dyn; + unsigned int voff; + int ret; + + ci_dyn = vswap_lock_cluster(entry, &voff); + if (!ci_dyn) { + if (typep) + *typep = VSWAP_NONE; + return 0; + } + ret = __vswap_check_backing(ci_dyn, voff, nr, typep); + swap_cluster_unlock(&ci_dyn->ci); + return ret; +} + +/** + * folio_phys_swap_backed - test whether a folio is backed by a contiguous + * range of physical swap slots. + * @folio: a swap-cache resident folio + * + * Return: %true if @folio->swap is not a vswap entry, or if these vswap + * entries are backed by a contiguous range of physical slots. + */ +static inline bool folio_phys_swap_backed(struct folio *folio) +{ + swp_entry_t entry = folio->swap; + int nr = folio_nr_pages(folio); + enum vswap_backing_type type; + + return !is_vswap_entry(entry) || + (vswap_check_backing(entry, nr, &type) == nr && + type == VSWAP_SWAPFILE); +} + static inline int vswap_cluster_alloc_vtable(struct swap_cluster_info_dynamic *ci_dyn, gfp_t gfp) { @@ -199,6 +338,47 @@ static inline bool is_vswap_entry(swp_entry_t entry) return false; } +static inline swp_entry_t vswap_to_phys(swp_entry_t entry) +{ + return (swp_entry_t){}; +} + +static inline bool folio_phys_swap_backed(struct folio *folio) +{ + return true; +} + #endif /* CONFIG_SWAP */ +/* + * Test a per-backend swap flag (SWP_SYNCHRONOUS_IO, SWP_STABLE_WRITES, ...) + * for @entry. For a vswap entry the property belongs to the current + * physical backing rather than vswap_si itself; resolve to the backing + * and test there. Returns false for zswap/zero/unbacked vswap entries + * as they don't have a backing bdev. + */ +static inline bool swap_entry_backend_has_flag(struct swap_info_struct *si, + swp_entry_t entry, + unsigned long flag) +{ + struct swap_info_struct *phys_si; + swp_entry_t phys; + bool has_flag; + + if (!swap_is_vswap(si)) + return data_race(si->flags & flag); + + phys = vswap_to_phys(entry); + if (!phys.val) + return false; + + phys_si = get_swap_device(phys); + if (IS_ERR_OR_NULL(phys_si)) + return false; + + has_flag = data_race(phys_si->flags & flag); + put_swap_device(phys_si); + return has_flag; +} + #endif /* _MM_VSWAP_H */ -- 2.53.1-Meta