linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>,  Chris Li <chrisl@kernel.org>,
	 Barry Song <21cnbao@gmail.com>,
	 linux-mm@kvack.org,  Andrew Morton <akpm@linux-foundation.org>,
	 Yu Zhao <yuzhao@google.com>,  Barry Song <v-songbaohua@oppo.com>,
	 SeongJae Park <sj@kernel.org>,  Hugh Dickins <hughd@google.com>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	 Matthew Wilcox <willy@infradead.org>,
	 Michal Hocko <mhocko@suse.com>,
	 Yosry Ahmed <yosryahmed@google.com>,
	 David Hildenbrand <david@redhat.com>,
	stable@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm/swap: fix race when skipping swapcache
Date: Thu, 08 Feb 2024 14:34:48 +0800	[thread overview]
Message-ID: <87eddnxy47.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <CAMgjq7AJo1SKzRc-w5UuK3Ojk5PaXxRV2_G2Ww9BGgiNRp_5Eg@mail.gmail.com> (Kairui Song's message of "Thu, 8 Feb 2024 14:04:54 +0800")

Kairui Song <ryncsn@gmail.com> writes:

> On Thu, Feb 8, 2024 at 2:31 AM Minchan Kim <minchan@kernel.org> wrote:
>>
>> 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 == 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


  reply	other threads:[~2024-02-08  6:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 18:25 Kairui Song
2024-02-06 18:44 ` SeongJae Park
2024-02-06 23:02 ` Minchan Kim
2024-02-07  3:22   ` Kairui Song
2024-02-06 23:10 ` Chris Li
2024-02-06 23:40   ` Barry Song
2024-02-07  2:03     ` Chris Li
2024-02-07  2:20       ` Kairui Song
2024-02-07  1:52         ` Barry Song
2024-02-07  3:21           ` Kairui Song
2024-02-07  4:01         ` Chris Li
2024-02-07  4:06           ` Kairui Song
2024-02-07 18:31             ` Minchan Kim
2024-02-08  6:04               ` Kairui Song
2024-02-08  6:34                 ` Huang, Ying [this message]
2024-02-08 19:01                   ` Kairui Song
2024-02-08 19:42                     ` Chris Li
2024-02-09  5:30                       ` Kairui Song
2024-02-12 19:53                         ` Kairui Song
2024-02-15  0:44                           ` Minchan Kim
2024-02-15 19:07                             ` Kairui Song
2024-02-19  5:42                     ` Huang, Ying
2024-02-08  7:16                 ` Barry Song
2024-02-07  2:08     ` Huang, Ying
2024-02-07  2:28       ` Kairui Song
2024-02-07  3:44         ` Huang, Ying
2024-02-07  3:45         ` Barry Song
2024-02-07  4:16           ` Huang, Ying
2024-02-07  4:24             ` Barry Song
2024-02-15 15:36 ` David Hildenbrand
2024-02-15 18:49   ` Kairui Song
2024-02-15 20:03     ` David Hildenbrand
2024-02-15 20:55       ` Minchan Kim
2024-02-15 22:58         ` Andrew Morton
2024-02-16 10:01           ` Kairui Song
2024-02-16  7:11       ` Kairui Song
2024-02-16 16:16         ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eddnxy47.fsf@yhuang6-desk2.ccr.corp.intel.com \
    --to=ying.huang@intel.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=ryncsn@gmail.com \
    --cc=sj@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=v-songbaohua@oppo.com \
    --cc=willy@infradead.org \
    --cc=yosryahmed@google.com \
    --cc=yuzhao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox