From: lizhe.67@bytedance.com
To: akpm@linux-foundation.org
Cc: david@redhat.com, dev.jain@arm.com, jgg@ziepe.ca,
jhubbard@nvidia.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, lizhe.67@bytedance.com,
muchun.song@linux.dev, peterx@redhat.com
Subject: Re: [PATCH v2] gup: optimize longterm pin_user_pages() for large folio
Date: Wed, 4 Jun 2025 15:58:30 +0800 [thread overview]
Message-ID: <20250604075830.27751-1-lizhe.67@bytedance.com> (raw)
In-Reply-To: <20250603204414.f2963e4a094e360cad7f966e@linux-foundation.org>
On Tue, 3 Jun 2025 20:44:14 -0700, akpm@linux-foundation.org wrote:
> On Wed, 4 Jun 2025 11:15:36 +0800 lizhe.67@bytedance.com wrote:
>
> > From: Li Zhe <lizhe.67@bytedance.com>
> >
> > In the current implementation of the longterm pin_user_pages() function,
> > we invoke the collect_longterm_unpinnable_folios() function. This function
> > iterates through the list to check whether each folio belongs to the
> > "longterm_unpinnabled" category. The folios in this list essentially
> > correspond to a contiguous region of user-space addresses, with each folio
> > representing a physical address in increments of PAGESIZE. If this
> > user-space address range is mapped with large folio, we can optimize the
> > performance of function pin_user_pages() by reducing the frequency of
> > memory accesses using READ_ONCE. This patch leverages this approach to
> > achieve performance improvements.
> >
> > The performance test results obtained through the gup_test tool from the
> > kernel source tree are as follows. We achieve an improvement of over 70%
> > for large folio with pagesize=2M. For normal page, we have only observed
> > a very slight degradation in performance.
> >
> > Without this patch:
> >
> > [root@localhost ~] ./gup_test -HL -m 8192 -n 512
> > TAP version 13
> > 1..1
> > # PIN_LONGTERM_BENCHMARK: Time: get:13623 put:10799 us#
> > ok 1 ioctl status 0
> > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> > [root@localhost ~]# ./gup_test -LT -m 8192 -n 512
> > TAP version 13
> > 1..1
> > # PIN_LONGTERM_BENCHMARK: Time: get:129733 put:31753 us#
> > ok 1 ioctl status 0
> > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> >
> > With this patch:
> >
> > [root@localhost ~] ./gup_test -HL -m 8192 -n 512
> > TAP version 13
> > 1..1
> > # PIN_LONGTERM_BENCHMARK: Time: get:4075 put:10792 us#
> > ok 1 ioctl status 0
> > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> > [root@localhost ~]# ./gup_test -LT -m 8192 -n 512
> > TAP version 13
> > 1..1
> > # PIN_LONGTERM_BENCHMARK: Time: get:130727 put:31763 us#
> > ok 1 ioctl status 0
> > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> I see no READ_ONCE()s in the patch and I had to go off and read the v1
> review to discover that the READ_ONCE is invoked in
> page_folio()->_compound_head(). Please help us out by including such
> details in the changelogs.
Sorry for the inconvenience. I will refine the wording of this part in
the next version.
> Is it credible that a humble READ_ONCE could yield a 3x improvement in
> one case? Why would this happen?
Sorry for the incomplete description. I believe that this optimization
is the result of multiple factors working together. In addition to
reducing the use of READ_ONCE(), when dealing with a large folio, we
simplify the check from comparing with prev_folio after invoking
pofs_get_folio() to determine if the next page is within the folio.
This change reduces the number of branches and increase cache hit rates.
The overall effect is a combination of these optimizations. I will
incorporate these details into the commit message in the next version.
Thanks,
Zhe
next prev parent reply other threads:[~2025-06-04 7:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 3:15 lizhe.67
2025-06-04 3:44 ` Andrew Morton
2025-06-04 7:58 ` lizhe.67 [this message]
2025-06-04 8:12 ` David Hildenbrand
2025-06-04 9:11 ` lizhe.67
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=20250604075830.27751-1-lizhe.67@bytedance.com \
--to=lizhe.67@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=peterx@redhat.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
all inboxes | Powered by JetHome®