Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1365966lqp; Fri, 22 Mar 2024 12:38:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrFc9JPE5MVwVpz5MrHwOf7eOT1DxtmSrvXwRVPQV68qnZtLMS4njXUvoRqwPljMq6t5ZtrkNoARyLpAcOAs1Mpi/64BhGL47Y0aWaUQ== X-Google-Smtp-Source: AGHT+IHyEAUKhnEugvfs+QMLEYK9NYKy5RbsvLTRb+aBjswSVbWnsbpJ76wKDciKaD0LAZjnhvwd X-Received: by 2002:a05:6870:569e:b0:221:a43d:60ef with SMTP id p30-20020a056870569e00b00221a43d60efmr904256oao.3.1711136291743; Fri, 22 Mar 2024 12:38:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711136291; cv=pass; d=google.com; s=arc-20160816; b=pj00eltvQyAfrUZJTQw+4Btd8uxTpf6CuWBXXSYI1ww/ZuHwWDU3AY99o5HZyKK5HM 5PDh9iWZLyy34z8EzWGbwoBYew/esoIpfsUnv9x82dCBo984o38ajjF25WtJdsNHis8T 7l5CwpPS1TlEOdgoVkuIzByRE/UESbTxbKDJkQr7d93jlrUfQi3MLERephcCkqmPdkz3 LYPtv4pGKmzXBL4Q291ar7f5fgstBVgwjchDRjQjIORqD3zzOo2lh5C6o5A6Abmv72Aw UipePFXCLDqBIg59IvUCG5j956vQmAMR87DboVvSM4Z1r9+nrMfFC1MH4DcHPeecSt54 SRRA== 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=Xdakqsi/D2JKyIKkGYWtlGPF0xjppXCKwXZBXILelig=; fh=skI4n6f0ltA2QRuSr8+Jms9rSAo9hCytyD/O4hxZyz8=; b=XPp0H4iLZOovh5zym8kPnir8QFPtyi1y+HrIAh3GPwj4fKDyITSNBXlNkQ9qfnZZU3 y+/uIOuqhxiStEioRZaIJSIqpmR5ftTjzMehDeaWquDG8GaQqFDVlDZFNbo1OF28alW6 Dq/aHVwTHcTeQYx6TFwgvMNOxCaHAxXeUChw2dFfe5U2wztx5wbe+XEaBe5SLlfpkjTA CkCMBFCu0mvqFzQS+bN53gKvB/TQdCAky6ZZ3SHN6qLLec68votxC+5XZgx6YbaOeutM ix8mFjCkT9e39qrsgvKVnlbGofg5LJSqRG7DIPQIOW8I5uZ1yYwx5FwgWbaBr/U3yM0+ 0Xhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H1fcSheb; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-112001-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112001-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w10-20020a63d74a000000b005dcbb9cf3a4si2654199pgi.129.2024.03.22.12.38.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 12:38:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112001-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H1fcSheb; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-112001-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112001-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 02151283B4F for ; Fri, 22 Mar 2024 19:38:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4258E7BAE6; Fri, 22 Mar 2024 19:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="H1fcSheb" Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 CCB651E514 for ; Fri, 22 Mar 2024 19:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711136287; cv=none; b=CjbJz73Ym7iIkaDdqeROxAKtnQOWIxzSvs/qdC8l8HOwwinVNZ1VqhwauAHE4iHi4XuoXzZjDk+Q53Oz/KVfqK1FjPgaNpBbw6G8ERcs8l6ZUPjatlwfVLpj25tL+lSSW7yQDNFOeb9XYnvGPxHa7DfNEATPVfDUQvfBPn+o0lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711136287; c=relaxed/simple; bh=Xdakqsi/D2JKyIKkGYWtlGPF0xjppXCKwXZBXILelig=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mRxi4H+ACa9f0+b30pJqptFji1EX2OLHYXxG2QEa/w+BSaRobNlz/RPvZvesdCyiOWWrf5npYiQt4CBX6SyKNsqd6EYr60BlDA4QWwNjMbnMWS++nrrmPnzPgcVy4hy48YNpX2VI75Ap+NW1Mxh7PfxGs3aO5KnQOUcl3tLYWo0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=H1fcSheb; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a472f8c6a55so133957966b.0 for ; Fri, 22 Mar 2024 12:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711136284; x=1711741084; 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=Xdakqsi/D2JKyIKkGYWtlGPF0xjppXCKwXZBXILelig=; b=H1fcSheb3nQCegSXsagopNkAVqrcdKpxNhxBC5PfmlsoCvR9UKWWAmJ81uzjHfnfW1 5Cz3bqw+ScwzCLrlbJdCbbovdY2QhY8GZINMAD/+XjEtJnAYCbSVO9NRn2Ebrsff/PG6 zkgr+KmaHUxKSjye87tGdTI6MnnJv4XwQVE/q132N7M4ZnjpimrwL5yGyGrujAnqN5LI OJLlXG0XpPq1k7iQPuSv8D47TNJzKNR6U55XVjmq8WKPX0gY8iD8sjPajhOr1Y926XEE RtnlE0qZgSBu58z79ibXlI6eJlmzpZtunomzG/UlPhudUNZpe0B0kL5W089RBsAYWy0C osaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711136284; x=1711741084; 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=Xdakqsi/D2JKyIKkGYWtlGPF0xjppXCKwXZBXILelig=; b=Ubc0pcqbYD921SM+MS9+uZaCDV4kuZQOE8K9gHAKu+QmDs5IJqQw1apuP5AjcjhPvC 3wpJX4s5vEQRABv6X/JLa1OiCoDf24gF/vITAkNRusv3BJleMXD8G5UVbdhVwJH2N2cC LprepNRhMarg9kpAdipYCxqchDl+Hjo3uXPOSF9se8HULw4GoWMXZfiAEMHZJoBMSlDE 2fir8j2K+inveCOuuqDmOk3OC6yecQBegq4nt6v7S6z2lvXNEzARTYFydV6JlyMFn7yC FEMQ+zfZbJbriaOGbKuQP+GDQ/Gp1hUsc1TR6qiocvze4gJleUU9dcQu8Ozw5jMMNNeK vpEg== X-Forwarded-Encrypted: i=1; AJvYcCVQ5VxMmvr4ooh8ryjI9vddyog06tKNq0vXvb7IC0QiT5L94AZDTxl+6JZSXzmsfOIRry7H8ymjL5w6O70sya92+L7JqmEgVu0ehZfK X-Gm-Message-State: AOJu0Yx6SvPSs4TEnkPzKtVtZv2qqGqDsuW8HpdVGmyU11YAGSaM+h17 ojTU14kwzXZA6HxX11Au+0+q7IT5bVqWWmcnbFGnWm5glCHtA9uKSs1BUiI+2E+iFQChrVZCySc j4FCmHw/3wM/mOcPACue1BUlOYGN+P/6Sv9V1 X-Received: by 2002:a17:906:ac7:b0:a47:2333:80b9 with SMTP id z7-20020a1709060ac700b00a47233380b9mr504939ejf.47.1711136283960; Fri, 22 Mar 2024 12:38:03 -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: <20240322163939.17846-1-chengming.zhou@linux.dev> From: Yosry Ahmed Date: Fri, 22 Mar 2024 12:37:27 -0700 Message-ID: Subject: Re: [RFC PATCH] mm: add folio in swapcache if swapin from zswap To: chengming.zhou@linux.dev Cc: 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 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 > the folio in the first time of swapin can't be installed in the pagetable > 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 swapfile= , > 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 thoug= h > 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.