Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1981692rdb; Wed, 31 Jan 2024 15:43:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpadWRVn/rtOBFPrACOyNLdxndGpt1q61PIIszd1YAEQUHudOIhrpeyidNaZM73Rtn1Yy0 X-Received: by 2002:ac2:504c:0:b0:50e:ca97:5afb with SMTP id a12-20020ac2504c000000b0050eca975afbmr458187lfm.18.1706744592834; Wed, 31 Jan 2024 15:43:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706744592; cv=pass; d=google.com; s=arc-20160816; b=sD/9qs81X5s5d7JwtXcCsNsziNt1bAPfxXOWdFzGwKfsBcBLXq8HQW+Oz15E8yJdzS VMB2K6bLQjFhH0ZiRprr22hOvdkZzdFbRh85S9GUfyu/UNt6AP4IgOcqlSiCqQ5bedaM O6rsQOxvFk22ket3oUvL8m0V44yGSMKxBd0rRU8nEfBFq+DWkrwEzu3jEyAnPgrqyOv7 hFyxuRNNdaMDqxegEJG/pPivBPWFqXM6Y9/F4MaLqLl6lXZ5c3E3H/O9CozaxrCMRQGZ fCbHme77teOgBi9kpqWcL8HwrVm0YVDVUX7fZbOb0yh/thmgc5sNSG2V4sEurmIdmS72 GkPw== 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=yWCIz5tRPDvVMbwlPXUHT60/hM3Jv0lhzZccM6cVE4Y=; fh=5k7orqt9Lphj5NHlNWV3LGRWd1vWevlPxuvsM5iEPSU=; b=ferYAAvEA2bmyguRR89SeWDTCDJL/j7x218AabOB/yLIqV8iTTPShzj2x2QaTu+6fc HZ3d5RKcaYbigfuM11TnW90Eez+/Mt4UiPj6qqkUUWZwqPj+Xjv8pUthI80vcrmUWG/p +q6YT4U8TKX3vX3JUVwY9Kl/a/2jTv37m/Vjl+isupN0mbXf1KADQPsyjxExB8hj9oK4 jZVmWim/Ww8gR6FtxE10nbTdMJkkqcX0+LrVm7UTgBxnNocXFKHG48nVu8ObMlL4q9YQ tIRNuSxWYJCJ2ueuW/vtLY2YDfj9zVHmqjTNC+XAxWDAaAcqbBga9xm3UzNpkzfz5HKQ Ht2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QATPpItI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47387-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUp0wmb5LkSvzclRDzZ55KhbXub49hBY8DCiNA9Gz+qem9Yg0CK+Da5xNxTfkpaAmByX/jnYk2bgCzUX8YInvIMwRwdGQYuM5aY86q1Hg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h25-20020a1709063b5900b00a36ba77ab7asi73040ejf.471.2024.01.31.15.43.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:43:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QATPpItI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47387-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47387-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8B16A1F20F16 for ; Wed, 31 Jan 2024 23:43:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BCD13B7AA; Wed, 31 Jan 2024 23:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QATPpItI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B9AD53B785 for ; Wed, 31 Jan 2024 23:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744295; cv=none; b=bgsin4Bmiax0EhKdmpe3feDrKQKsGya96qJiEdqoLGtASRDDOTvwD0sNKve0J1xb60NZjew1hCNCJI9aAoqWqfs2tigNDeHSURoYWePcB2W270YtX8tOTtZzdfgu9FW8seAhhex+F7rMwDemeF/vfR3TtyYFaVQl3ee03KGZZ44= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744295; c=relaxed/simple; bh=6WEOBZD8BEPfYQSuPkRb9qFLZYglJJhBpRxM4e7iLD0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Yys7OUGh1wUFHOz6nDumLYDHJh7NJ7ZLLruHyFh+aafJZXp87G1XT3uQCdhY1D0EJqNGQsiO1uuVrod1vZG8RM5KCqugTPCRatoamR697ODaTmSkayJyEkGJ0vwZARVEWDHr4fhrzjCV+18gB6U0Ws41GAQ+hZH1N/Jyw2AnZOM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QATPpItI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CB10C433C7 for ; Wed, 31 Jan 2024 23:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706744295; bh=6WEOBZD8BEPfYQSuPkRb9qFLZYglJJhBpRxM4e7iLD0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QATPpItIWBSTebzG8b5hlHSthvcoig7hoxvezVOI8IdMJeR98lIGKaIUoZiF7F6JN 2OrvhTRfEwP1Dd88fWA2rHp/vtTR3jS3aYT9aJU802ew7sYNXn9SIHyPx6heHH60eP K84d8lEXsniPWcGef6rIKtWRpcGZ/vjApURVNAYgKKG388MunSJYXc29g478lCjMYZ FezMa+jisWrrbBOgd10K/jGnplcXTk2+BOKruPCtDsB88mVT0Jev+QKGBcUin4WIjE BL7aAsJE4U8HgGlaJAlBCLW80I2pyHKphrfdukPrmZ9DmczomOruO7wXTw2lRWZ1yV 9wIRoOmqQxG+Q== Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-363793e88abso1579685ab.1 for ; Wed, 31 Jan 2024 15:38:15 -0800 (PST) X-Gm-Message-State: AOJu0YwP0ldOQ05N08HuRW7PVyqCwy6zLgFW7MsoZ1485juAN2RLJuMj aLk9LgSC3hU7nAwGZIQiyGSz0bU1EQajRliuo54qludKy4lmUdMZgnrwoLT10rBdvTuupjCPYT1 LSPW07ju93WzkX3FrsyOvZOWUiQxNePey4Ixg X-Received: by 2002:a92:d190:0:b0:363:9665:1a64 with SMTP id z16-20020a92d190000000b0036396651a64mr841907ilz.10.1706744294562; Wed, 31 Jan 2024 15:38:14 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240129175423.1987-1-ryncsn@gmail.com> <20240129175423.1987-7-ryncsn@gmail.com> <87bk92gqpx.fsf_-_@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87bk92gqpx.fsf_-_@yhuang6-desk2.ccr.corp.intel.com> From: Chris Li Date: Wed, 31 Jan 2024 15:38:02 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Whether is the race for SWP_SYNCHRONOUS_IO possible? (was Re: [PATCH v3 6/7] mm/swap, shmem: use unified swapin helper for shmem) To: "Huang, Ying" Cc: Minchan Kim , Kairui Song , linux-mm@kvack.org, Kairui Song , Andrew Morton , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org, Yu Zhao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 30, 2024 at 6:53=E2=80=AFPM Huang, Ying = wrote: > > Hi, Minchan, > > When I review the patchset from Kairui, I checked the code to skip swap > cache in do_swap_page() for swap device with SWP_SYNCHRONOUS_IO. Is the > following race possible? Where a page is swapped out to a swap device > with SWP_SYNCHRONOUS_IO and the swap count is 1. Then 2 threads of the > process runs on CPU0 and CPU1 as below. CPU0 is running do_swap_page(). > > CPU0 CPU1 > ---- ---- > swap_cache_get_folio() > check sync io and swap count > alloc folio > swap_readpage() > folio_lock_or_retry() > swap in the swap entry > write page > swap out to same swap entry > pte_offset_map_lock() > check pte_same() > swap_free() <-- new content lost! > set_pte_at() <-- stale page! > folio_unlock() > pte_unmap_unlock() Yes, that path looks possible but hard to hit due to the requirement of swap in and swap out in a short window. I have the similar question on the previous zswap rb tree to xarray discussion regarding deleting an entry where the entry might change due to swap in then swap out. Chris