From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E47F2EA47C for ; Tue, 7 Jul 2026 08:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783412811; cv=none; b=NDFWQPGFUj+VNfpFaw30fmuHJEIGmA8QR2+mHIrK5ivjpehFugZ2EjH4AIUAdeYQDPMlTEK+0HHXyI9lxNLrcHIPE+mXO9miemhQQ8KMbVZhL0brs69jUuXFRFuMwdkdGC2pUiM/ll9VCpkK6UZ2VoLSF1EnK5l0VS80js7kF8Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783412811; c=relaxed/simple; bh=YaObGmVK6sRg1DVjWJ7yVLnHOmtvStKnAwdYTFE5Jeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=FqHvQClqbkCiKV+eDDA0P62QBj9OKNqWv4NgMajwDymkIg6cE3K1Cq8ewLOKF1kTEUlmnOrywLWWr077Q58nzPWGGobsONv117SaN/kFti0HHLIlq8YjzVDaINrTwGaxgABWBmD0ekT7VzHjgOo5odwuTudsz+Q2rUFOroylARk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=iF90jdy1; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="iF90jdy1" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783412807; h=from:from: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:in-reply-to:references:references; bh=3hKIIEJl3WKu1bJOCbl82x7ScTc+umlVXZysFmiodbQ=; b=iF90jdy1nuou2/+Rjg4M6C5f7Xwi/rloSo2iIH6pAgdG87gXAeL+1C22Ka8hAuEVsABf+A OTZTbQCEdUXa/lnGF7nHydqtnd0QekToPdz27udDdEK9m/Kfh9uVcRTpIKP+cJhHvsSZZu s/74lM60TfXtTv7oPfC7Hv9UEgqgnEw= From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, hannes@cmpxchg.org, yosry@kernel.org, chengming.zhou@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [RFC PATCH 03/10] mm/swap: add redirect_xa field and ghost redirect helper declarations Date: Tue, 7 Jul 2026 16:26:05 +0800 Message-ID: <20260707082614.95030-4-baoquan.he@linux.dev> In-Reply-To: <20260707082614.95030-1-baoquan.he@linux.dev> References: <20260707082614.95030-1-baoquan.he@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add a 'struct xarray redirect_xa' to swap_info_struct (guarded by CONFIG_ZSWAP) to persist ghost_offset -> phys_swp_entry_t mappings across swap-cache PFN cycles. Declare the ghost redirect helper functions in mm/swap.h. All are no-ops when CONFIG_ZSWAP=n. Signed-off-by: Baoquan He --- include/linux/swap.h | 3 +++ mm/swap.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 9829a31a541e..a4d6851e0921 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -277,6 +277,9 @@ 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 */ +#ifdef CONFIG_ZSWAP + struct xarray redirect_xa; /* ghost offset → phys swp_entry_t */ +#endif }; static inline swp_entry_t page_swap_entry(struct page *page) diff --git a/mm/swap.h b/mm/swap.h index 2d29e41d3323..bc51ee5dbf51 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -287,6 +287,20 @@ void swap_write_unplug(struct swap_iocb *sio); int swap_writeout(struct folio *folio, struct swap_iocb **swap_plug); int __swap_writepage(struct folio *folio, struct swap_iocb **swap_plug); +/* Ghost swapfile redirect helpers (mm/swapfile.c) */ +#ifdef CONFIG_ZSWAP +swp_entry_t ghost_redirect_to_phys(struct swap_info_struct *si, + pgoff_t offset); +swp_entry_t alloc_phys_swap_slot(void); +void free_phys_swap_slot(swp_entry_t phys_entry); +#else +static inline swp_entry_t ghost_redirect_to_phys(struct swap_info_struct *si, + pgoff_t offset) +{ return (swp_entry_t){}; } +static inline swp_entry_t alloc_phys_swap_slot(void) { return (swp_entry_t){}; } +static inline void free_phys_swap_slot(swp_entry_t phys_entry) {} +#endif + /* linux/mm/swap_state.c */ extern struct address_space swap_space __read_mostly; static inline struct address_space *swap_address_space(swp_entry_t entry) -- 2.54.0