All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: ryncsn@gmail.com, nphamcs@gmail.com, ying.huang@intel.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: Tue, 9 Apr 2024 22:41:32 +0800	[thread overview]
Message-ID: <20240409144132.GA542987@bytedance> (raw)
In-Reply-To: <20240408132704.f966adc8d3928df4d3b8c0a9@linux-foundation.org>

On Mon, Apr 08, 2024 at 01:27:04PM -0700, Andrew Morton wrote:
> 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?

Hi Andrew,

When share memory between two or more processes has swapped and pagefault now,
it would readahead swap and call __read_swap_cache_async().
If one of the processes calls swapcache_prepare() and finds that the cache 
has been EXIST(another process added), it will folio_put on the basis of the 
alloc_pages_mpol() that has been called, and then try filemap_get_folio() again.

I think the page alloc in this process is wasteful.
when the memory pressure is large, alloc_pages_mpol() will be time-consuming, 
so the purpose of my patch is to judge whether the page has cache before page alloc, 
then skip page alloc and retry filemap_get_folio() to save the time of the function.

Thank you.

> 
> > So skip page allocation if SWAP_HAS_CACHE was set, just
> > schedule_timeout_uninterruptible and continue to acquire page
> > via filemap_get_folio() from swap cache, to speedup
> > __read_swap_cache_async.


  parent reply	other threads:[~2024-04-09 14:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 12:14 [PATCH v2] mm: swap: prejudgement swap_has_cache to avoid page allocation 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
2024-04-10  1:45       ` Huang, Ying
2024-04-09 14:41   ` Zhaoyu Liu [this message]
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=20240409144132.GA542987@bytedance \
    --to=liuzhaoyu.zackary@bytedance.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=nphamcs@gmail.com \
    --cc=ryncsn@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=ying.huang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.