linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: Nhat Pham <nphamcs@gmail.com>
Cc: Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	 ryncsn@gmail.com,  songmuchun@bytedance.com, david@redhat.com,
	 chrisl@kernel.org,  guo.ziliang@zte.com.cn,
	yosryahmed@google.com,  linux-kernel@vger.kernel.org,
	 linux-mm@kvack.org
Subject: Re: [PATCH v2] mm: swap: prejudgement swap_has_cache to avoid page allocation
Date: Wed, 10 Apr 2024 09:46:18 +0800	[thread overview]
Message-ID: <8734ru6lcl.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <CAKEwX=MBts2mGgTE__VP-ZVMrMFTzQnbTAkMPTJs3KNRQ2QDjg@mail.gmail.com> (Nhat Pham's message of "Tue, 9 Apr 2024 10:52:40 -0700")

Nhat Pham <nphamcs@gmail.com> writes:

> On Tue, Apr 9, 2024 at 7:57 AM Zhaoyu Liu
> <liuzhaoyu.zackary@bytedance.com> wrote:
>>
>> On Tue, Apr 09, 2024 at 09:07:29AM +0800, Huang, Ying wrote:
>> > Andrew Morton <akpm@linux-foundation.org> writes:
>> >
>> > > On Mon, 8 Apr 2024 20:14:39 +0800 Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com> wrote:
>> > >
>> > >> Based on qemu arm64 - latest kernel + 100M memory + 1024M swapfile.
>> > >> Create 1G anon mmap and set it to shared, and has two processes
>> > >> randomly access the shared memory. When they are racing on swap cache,
>> > >> on average, each "alloc_pages_mpol + swapcache_prepare + folio_put"
>> > >> took about 1475 us.
>> > >
>> > > And what effect does this patch have upon the measured time?  ANd upon
>> > > overall runtime?
>> >
>> > And the patch will cause increased lock contention, please test with
>> > more processes and perhaps HDD swap device too.
>>
>> Hi Ying,
>>
>> Thank you for your suggestion.
>> It may indeed cause some lock contention, as mentioned by Kairui before.
>>
>> If so, is it recommended?
>> ---
>>   unsigned char swap_map, mapcount, hascache;
>>   ...
>>   /* Return raw data of the si->swap_map[offset] */
>>   swap_map = __swap_map(si, entry);
>>   mapcount = swap_map & ~SWAP_HAS_CACHE;
>>   if (!mapcount && swap_slot_cache_enabled)
>>   ...
>>   hascache = swap_map & SWAP_HAS_CACHE;
>>   /* Could judge that it's being added to swap cache with high probability */
>>   if (mapcount && hascache)
>>     goto skip_alloc;
>>   ...
>> ---
>> In doing so, there is no additional use of locks.
>>
>
> Hmm so is this a lockless check now? Ummmm... Could someone with more
> expertise in the Linux kernel memory model double check that this is
> even a valid state we're observing here? Looks like we're performing
> an unguarded, unsynchronized, non-atomic read with the possibility of
> concurrent write - is there a chance we might see partial/invalid
> results?
>
> Could you also test with zswap enabled (and perhaps with zswap
> shrinker enabled)?

READ_ONCE() will save us from partial/invalid results.

--
Best Regards,
Huang, Ying


  reply	other threads:[~2024-04-10  1:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 12:14 Zhaoyu Liu
2024-04-08 20:27 ` Andrew Morton
2024-04-09  1:07   ` Huang, Ying
2024-04-09 14:57     ` Zhaoyu Liu
2024-04-09 17:52       ` Nhat Pham
2024-04-10  1:46         ` Huang, Ying [this message]
2024-04-10  1:45       ` Huang, Ying
2024-04-09 14:41   ` Zhaoyu Liu
2024-04-10  1:43     ` Huang, Ying
2024-04-10 18:55 ` Tim Chen

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=8734ru6lcl.fsf@yhuang6-desk2.ccr.corp.intel.com \
    --to=ying.huang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=guo.ziliang@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuzhaoyu.zackary@bytedance.com \
    --cc=nphamcs@gmail.com \
    --cc=ryncsn@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=yosryahmed@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