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 DED5AC4828F for ; Thu, 8 Feb 2024 06:36:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E2C46B0095; Thu, 8 Feb 2024 01:36:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 690896B0096; Thu, 8 Feb 2024 01:36:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 531C46B0098; Thu, 8 Feb 2024 01:36:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 407696B0095 for ; Thu, 8 Feb 2024 01:36:53 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1554A1A016C for ; Thu, 8 Feb 2024 06:36:53 +0000 (UTC) X-FDA: 81767678706.04.ECB26F4 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by imf09.hostedemail.com (Postfix) with ESMTP id 940FA140011 for ; Thu, 8 Feb 2024 06:36:49 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="O/4NW8eI"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.18 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707374210; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wPxTQLzIgrSJ4B0TUl71M/QYWADF9h5/QqFKKez4h+8=; b=h217ENVr+ZBSgkLC1VPZG5cOsfvOHQK/noZQbxLYSSDHY52glDW0vPW1tOpXNcod+kS8x1 73m8XMsnTjRkqTXpbkJPIquexGxx19FJ0jdiaMVMhIeIe1ta3GmyTz1ePJUuVvqrBjDKtG Rupq70/IksjaFgQqNshzmT2hpViUzjQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="O/4NW8eI"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.18 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707374210; a=rsa-sha256; cv=none; b=wMX8OjklswnLleaK1XPPgE6qR6AgxnUihUfxVoqOFgUxeS4rYl+lTK7SZzTrp5NkRk69kC MSLS9DbUEWEuNOZF0yYNEWCfoDcRssyRD5pT4AC4lbmOjnkyP1JjtqHyKqM7e0nBbBQ5Zt ds0ZKHsT6fpjL9GNWCl9jieiZmahCpE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707374210; x=1738910210; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=wPxTQLzIgrSJ4B0TUl71M/QYWADF9h5/QqFKKez4h+8=; b=O/4NW8eIap8YcQLRBok6UCVuxCSBqSuMAOKNKwLukC9uISSINooXOV+n in4ETaTRtZR/Dy1nkHjabxCUFibpNsfW6pKOwTg0yybgCivEYUGG1TUYA +ruOVa6cHFgE5uWRJ1pucXZtLpRTZQxCgdbL59y47asO2IxsQTyvADnef aw2mgiudHlh+sgI+txin1EleIKEGtR3c2fGiSVdMx8qywElvO6YPXBirn 29/3UNy39gaT8wvePfpkejmwttCOhNefA3QKaASM4VBqfxXcedCvkzC3W 5GSV3bAFLnHwNn8NLwuj9jHU/oewT55A+w3QVBRIrdTM5/nkq0GwUvyn2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="1297940" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1297940" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 22:36:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1568338" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 22:36:44 -0800 From: "Huang, Ying" To: Kairui Song Cc: Minchan Kim , Chris Li , Barry Song <21cnbao@gmail.com>, linux-mm@kvack.org, Andrew Morton , Yu Zhao , Barry Song , SeongJae Park , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/swap: fix race when skipping swapcache In-Reply-To: (Kairui Song's message of "Thu, 8 Feb 2024 14:04:54 +0800") References: <20240206182559.32264-1-ryncsn@gmail.com> Date: Thu, 08 Feb 2024 14:34:48 +0800 Message-ID: <87eddnxy47.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 940FA140011 X-Stat-Signature: onm1auxn1zabrtobjm1zzfk34k3r9wo5 X-Rspam-User: X-HE-Tag: 1707374209-741624 X-HE-Meta: U2FsdGVkX19oXjGOc4kNFXcTbjO9R8Vc+7jkQhDgPUoMBGJL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4c+UMTmwID3mnbuqagubyKtThqMOVcQYz1teaDWpNZ+O2pio0jl9GyhWr03qkz2Z3EAfQDmz/nBkq73vsZ9zwjhcfACSyTWFFegH 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: Kairui Song writes: > On Thu, Feb 8, 2024 at 2:31=E2=80=AFAM Minchan Kim w= rote: >> >> On Wed, Feb 07, 2024 at 12:06:15PM +0800, Kairui Song wrote: [snip] >> > >> > So I think the thing is, it's getting complex because this patch >> > wanted to make it simple and just reuse the swap cache flags. >> >> I agree that a simple fix would be the important at this point. >> >> Considering your description, here's my understanding of the other idea: >> Other method, such as increasing the swap count, haven't proven effective >> in your tests. The approach risk forcing racers to rely on the swap cache >> again and the potential performance loss in race scenario. >> >> While I understand that simplicity is important, and performance loss >> in this case may be infrequent, I believe swap_count approach could be a >> suitable solution. What do you think? > > Hi Minchan > > Yes, my main concern was about simplicity and performance. > > Increasing swap_count here will also race with another process from > releasing swap_count to 0 (swapcache was able to sync callers in other > call paths but we skipped swapcache here). What is the consequence of the race condition? > So the right step is: 1. Lock the cluster/swap lock; 2. Check if still > have swap_count =3D=3D 1, bail out if not; 3. Set it to 2; > __swap_duplicate can be modified to support this, it's similar to > existing logics for SWAP_HAS_CACHE. > > And swap freeing path will do more things, swapcache clean up needs to > be handled even in the bypassing path since the racer may add it to > swapcache. > > Reusing SWAP_HAS_CACHE seems to make it much simpler and avoided many > overhead, so I used that way in this patch, the only issue is > potentially repeated page faults now. > > I'm currently trying to add a SWAP_MAP_LOCK (or SWAP_MAP_SYNC, I'm bad > at naming it) special value, so any racer can just spin on it to avoid > all the problems, how do you think about this? Let's try some simpler method firstly. -- Best Regards, Huang, Ying