From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796335248; b=XFf+AWxQCMdAJe9FZWIVkPPKI3ETmRbQKmGfrfMLATMuSUIvfaRjJ7T2+K7nBbntA1Rx tpUP4wkkLXYVZSiZ0MoZIcsR6+oxyqi4kL+s4jfra5da1sGQpN8Zed1hMOB5n5Swj/wDf HHaGXXrQYa0kATgGR1rnW2gPk8KOvHRm8SnVo7Ttfe9j8msJCYEgZc1nSnljNd4Pc36z3 Yqn1uaA/PraS9b03bGk1FY61GQDEI9QFqQmEiEj/2t1n9fgpVjUty7/tNidHfpqdTc7pX eDrFUY+F3v5i5EjAzW05DlvbS4YwgV15d5pQpHZI8lsBCeQcOqjzoo0K69UfC7UogkQ== 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=BFyKrTjl/ml2ETvm1ar3cHqQVueayVCYMi+aalIIS3XovK3T8UHWTFWtAmBisGysjMdI WG7go6I+wxZCCdOsCn5o0zAjsF78i5dstDbBDEBmoWtx/7zPH90cNU9nt4M+KKRu5ralk CKl65Tttfv2maDDTIEVygOjD+8NwORJwcHPziMXdzQIgpaJWb2b5ES4tsSigBoaU9vMRH lqAdEd1Gb0zCySLWZxBLlwe78O/MiGTc4SpOR+3BjN4EJDiSKXNk5gqPoayJ/GR7Ftnzt i80d3L6JrWoUQhP55SOv+Kaz+tYE1vX9ZADWl8b2/Dl7LB91hjUWFx9IIV35vJ6wufw== 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.43 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (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 9525C606A33E for ; Thu, 3 Dec 2026 22:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9525C606A33E 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-f43.google.com with SMTP id 956f58d0204a3-67df3b1ca06so278006d50.2 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=tS3JkpT8O9evVArDkdseQ756leLlVd9AnBKi1SwSs9m6qscffrfSkZng7wvI/G4d3H v5hh3ZGBCOzQjFqfHJb7IjZ+KYAADx7AgGWOZkm4Cb62XCSIipCUGLh1k3JwUupRQFYy Vc4DRWn2Dwk+X4CuZ2HdiTVdBj6wg57gzH7EUmjzZGMeYR6ELpVL+rdYml39/m7edEv+ J4rTWSOh28lZYsJnlEOWifalFG32SeQye2VY5ONLRjqbOYOy6Otpfo9Pb8w7N3zGMoAN A295ikwC2h1U4UWygtUGGptiXTSUGP/GylxYWkNRQ1T01zQ6WlnyXvyw7xXthACJ0Vaq LDPw== X-Forwarded-Encrypted: i=1; AL+hErFnV1aS/BWS2b166YFRo7BLTY4B2vqdRLMTnA8PwZqjpgeWtMkhe62tzv5Qstrju6MO8JLenuC0Fog=@vger.kernel.org X-Gm-Message-State: APuU4Z/lZnVz3dyUiqdMLFDRQovk3JpgSiEIOjjA4g1ya8lP43wNs5AN IJtv7xs6UE+DVoyfhA4xFkXf+LhmUqDRXBxoGLK/wPkRbKXBxRuwhL1z X-Gm-Gg: AZFdTZfUPFSs4a8WA4wB/N/uE6y5P0yoLSw2a2G7o9rkoJV2zZyXODYMlbT+Km3eKLc 0a4+rIztLdXynYB8HV9PWFMlPJoFTMvjwZcDK4hXqmeJo6WRTe85fNzNge09sfRlDqUXrl0S/r3 amVGidHHQ7ma7a5yd6oQZYi8xS5khwaWrwVsLcAXVjPBUdIk9ku9ZWWEPK5d/fWq8WSf1DDawoq ADYpeJc8NXvYwXC92VzaK0NpRHDMeuaKDmoC6oKRcSlv9pVlSoTYB1lDsyUS482UnP9N5ovbjtY dJKDm7lAIUdLx5ck1jttWrScHnbQc6vR4TVkBa7+XfDKmUQp16fPkSmIJgHEjzKgRllRTXLczRR GbvfRGGSHjDe32tRQTm2D9YZuDsfwwYXgmv5/Z/t4VpjRQ5enIN/J1fw5CMFxUN1MecjTix/0Ut VZxReQKpDvJmL/BwnKqxYllH29tcJ5KKCGlg6NHdW5f2vDq2qqDdvOqHhD+4CdGw8OJGNqqZ0rv 6B1ADxdsVOIvc+19j6t5mQnVxyriEsT/WE2vULMl5EY4RlhdfWCNpSQNWc1UCxvmfFGSTLsLEI9 tNiNeWLUID16DWzD+y/pSiyJZxLdTcf6aMJBS2SJ+Lsi/PXz2l5o9AkaNpEdaJFdoh1jjVVLl9a LDP2fjWGo4gDTsugJWbvD13M8k1o63w6iiPmnww== 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: 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 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