From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87317C48BC4 for ; Thu, 15 Feb 2024 20:55:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF12A6B009D; Thu, 15 Feb 2024 15:55:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA0CE8D0001; Thu, 15 Feb 2024 15:55:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D685C6B009F; Thu, 15 Feb 2024 15:55:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C57E56B009D for ; Thu, 15 Feb 2024 15:55:17 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9A2E6A0AEB for ; Thu, 15 Feb 2024 20:55:17 +0000 (UTC) X-FDA: 81795243474.07.D8CD792 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf30.hostedemail.com (Postfix) with ESMTP id A42DA80017 for ; Thu, 15 Feb 2024 20:55:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CtxWYsTw; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf30.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708030515; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r7KeUmQ5rtQIKjg5bbnS3xkReICqYXg+NK0gShllzn0=; b=T5MXi/qZ3GAz7rR7d24I72OIUpXc//rLekS6p8aQcC8K/ZLVwFAfxTS2+ObfwynDMYiiYt 5i+9yaP0/VLWJYrU7n1yLgPYItBjJxU7md8u5lwpKzQHOyFd9zwIK9BrkEG2qMBinRrviW m1RLZDFPFQlhNFaLK5/BaqZ+Wegw6Bc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CtxWYsTw; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf30.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708030515; a=rsa-sha256; cv=none; b=5WNSBq0Jw5MAzkcQ52bmcU2r9KyMt+2Ozh3hsgC25xqWTjcVBOFmSdIjvqtUHs+2AzOSc3 vWrRxW+hJNTYadKfSWBRDpsCiwD5fsKnyy/YmQ8O/O6femAnjEoWfSvBWRufFEiIYXjHgA uazAbFVjONN9cKeuYwyxv/JeBMlxWWQ= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d746856d85so11659035ad.0 for ; Thu, 15 Feb 2024 12:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708030514; x=1708635314; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=r7KeUmQ5rtQIKjg5bbnS3xkReICqYXg+NK0gShllzn0=; b=CtxWYsTwoBdBsm/UbCBcoyZF9XSeeEuAGMiY4Hc7MiJqm7JHlcsS2qU3ppoIO5e6LG QkSKFZ0LpipWcxHeL2zNbKJXvFddwPPoSKonlROLaNEcsqZHVt+VdVNK2/vCayq+n8CI Kedgid9g9G9+8/wLoCeFhETv/oMWiOauVGSiLdSBKpvUr9mAn9lFXgoO8LdgCeb56Csb ezvYb1m/wOW/+Qu/CqnfepvBVMeN8Xcb+rb4wAJ0LmIKc0pZgEQoQ6PSM967IGW9OD2h L285+r2bfmpdLvK1oylV7x56/LXq7HUvkykighkG4qp8jFoJHEVmBgB2z5PEFt6HhpLP yaww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708030514; x=1708635314; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r7KeUmQ5rtQIKjg5bbnS3xkReICqYXg+NK0gShllzn0=; b=RI5crWR0LDXiXr0MHKQFp/q/DsLJyyiR6HxJAVSwr5M2yUD1S22ofET9AUeHWyw+XN seGLV4DM2v201hGMiIyCsv8Q23izyYTwlxmiKJR2zl9EScGCAfMY1KQdJHDwTh/zy0EA pGlboEXy7xv4QmiGE+rUIdjGcffgSUvqfHKCtK4llSILEE2NRpJ6u/gNJ8mfn0Y7HHRJ hZv9KUqg2aCuGgEcuyIQEZLziRgANbT0o87DdTKwOGkrY9kCpI2Feo3w1XOz0Q3GgJLf fdMrgMQ7tfGow4a01CCX8zQPYdZLdxeFsKWB69mygYemmIiC2dlD8IPUy8VcIi2uXT8l g50g== X-Forwarded-Encrypted: i=1; AJvYcCUuSwDktrfJE9x6iZRSpqzv9/wk38cEcBGTjePh8QClnpVuS3kr9Ck5+Uj1krnUM6Ly4Z0Mipxsjpc/1RroN6jK9EE= X-Gm-Message-State: AOJu0YwP8+uC2mOiMoRrMKEpMsc+8jpqY2XjEJa7TG4jGweLFpX3vBA0 nDITD8lVmG+DpU8X5TzGiDUk5bKmyiw6UgMvp6blPqxR/eiXpNK4 X-Google-Smtp-Source: AGHT+IF7vFLlsC6PM38G1zfNCpMrYhgcMQQS0vF9cRox0azJFhgKB3VSOd4zEVDtNy7j0rmcWMxpwg== X-Received: by 2002:a17:902:7c01:b0:1d9:f495:cfa4 with SMTP id x1-20020a1709027c0100b001d9f495cfa4mr2658373pll.62.1708030514195; Thu, 15 Feb 2024 12:55:14 -0800 (PST) Received: from google.com ([2620:0:1000:8411:9dc5:487d:7c08:30bb]) by smtp.gmail.com with ESMTPSA id x9-20020a170902e04900b001db561fa164sm1671380plx.25.2024.02.15.12.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 12:55:13 -0800 (PST) Date: Thu, 15 Feb 2024 12:55:11 -0800 From: Minchan Kim To: David Hildenbrand Cc: Kairui Song , linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , Chris Li , Yu Zhao , Barry Song , SeongJae Park , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/swap: fix race when skipping swapcache Message-ID: References: <20240206182559.32264-1-ryncsn@gmail.com> <1d259a51-46e6-4d3b-9455-38dbcc17b168@redhat.com> <4c651673-132f-4cd8-997e-175f586fd2e6@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c651673-132f-4cd8-997e-175f586fd2e6@redhat.com> X-Rspam-User: X-Stat-Signature: 64wwhjtsiwsgrrixiwprxz8knipujoe8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A42DA80017 X-HE-Tag: 1708030515-2144 X-HE-Meta: U2FsdGVkX1/VNDpI83VuPtZyKqtE4YeioAcNtlhjUprx0DSHcgWMIEYCUcR/RWIm+jTyyBkqgke6fojiVPlJVxTdp5lyadiaZDbHNSuK8NGRxwo1kOiUEuzTWTAxiaViDmJv1ZEJfuYI+Q39heCaTvzIkGicl25LopdjZf6poFtZDm0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bZHO9DSuLMQo+NFZHbL7ULI9FzSN43fGh9cTuyvsRMGqiwDQPnRnupQ89UH4t1/jB0sBLmWoXloDFNoJC0DhxdZnWjDZr+5kOukJf3M2+wYez7LRENQ3IuKnGiwFrGnVnTQhd0WzrTSKWH00Bz038S0tMXRuOWvRRY1wmLapOY1qxDRn9Pih7ETCq32zOgyl/3hjdkxL/nN9tCcDbFPHs5Fov1FVAwduF5I/3nTaJXQFrKAtsZGPWmcVq3ibNviwYk8DE+S2ef/u1YKlHX3oADOQY4GDv42LSTWNk/MmeB3gez4IPauWe8myJ/9am7Ebcgjme4+XQaXpYYzs6lG7mn2LjZVyN5wbD1esoQZ2dx77HjbGckIcM/31/hCvUJbmTnWvCQUJd9O7nQqZniXADAvIjk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi David, On Thu, Feb 15, 2024 at 09:03:28PM +0100, David Hildenbrand wrote: < snip > > > > > > > We would detect later, that the PTE changed, but we would temporarily > > > mess with that swap slot that we might no longer "own". > > > > > > I was thinking about alternatives, it's tricky because of the concurrent > > > MADV_DONTNEED possibility. Something with another fake-swap entry type > > > (similar to migration entries) might work, but would require more changes. > > > > Yeah, in the long term I also think more work is needed for the swap subsystem. > > > > In my opinion, for this particular issue, or, for cache bypassed > > swapin, a new swap map value similar to SWAP_MAP_BAD/SWAP_MAP_SHMEM > > might be needed, that may even help to simplify the swap count release > > routine for cache bypassed swapin, and improve the performance. > > The question is if we really want to track that in the swapcache and not > rather in the page table. > > Imagine the following: > > (1) allocate the folio and lock it (we do that already) > > (2) take the page table lock. If the PTE is still the same, insert a new > "swapin_in_process" fake swp entry that references the locked folio. > > (3) read the folio from swap. This will unlock the folio IIUC. (we do that > already) > > (4) relock the folio. (we do that already, might not want to fail) > > (4) take the PTE lock. If the PTE did not change, turn it into a present PTE > entry. Otherwise, cleanup. > > > Any concurrent swap-in users would spot the new "swapin_in_process" fake swp > entry and wait for the page lock (just like we do with migration entries). > > Zap code would mostly only clear the "swapin_in_process" fake swp entry and > leave the cleanup to (4) above. Fortunately, concurrent fork() is impossible > as that cannot race with page faults. > > There might be one minor thing to optimize with the folio lock above. But in > essence, it would work just like migration entries, just that they are > installed only while we actually do read the content from disk etc. That's a great idea. I was thinking to have the synchronization in the page table but couldn't reach to the other non_swap_entry idea. Only concern of the approach is that it would be harder to have the fix in the stable tree. If there isn't strong objection, I prefer the Kairui's orginal solution(with some tweak of scheduler if it's necessary) first and then pursue your idea on latest tree.