Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1424380lqp; Fri, 22 Mar 2024 14:42:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxycDUt8w20ytO/OgA2HSS85lDTkuFvLX6nTNQTf66wan8SOe4yuKfhGJQ6mBtA5VwY2nsawOs9vpXM8zRzUvI3R9XpcUm4ALS+q9eOA== X-Google-Smtp-Source: AGHT+IEMGkaJY3uZedKJ/jBQctmyA83HUiXbczrTwhPb81yOQ/wbuuZ+Ph/udSaOxBTbpeTz0q5l X-Received: by 2002:a05:6a00:4607:b0:6e7:8047:96f0 with SMTP id ko7-20020a056a00460700b006e7804796f0mr1006017pfb.28.1711143750712; Fri, 22 Mar 2024 14:42:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711143750; cv=pass; d=google.com; s=arc-20160816; b=W+Md3tbHE+DxwM18bvBwW9Wq8ye/tuh4/UQ0Cn+9eFwWWIfKO9Vhm0VynWQEDTT9eM FkiYTKJP+NCNeXFOAqgUFPN0h330ys3SGNUrCZygvyAjg0e9qhmp57cSrJXcP0KD67aj mHtkkbig57E/M59U59eTyG8hcpFgMKo8L3irPkWchbmi/Z+tFDWWbpdNEH3KwovLHz74 vsOcpyboREXvFvWbUlRgc7R1ID4lHOwaKiqni2LWIQsfePDTCa0ik7/jarVVSy4jL1UH NWmwgLW2I+VeBn8W5+fIA9TKtlaanjS2S3IIRliOvw6RRJY87i7OHgkCeytaKC/ueSgA LHzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=RQll5QYZhzufGj+S1fYXa+jgiDZDq7VQ1QzparuV7Ek=; fh=UGV/mOZML74TuT9ukievr+uZTLHGhpH5oXiyM75yXOY=; b=0ksNn5kmQNg+SGjDwZz1GpIM3WttTe5RDunTDy416Pd+XL6N1YEGukkQ6HEr2nZGgO uY2xbBANOVJ+xmGRablStVL1b3ic4nEduYGJMC799zp/3bMcHnKHqyqqhBXBp3Z6JRIO TR00lm8xxHdPqa59gtUuv95znztVDrPFLHq8b/dCahEV6rjMMr4kPbUQuCdpUNpbr2kB 7wj/4bc4xSJhPuVYL50NwOxYtyTjr6gWqy5jfogthCph2ptfSn+eoofAzMwUzcl1Mi22 b8Ja8TsyKpfwm63k2EvGUx9MW6y4Z3Y2zdRlo1BpcHZiAKmstwmni9ZF4Rh/htYZZJi8 0/6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZJyq42aI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k17-20020aa78211000000b006e68943a381si357461pfi.233.2024.03.22.14.42.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 14:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZJyq42aI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 06D1CB222D2 for ; Fri, 22 Mar 2024 21:42:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63CBB80629; Fri, 22 Mar 2024 21:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZJyq42aI" Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2136F81205 for ; Fri, 22 Mar 2024 21:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711143711; cv=none; b=Jx+Kc/cWu30G6Y7uX2JP0NLZgSEOQZIBeCmjqvPOP5NZ0cwUCsHY2id2QWAcWKM+6CYr92+ZcYpu58oXxj31zH0753o8sqtRUBZDNWA8E4SM9vPakkHtsnp9dEbHQZi0innKI6F3B6ZNQjpu6os5JvT6fRwkZDVt9ujHiYdbdrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711143711; c=relaxed/simple; bh=RQll5QYZhzufGj+S1fYXa+jgiDZDq7VQ1QzparuV7Ek=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DOkFER/scrGPrFu5PnVXr4061Rk3fm2bHI0h9mL+lpmlvn7VYx3UQxiNUFeZ4EJbBmZF9DzIsOIlnhSBep0WVoJedwv7XlNkDfYlNtqzFq8l0x9cD9ISlIVxSPa24aXLowE4nLnH9//45tGQ9uUC9e7Bz0sOBeQSNaMqu0ATGlA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZJyq42aI; arc=none smtp.client-ip=209.85.222.50 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 Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-7e08498aa43so1094916241.3 for ; Fri, 22 Mar 2024 14:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711143709; x=1711748509; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RQll5QYZhzufGj+S1fYXa+jgiDZDq7VQ1QzparuV7Ek=; b=ZJyq42aI3gZcW2/lT6byH3r/SIXhrwPHi5NoWFtuzSGzjHwQ4CNsoWY4aVst6lFiAh Tbvv1uObWy+KfOFV67E/g4tGWuLPfYDL7vvYvrS34JYyrF+cljMxrzLLknR3FaJZ8mZx bBiTOmQfwkFCWdIutvPZJHfzGA6QqarQ7thee032fHHZ8fF9XGbQFurwhZLUN9MIP2zM /VOavZelr/X9sCUkh+I6ZTc/tKE4U74oZzltbEuxAJ9KrXamhJjDzGHyHikHBGkDDWwf D0NJ3ycpkhFDB/mhtrnk4+246Vz7nCZVCCG5YKpuYB/UhPWR9BaKR37QNUVbyBmam7z4 JNiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711143709; x=1711748509; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RQll5QYZhzufGj+S1fYXa+jgiDZDq7VQ1QzparuV7Ek=; b=WsKmusJjPdz9FlfFiod9QB1VQvGc3vf7QGR3t4PXlHimSWgbLX1MDvniogDsrUy2lf F7Oy972CvbqyrRlW+eri7R8Ga6RewBo2HDnxUJD9MhA8aT6Dsdu3mcRYx9y5qrEHyinC 4ZYJuS/JbhmL0QpdoWLkj+15yZ5T31nPHd/kIth8yld5vvn4wSRds6kL5CeERN8lNiac XEzAc1XUD/l2UghG46hkpMKzGvSKlIX7eo7BNYTRGoN8/eJb/OHaEzJCAPr46Xoo2Q0v gQjPl/dbyksG978eGPHCRJwHRV103Xhi2BoSJ/QM/6cB50ACim5eIlbZfdVf9oLWpfqV A9zQ== X-Forwarded-Encrypted: i=1; AJvYcCWp/+UtTYVUBY7SYS4v0HUf29R8aeWL6FK5CjKywW3+a2aZ9WqjX6+xurVesglMRfphXvvIgn/bi2OoI5E7c2zjKsD5en67ULER7iK1 X-Gm-Message-State: AOJu0YxZleg50bhJvjMnjFYm16edjOwctj047MBFn9oaUm3mPjNboCbY KfXxKq0rd5qw9xOYlKR+qrGWbJdeRcHf7Mwcy9M/OHWhKDDhYiF6PHovKCug/5B02rs1CStXJpj RL0OFu44m5iI8yQr70+18l59P9vc= X-Received: by 2002:a05:6102:f0d:b0:473:2d91:c4d5 with SMTP id v13-20020a0561020f0d00b004732d91c4d5mr988952vss.25.1711143704130; Fri, 22 Mar 2024 14:41:44 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240322163939.17846-1-chengming.zhou@linux.dev> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Sat, 23 Mar 2024 10:41:32 +1300 Message-ID: Subject: Re: [RFC PATCH] mm: add folio in swapcache if swapin from zswap To: Yosry Ahmed Cc: chengming.zhou@linux.dev, hannes@cmpxchg.org, nphamcs@gmail.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Mar 23, 2024 at 8:38=E2=80=AFAM Yosry Ahmed = wrote: > > On Fri, Mar 22, 2024 at 9:40=E2=80=AFAM wrote: > > > > From: Chengming Zhou > > > > There is a report of data corruption caused by double swapin, which is > > only possible in the skip swapcache path on SWP_SYNCHRONOUS_IO backends= . > > > > The root cause is that zswap is not like other "normal" swap backends, > > it won't keep the copy of data after the first time of swapin. So if I don't quite understand this, so once we load a page from zswap, zswap will free it even though do_swap_page might not set it to PTE? shouldn't zswap free the memory after notify_free just like zram? > > the folio in the first time of swapin can't be installed in the pagetab= le > > successfully and we just free it directly. Then in the second time of > > swapin, we can't find anything in zswap and read wrong data from swapfi= le, > > so this data corruption problem happened. > > > > We can fix it by always adding the folio into swapcache if we know the > > pinned swap entry can be found in zswap, so it won't get freed even tho= ugh > > it can't be installed successfully in the first time of swapin. > > A concurrent faulting thread could have already checked the swapcache > before we add the folio to it, right? In this case, that thread will > go ahead and call swap_read_folio() anyway. > > Also, I suspect the zswap lookup might hurt performance. Would it be > better to add the folio back to zswap upon failure? This should be > detectable by checking if the folio is dirty as I mentioned in the bug > report thread. I don't like the idea either as sync-io is the fast path for zram etc. or, can we use the way of zram to free compressed data? >