From: Dev Jain <dev.jain@arm.com>
To: lizhe.67@bytedance.com
Cc: akpm@linux-foundation.org, david@redhat.com, jgg@ziepe.ca,
jhubbard@nvidia.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, muchun.song@linux.dev, peterx@redhat.com,
ryan.roberts@arm.com
Subject: Re: [PATCH] gup: optimize longterm pin_user_pages() for large folio
Date: Fri, 30 May 2025 15:42:10 +0530 [thread overview]
Message-ID: <3678020c-8b67-4ad7-a859-59d301784883@arm.com> (raw)
In-Reply-To: <20250530100453.36028-1-lizhe.67@bytedance.com>
On 30/05/25 3:34 pm, lizhe.67@bytedance.com wrote:
> On Fri, 30 May 2025 15:23:49 +0530, dev.jain@arm.com wrote:
>
>> On 30/05/25 2:53 pm, 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 number of if-else
>>> branches and 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 75%
>>> for large folio with pagesize=2M. For normal page, we have only observed
>>> a very slight degradation in performance.
>>
>> Thanks for the patch! I have no idea on GUP but in my limited understanding
>> the patch looks fine, let's wait for more comments.
>>
>> [----]
>>
>>> }
>>>
>>> +static struct folio *pofs_next_folio(struct folio *folio,
>>> + struct pages_or_folios *pofs, long *index_ptr)
>>> +{
>>> + long i = *index_ptr + 1;
>>> + unsigned long nr_pages = folio_nr_pages(folio);
>>> +
>>> + if (!pofs->has_folios)
>>> + while ((i < pofs->nr_entries) &&
>>> + /* Is this page part of this folio? */
>>> + (folio_page_idx(folio, pofs->pages[i]) < nr_pages))
>>> + i++;
>>> +
>>> + if (unlikely(i == pofs->nr_entries))
>>> + return NULL;
>>> + *index_ptr = i;
>>> +
>>> + return pofs_get_folio(pofs, i);
>>> +}
>>> +
>>> /*
>>> * Returns the number of collected folios. Return value is always >= 0.
>>> */
>>> @@ -2324,16 +2343,12 @@ static void collect_longterm_unpinnable_folios(
>>> struct list_head *movable_folio_list,
>>> struct pages_or_folios *pofs)
>>> {
>>> - struct folio *prev_folio = NULL;
>>> bool drain_allow = true;
>>> - unsigned long i;
>>> -
>>> - for (i = 0; i < pofs->nr_entries; i++) {
>>> - struct folio *folio = pofs_get_folio(pofs, i);
>>> + long i = 0;
>>
>> Why not unsigned long?
> This is because I want to match the type of pages_or_folios->nr_entries.
Ah right, although I wonder why we are not using unsigned long in the first place...
>
> Thanks,
> Zhe
next prev parent reply other threads:[~2025-05-30 10:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 9:23 lizhe.67
2025-05-30 9:53 ` Dev Jain
2025-05-30 10:04 ` lizhe.67
2025-05-30 10:12 ` Dev Jain [this message]
2025-05-30 11:31 ` David Hildenbrand
2025-05-30 12:20 ` lizhe.67
2025-05-30 13:08 ` David Hildenbrand
2025-05-30 15:02 ` lizhe.67
2025-05-30 20:37 ` 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=3678020c-8b67-4ad7-a859-59d301784883@arm.com \
--to=dev.jain@arm.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizhe.67@bytedance.com \
--cc=muchun.song@linux.dev \
--cc=peterx@redhat.com \
--cc=ryan.roberts@arm.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