From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 50667319871 for ; Tue, 7 Jul 2026 08:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783412848; cv=none; b=X2qpi5CnnBKcuLyW1TaYbUM2H1k8Ns4Y85M3jziGyj7aoh9tkLuzMqyAubqMVOnGdq10K2rJftlA8HKt3EHCf9XayMn60oW+Y2Ku0a5aJ5UMMxzLMPJ2BtroDwAGRJGEWxozHgwyeNLQ8Bh+188eCD0FfVBd1LjQ8INkpGT9jss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783412848; c=relaxed/simple; bh=MqpA2z4u5A6GJ9qmDb2h06Wb9r3BxRmKFbubizxEJRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=acrzzs+W2esfMzDjexA2uJ1ozE7unTW7xVGKJvpVyLLaep/wWZ89kEQpOch5QjDKaGVosscV3fSTxfkd/Y2Fc2cFlk7nGyUoSVSYBb/FPHvL/oq5NQ6Hyuf0cuGDxMKAnlUIn0yXuy1GKGWH7WNTshaWaY3iIDyLKinuHMkvaVg= 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=YVTrCYc1; arc=none smtp.client-ip=91.218.175.183 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="YVTrCYc1" 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=1783412845; 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=xV6i/G5pvlleZ0L2NE10sfLpZZEgkyaYGlgJlwxedI0=; b=YVTrCYc1lk6biMb7/w3lGOo9ySjGlkCD96RgvbGRfxiWzBgO1Ut3rtMJofaE7o5gakhUkL HSCh/0bijy5lD28vCiOnxnR6cYkN9ZN8rKnitcM2mp6/cdmjYXLO8KMIM6a3XxSVr12wTW aAXhK3h22QY7XfE0HQLbHZHirouHW9U= 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 07/10] mm/page_io: forward ghost swap reads to physical device via Redirect Date: Tue, 7 Jul 2026 16:26:09 +0800 Message-ID: <20260707082614.95030-8-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 When swap_read_folio() encounters a ghost swap entry (SWP_GHOST), check if there is a Redirect mapping to a physical swap slot via ghost_redirect_to_phys(). If a physical backing exists, forward the I/O to that device: 1. Query the redirect_xa / swap table for the physical swp_entry_t. 2. Temporarily redirect folio->swap to the physical entry so the existing swap_read_folio_bdev_{sync,async} / swap_read_folio_fs path computes the correct sector from the physical offset. 3. Restore folio->swap to the original ghost entry after I/O. This completes the backend-switching round trip: - Swapout: PTE -> ghost entry -> zswap_store -> Pointer(zswap_entry) - Writeback: Pointer -> decompress -> write to phys -> Redirect(phys) - Swapin: PTE -> ghost entry -> Redirect -> read from phys device Signed-off-by: Baoquan He --- mm/page_io.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/page_io.c b/mm/page_io.c index 96e776f9a503..b87b46f05b2f 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -697,6 +697,39 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug, void *zentry) goto finish; if (unlikely(sis->flags & SWP_GHOST)) { + swp_entry_t phys_entry; + struct swap_info_struct *phys_si; + + /* + * Ghost swap entry: check if there's a Redirect to a + * physical swap slot. If so, read from the physical + * device instead. + */ + phys_entry = ghost_redirect_to_phys(sis, swp_offset(folio->swap)); + if (phys_entry.val) { + phys_si = __swap_entry_to_info(phys_entry); + if (phys_si && phys_si->bdev) { + swp_entry_t saved = folio->swap; + + /* + * Temporarily point the folio to the + * physical entry so the bdev read path + * computes the correct sector. + */ + folio->swap = phys_entry; + zswap_folio_swapin(folio); + if (data_race(phys_si->flags & SWP_FS_OPS)) + swap_read_folio_fs(folio, plug); + else if (phys_si->flags & SWP_SYNCHRONOUS_IO) + swap_read_folio_bdev_sync(folio, + phys_si); + else + swap_read_folio_bdev_async(folio, + phys_si); + folio->swap = saved; + goto finish; + } + } folio_unlock(folio); goto finish; } -- 2.54.0