From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796335248; b=CSyGHvACFmecPjglzwpXDqDzupL8+7KVT/G/uZNYeUOQbw2Zi7irxWMlSjzaOhN4exHy y70MUypDt8y1JibPG9FeapvIXXKA5t4J/WpsJuxr/IdA9BMElVbG5cGUJRuSrw+5oZElz YgZ4EFoX6+2RZDReZQSU7hLb/4v28T6yR/dhzRR6c40nxf6jqRL0lH6k9lCt9ZpUetQxQ 02xvG2IMPQqr9ZyvJrQHJ6iSlGRlPHEnqZYGJ+z7HvPUWz/f0qEEs7GHShENflFOZdtuW 88uun+gvOs++JDRa5x8cG6tu/Hybeu7GCrFCE5dzCMtUMg7HOE/9X9Vwb15cekZmXEA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796335248; 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=v9WQBM+L4C1aIdBGwc0+b9IXu0r5QbwGvfM9Jbxz/ek=; b=JCBXjFASTvNQES94rxiFol61IIwZKVnHac5hfl8OW72Q5JkgFoNE9N2Ou54rOI02F4Xg lNyhEY4hh7Ly8ySyd5KbVt6GZXk+Ei0TestZJGpE8Lbc8j7SrwuswpU7lelutweLaKR1F kVR72sT90yp8lPOSvaQDx46hRFhGupt/o4pYvdGxY3PmlVWqmcGOdkKTXK82QBvxxTgu2 T9RzdAA6rwP2oPFgYqc2ckoch4qyhlkSfUNlRc4on930RTi4xZgdiuQz3/1oApxoHSQ+N G0ikjgWVSLfQIHK+H4drHipfImDDHaX32WuituNBq0EZq9aI8BiYFdfrxSEhAzG8CIQ== 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=g4TYrEgz; arc=none smtp.remote-ip=74.125.224.50 Received: from mail-yx1-f50.google.com (mail-yx1-f50.google.com [74.125.224.50]) (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 A4CC2606A685 for ; Thu, 3 Dec 2026 22:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4CC2606A685 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=g4TYrEgz Received: by mail-yx1-f50.google.com with SMTP id 956f58d0204a3-67c0bd676eeso213635d50.3 for ; Thu, 03 Dec 2026 14:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796335247; x=1796940047; 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=v9WQBM+L4C1aIdBGwc0+b9IXu0r5QbwGvfM9Jbxz/ek=; b=g4TYrEgz6ZStHyI7JHmugSzYu64h93il3VWdpssUgIZoDeYmTQWfcWG/+AW0M3Ce9H mUYtv1zPPX+dCv1OXMnq6fCfz2tsqPSW/yVJMxOh+Rj36PS4+S5s4wLy1nEyKH46LxA3 XfrRDyJEH8wOjL6lMOMMqtm6uoj4+X0GuK1Yz9+hZOyM+tR5seUOH7/DbU1VAa5DPNL9 JgVIvORw3WmM5ziVWkwqEEGOPKORqyUwzuVzEt7GmBsL3kndOZiSigntOxQlGkohMWFV nQHgFoOM0d0nxCoSo+NSVXvk/boy/Zf+Y6Eum5WeUk7SsLWsD3u04MLKAFammkhmZuDZ cbHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796335247; x=1796940047; 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=v9WQBM+L4C1aIdBGwc0+b9IXu0r5QbwGvfM9Jbxz/ek=; b=ZAJXCHrm8vqOq32kkB3/0RfPXokXr9kM4O4yjb6Ef8dWo12NmPYdmi7jtnZn0/fkaM 898KfO2hcruqJVe5muQCt5uGBPGatwq1aHuSFulk7F2JmICH/HSztE7A6tz6W/RoQcrV QCVgU8uHD/8vvPVuEfO9hxVrp5R6y5u8n0Fij32Ty5WjJyZYZ9swnjMGSgbeoKv6WVWb Rr1+qFYSNEvZgOWYQuCgFnsgHlDNkHxS1WhhtnLU+ut+guq8p4gcTZYOCBTniiEFY3ew +3XFNhNTinkAPUFGAkO4g+jIyhb6DN0q/anKttd2Yb16MQ0334i1Rhn9a7ZDqgGdZWx/ ANwQ== X-Forwarded-Encrypted: i=1; AL+hErGt/w0hvHg0njmcMcj+Wz7H3GxiGy3P6dw8ziPOr+Ibn1F2h3Aev8wae8ai8+U8oEh/KK31Z0h/@vger.kernel.org X-Gm-Message-State: APuU4Z9hj+FsLL1XSUsqJ84Rl001GOzqJdqbAmmENtGZy7NpMDLT53xq aqZzHL2FOxXD/xMN1lOMFov3A+Ug8eOW2M1gNGMlQbzgzm41Di27w4Fx X-Gm-Gg: AZFdTZeDb2kGXYtWaovIncKtojad2r/IpAvup697+NetbmcpQtg08/DlFvdTEvm3BYe 60f75J1jcO5OTm4Dwynau5Rw3Js8wZ2bC95IEeYrBaZzcr7lwKADt063c6yH+6recDl2GwCVc3E QVcgH9kGxsD1yaGRWXSvfcMUq4FxWS2Dw51zUbNvsxhPxduPKkVcMu2VauXwdx2c7DOmhswobWa t/PLupg8t2vg9dymZXQunmy/Qt1gFQOFTiMzrnEASD/ypHsyhkFRxx8PDj0a6UAzzXexb4PtrLG Px7UsAfdSkE4AmIFzBuL5YG291uzXW1EFEr+4O2WhuOkKfuz2/FYnJwOUT9yFo3V+2iQUFS82QM IIucE4sI99TDOZTHdTjmjnu8JyqYyzs61D7dZ4KdOT1Eaw7SFPWQRInObfzMnQlQdpp41G3hM5A 4qEadXZqVVDK2cHEOh2eUcXpi/Lkz1u6Q6ZrtoOVazeqI6QQ5qYorsmljctYjDWPLRlA8Q5poYY cal9hI9Wch5I3dHtNYiGjq23owqPAIzj0THmISwDSoaRUyaxKvocIwLCvu0PH/0XyzN767kTw56 2tkq4CvNTxowQFJX2zPM1vRlzLGsltLrboyf1wfhUhX4loIf1X3h6i+OYWXrWXRgJ+6AAj0Pg3N D0MUHJSvuBKQj1U+2/T1ePmseDL+EWsRjcKmGBQ== X-Received: by 2002:a05:690e:4089:b0:67e:ad77:e538 with SMTP id 956f58d0204a3-67f72423437mr63575d50.67.1796335246202; Thu, 03 Dec 2026 14:00:46 -0800 (PST) Received: from localhost ([2a03:2880:10ff:5f::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67f0cd04b79sm206551d50.10.2026.12.03.14.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 14:00:45 -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 18/20] mm/zswap: store compressed entries only in the vtable Date: Thu, 3 Dec 2026 14:00:08 -0800 Message-ID: <20261203220010.1302207-19-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: cgroups@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 Vswap is mandatory and supports 32-bit systems, so the vtable supplies every zswap lookup for decompression and writeback. Remove the redundant per-device XArrays and call the virtual entry helpers directly. Signed-off-by: Nhat Pham --- Documentation/admin-guide/mm/zswap.rst | 12 +- include/linux/zswap.h | 13 -- mm/swapfile.c | 12 +- mm/zswap.c | 185 +++---------------------- 4 files changed, 28 insertions(+), 194 deletions(-) diff --git a/Documentation/admin-guide/mm/zswap.rst b/Documentation/admin-guide/mm/zswap.rst index 2464425c783d..6dbe6ed7112a 100644 --- a/Documentation/admin-guide/mm/zswap.rst +++ b/Documentation/admin-guide/mm/zswap.rst @@ -59,19 +59,15 @@ returned by the allocation routine and that handle must be mapped before being accessed. The compressed memory pool grows on demand and shrinks as compressed pages are freed. The pool is not preallocated. -When a swap page is passed from swapout to zswap, zswap maintains a mapping of -the swap entry, a combination of the swap type and swap offset, to the zsmalloc -handle that references that compressed swap page. This mapping is achieved -with an xarray per swap type. The swap offset is the search key for the xarray -nodes. +When zswap compresses a swap page, it stores the zsmalloc handle in a zswap +entry. The corresponding virtual swap slot points to that entry in its vtable. During a page fault on a PTE that is a swap entry, the swapin code calls the zswap load function to decompress the page into the page allocated by the page fault handler. -Once there are no PTEs referencing a swap page stored in zswap (i.e. the count -in the swap_map goes to 0) the swap code calls the zswap invalidate function -to free the compressed entry. +When the swap code releases the virtual swap slot, it frees any remaining +compressed entry. Zswap seeks to be simple in its policies. Sysfs attributes allow for one user controlled policy: diff --git a/include/linux/zswap.h b/include/linux/zswap.h index b90f330f87cd..08bbb567b83e 100644 --- a/include/linux/zswap.h +++ b/include/linux/zswap.h @@ -28,10 +28,7 @@ struct zswap_lruvec_state { unsigned long zswap_total_pages(void); bool zswap_store(struct folio *folio); int zswap_load(struct folio *folio); -void zswap_invalidate(int type, pgoff_t offset, unsigned long nr_entries); void zswap_entry_free(struct zswap_entry *entry); -int zswap_swapon(int type, unsigned long nr_pages); -void zswap_swapoff(int type); void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg); void zswap_lruvec_state_init(struct lruvec *lruvec); void zswap_folio_swapin(struct folio *folio); @@ -52,18 +49,8 @@ static inline int zswap_load(struct folio *folio) return -ENOENT; } -static inline void zswap_invalidate(int type, pgoff_t offset, - unsigned long nr_entries) -{ -} - static inline void zswap_entry_free(struct zswap_entry *entry) {} -static inline int zswap_swapon(int type, unsigned long nr_pages) -{ - return 0; -} -static inline void zswap_swapoff(int type) {} static inline void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) {} static inline void zswap_lruvec_state_init(struct lruvec *lruvec) {} static inline void zswap_folio_swapin(struct folio *folio) {} diff --git a/mm/swapfile.c b/mm/swapfile.c index 8f38737d8aa6..d71fccce5ae3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1603,9 +1603,6 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, unsigned long end = offset + nr_entries - 1; void (*swap_slot_free_notify)(struct block_device *, unsigned long); - if (!swap_is_vswap(si)) - zswap_invalidate(si->type, offset, nr_entries); - if (si->flags & SWP_BLKDEV) swap_slot_free_notify = si->bdev->bd_disk->fops->swap_slot_free_notify; @@ -4086,7 +4083,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) spin_unlock(&p->lock); spin_unlock(&swap_lock); arch_swap_invalidate_area(p->type); - zswap_swapoff(p->type); mutex_unlock(&swapon_mutex); kfree(p->global_cluster); p->global_cluster = NULL; @@ -4715,10 +4711,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) } } - error = zswap_swapon(si->type, maxpages); - if (error) - goto bad_swap_unlock_inode; - /* * Flush any pending IO and dirty mappings before we start using this * swap device. @@ -4727,7 +4719,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) error = inode_drain_writes(inode); if (error) { inode->i_flags &= ~S_SWAPFILE; - goto free_swap_zswap; + goto bad_swap_unlock_inode; } mutex_lock(&swapon_mutex); @@ -4761,8 +4753,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) error = 0; goto out; -free_swap_zswap: - zswap_swapoff(si->type); bad_swap_unlock_inode: inode_unlock(inode); bad_swap: diff --git a/mm/zswap.c b/mm/zswap.c index e527a34e52a8..c4fb6af8b300 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -158,12 +158,6 @@ struct crypto_acomp_ctx { struct zswap_acomp_req decomp; /* unused with on-stack requests */ }; -/* - * The lock ordering is zswap_tree.lock -> zswap_pool.lru_lock. - * The only case where lru_lock is not acquired while holding tree.lock is - * when a zswap_entry is taken off the lru for writeback, in that case it - * needs to be verified that it's still valid in the tree. - */ struct zswap_pool { struct zs_pool *zs_pool; struct crypto_acomp_ctx __percpu *acomp_ctx; @@ -185,7 +179,11 @@ struct zswap_pool { static DEFINE_XARRAY_FLAGS(zswap_pools, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH); static struct zswap_pool __rcu *zswap_current_pool; -/* Global LRU lists shared by all zswap pools. */ +/* + * Global LRU lists shared by all zswap pools. Releasing an entry from the + * vtable takes the cluster lock before the LRU lock. Writeback drops the + * LRU lock before revalidating the entry under the cluster lock. + */ static struct list_lru zswap_list_lru; /* The lock protects zswap_next_shrink updates. */ @@ -200,7 +198,7 @@ static struct shrinker *zswap_shrinker; * This structure contains the metadata for tracking a single compressed * page within zswap. * - * swpentry - associated swap entry, the offset indexes into the xarray + * swpentry - virtual swap entry whose vtable slot holds this zswap entry * length - the length in bytes of the compressed page data. Needed during * decompression. * referenced - true if the entry recently entered the zswap pool. Unset by the @@ -232,9 +230,6 @@ static struct zswap_pool *zswap_entry_pool(struct zswap_entry *entry) return xa_load(&zswap_pools, entry->pool_idx); } -static struct xarray *zswap_trees[MAX_SWAPFILES]; -static unsigned int nr_zswap_trees[MAX_SWAPFILES]; - /* pool counter to provide unique names to zsmalloc */ static atomic_t zswap_pools_count = ATOMIC_INIT(0); @@ -256,39 +251,6 @@ static bool zswap_has_pool; * helpers and fwd declarations **********************************/ -/* One swap address space for each 64M swap space */ -#define ZSWAP_ADDRESS_SPACE_SHIFT 14 -#define ZSWAP_ADDRESS_SPACE_PAGES (1 << ZSWAP_ADDRESS_SPACE_SHIFT) - -static inline struct xarray *zswap_tree(int type, pgoff_t offset) -{ - return &zswap_trees[type][offset >> ZSWAP_ADDRESS_SPACE_SHIFT]; -} - -static inline struct xarray *swap_zswap_tree(swp_entry_t swp) -{ - return zswap_tree(swp_type(swp), swp_offset(swp)); -} - -static struct zswap_entry *zswap_entry_load(swp_entry_t swp) -{ - if (is_vswap_entry(swp)) - return vswap_zswap_load(swp); - return xa_load(swap_zswap_tree(swp), swp_offset(swp)); -} - -static struct zswap_entry *zswap_entry_store(swp_entry_t swp, - struct zswap_entry *entry) -{ - if (is_vswap_entry(swp)) { - vswap_zswap_store(swp, entry); - return NULL; - } - - return xa_store(swap_zswap_tree(swp), swp_offset(swp), entry, - GFP_KERNEL); -} - #define zswap_pool_debug(msg, p) \ pr_debug("%s pool %s\n", msg, (p)->tfm_name) @@ -1138,7 +1100,7 @@ static int zswap_writeback_entry(struct swap_io_ctx *ctx, * old compressed data. Only when this is successful can the entry * be dereferenced. */ - if (entry != zswap_entry_load(swpentry)) { + if (entry != vswap_zswap_load(swpentry)) { ret = -ENOMEM; goto err; } @@ -1264,8 +1226,7 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o * * 1. We extract the swp_entry_t to the stack, allowing * zswap_writeback_entry() to pin the swap entry and - * then validate the zswap entry against that swap entry's - * tree using pointer value comparison. Only when that + * then validate the pointer against the vtable slot. Only when that * is successful can the entry be dereferenced. * * 2. Usually, objects are taken off the LRU for reclaim. In @@ -1288,7 +1249,7 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o /* * Once the lru lock is dropped, the entry might get freed. The * swpentry is copied to the stack, and entry isn't deref'd again - * until the entry is verified to still be alive in the tree. + * until writeback verifies it against the vtable. */ swpentry = entry->swpentry; @@ -1588,7 +1549,7 @@ static bool zswap_store_page(struct folio *folio, long index, struct zswap_pool *pool) { swp_entry_t page_swpentry = folio_swap_entry(folio, index); - struct zswap_entry *entry, *old; + struct zswap_entry *entry; /* allocate entry */ entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); @@ -1607,29 +1568,14 @@ static bool zswap_store_page(struct folio *folio, long index, */ entry->pool_idx = pool->idx; - old = zswap_entry_store(page_swpentry, entry); - if (xa_is_err(old)) { - int err = xa_err(old); - - WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); - zswap_reject_alloc_fail++; - goto store_failed; - } + vswap_zswap_store(page_swpentry, entry); /* - * We may have had an existing entry that became stale when - * the folio was redirtied and now the new version is being - * swapped out. Get rid of the old. - */ - if (old) - zswap_entry_free(old); - - /* - * The entry is successfully compressed and stored in the tree, there is + * The entry is successfully compressed and stored, so there is * no further possibility of failure. Grab refs to the pool and objcg, * charge zswap memory, and increment zswap_stored_pages. * The opposite actions will be performed by zswap_entry_free() - * when the entry is removed from the tree. + * when the entry is removed from the vtable. */ zswap_pool_get(pool); if (objcg) { @@ -1641,7 +1587,7 @@ static bool zswap_store_page(struct folio *folio, long index, atomic_long_inc(&zswap_stored_incompressible_pages); /* - * We finish initializing the entry while it's already in xarray. + * We finish initializing the entry while it's already in the vtable. * This is safe because: * * 1. Concurrent stores and invalidations are excluded by folio lock. @@ -1658,8 +1604,6 @@ static bool zswap_store_page(struct folio *folio, long index, return true; -store_failed: - zs_free(pool->zs_pool, &entry->handle); compress_failed: zswap_entry_cache_free(entry); return false; @@ -1668,7 +1612,6 @@ static bool zswap_store_page(struct folio *folio, long index, bool zswap_store(struct folio *folio) { long nr_pages = folio_nr_pages(folio); - swp_entry_t swp = folio->swap; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; struct zswap_pool *pool; @@ -1730,17 +1673,10 @@ bool zswap_store(struct folio *folio) return ret; /* - * If the zswap store fails or zswap is disabled, we must invalidate - * the possibly stale entries which were previously stored at the - * offsets corresponding to each page of the folio. Otherwise, - * writeback could overwrite the new data in the swapfile. + * Drop any entries installed before a partial store failed. */ - if (is_vswap_entry(swp)) { - if (index > 0) - folio_release_non_phys_swap_backing(folio); - } else { - zswap_invalidate(swp_type(swp), swp_offset(swp), nr_pages); - } + if (index > 0) + folio_release_non_phys_swap_backing(folio); return ret; } @@ -1756,32 +1692,15 @@ bool zswap_store(struct folio *folio) */ bool zswap_is_present(swp_entry_t entry, unsigned int nr) { - pgoff_t offset = swp_offset(entry); - struct xarray *tree; - unsigned long index = offset; unsigned int i; - /* Virtual entries have no native zswap tree. */ - if (is_vswap_entry(entry)) { - for (i = 0; i < nr; i++) - if (vswap_zswap_load(swp_entry(swp_type(entry), offset + i))) - return true; - return false; + for (i = 0; i < nr; i++) { + if (vswap_zswap_load(entry)) + return true; + entry.val++; } - tree = swap_zswap_tree(entry); - - if (zswap_never_enabled() || xa_empty(tree)) - return false; - /* - * A pinned range is at most SWAPFILE_CLUSTER slots and is aligned to - * its own size, so one tree covers all of it and a single lookup is - * enough. Scanning only part of the range would report a false - * "absent" and let the caller read a stale copy from the device. - */ - BUILD_BUG_ON(SWAPFILE_CLUSTER > ZSWAP_ADDRESS_SPACE_PAGES); - - return xa_find(tree, &index, offset + nr - 1, XA_PRESENT); + return false; } /** @@ -1817,7 +1736,7 @@ int zswap_load(struct folio *folio) if (folio_test_large(folio)) return -ENOENT; - entry = zswap_entry_load(swp); + entry = vswap_zswap_load(swp); if (!entry) return -ENOENT; @@ -1847,64 +1766,6 @@ int zswap_load(struct folio *folio) return 0; } -void zswap_invalidate(int type, pgoff_t offset, unsigned long nr_entries) -{ - struct zswap_entry *entry; - struct xarray *tree; - unsigned long i; - - if (zswap_never_enabled()) - return; - - for (i = 0; i < nr_entries; i++) { - tree = zswap_tree(type, offset + i); - - if (xa_empty(tree)) - continue; - - entry = xa_erase(tree, offset + i); - if (entry) - zswap_entry_free(entry); - } -} - -int zswap_swapon(int type, unsigned long nr_pages) -{ - struct xarray *trees, *tree; - unsigned int nr, i; - - nr = DIV_ROUND_UP(nr_pages, ZSWAP_ADDRESS_SPACE_PAGES); - trees = kvzalloc_objs(*tree, nr); - if (!trees) { - pr_err("alloc failed, zswap disabled for swap type %d\n", type); - return -ENOMEM; - } - - for (i = 0; i < nr; i++) - xa_init(trees + i); - - nr_zswap_trees[type] = nr; - zswap_trees[type] = trees; - return 0; -} - -void zswap_swapoff(int type) -{ - struct xarray *trees = zswap_trees[type]; - unsigned int i; - - if (!trees) - return; - - /* try_to_unuse() invalidated all the entries already */ - for (i = 0; i < nr_zswap_trees[type]; i++) - WARN_ON_ONCE(!xa_empty(trees + i)); - - kvfree(trees); - nr_zswap_trees[type] = 0; - zswap_trees[type] = NULL; -} - /********************************* * debugfs functions **********************************/ -- 2.53.1-Meta