From: David Hildenbrand <david@redhat.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, lizhe.67@bytedance.com
Cc: akpm@linux-foundation.org, alex.williamson@redhat.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, peterx@redhat.com
Subject: Re: [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked()
Date: Wed, 18 Jun 2025 13:40:13 +0200 [thread overview]
Message-ID: <9c31da33-8579-414a-9b2a-21d7d8049050@redhat.com> (raw)
In-Reply-To: <20250618113626.GK1376515@ziepe.ca>
On 18.06.25 13:36, Jason Gunthorpe wrote:
> On Wed, Jun 18, 2025 at 02:28:20PM +0800, lizhe.67@bytedance.com wrote:
>> On Tue, 17 Jun 2025 12:22:10 -0300, jgg@ziepe.ca wrote:
>>> + while (npage) {
>>> + long nr_pages = 1;
>>> +
>>> + if (!is_invalid_reserved_pfn(pfn)) {
>>> + struct page *page = pfn_to_page(pfn);
>>> + struct folio *folio = page_folio(page);
>>> + long folio_pages_num = folio_nr_pages(folio);
>>> +
>>> + /*
>>> + * For a folio, it represents a physically
>>> + * contiguous set of bytes, and all of its pages
>>> + * share the same invalid/reserved state.
>>> + *
>>> + * Here, our PFNs are contiguous. Therefore, if we
>>> + * detect that the current PFN belongs to a large
>>> + * folio, we can batch the operations for the next
>>> + * nr_pages PFNs.
>>> + */
>>> + if (folio_pages_num > 1)
>>> + nr_pages = min_t(long, npage,
>>> + folio_pages_num -
>>> + folio_page_idx(folio, page));
>>> +
>>> + unpin_user_folio_dirty_locked(folio, nr_pages,
>>> + dma->prot & IOMMU_WRITE);
>>
>> Are you suggesting that we should directly call
>> unpin_user_page_range_dirty_lock() here (patch 3/3) instead?
>
> I'm saying you should not have the word 'folio' inside the VFIO. You
> accumulate a contiguous range of pfns, by only checking the pfn, and
> then call
>
> unpin_user_page_range_dirty_lock(pfn_to_page(first_pfn)...);
>
> No need for any of this. vfio should never look at the struct page
> except as the last moment to pass the range.
Hah, agreed, that's actually simpler and there is no need to factor
anything out.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-06-18 11:40 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 4:18 [PATCH v4 0/3] optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 4:18 ` [PATCH v4 1/3] vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote() lizhe.67
2025-06-17 4:18 ` [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked() lizhe.67
2025-06-17 7:35 ` David Hildenbrand
2025-06-17 13:42 ` Jason Gunthorpe
2025-06-17 13:45 ` David Hildenbrand
2025-06-17 13:58 ` David Hildenbrand
2025-06-17 14:04 ` David Hildenbrand
2025-06-17 15:22 ` Jason Gunthorpe
2025-06-18 6:28 ` lizhe.67
2025-06-18 8:20 ` David Hildenbrand
2025-06-18 11:36 ` Jason Gunthorpe
2025-06-18 11:40 ` David Hildenbrand [this message]
2025-06-18 11:42 ` David Hildenbrand
2025-06-18 11:46 ` Jason Gunthorpe
2025-06-18 11:52 ` David Hildenbrand
2025-06-18 11:56 ` Jason Gunthorpe
2025-06-18 12:19 ` lizhe.67
2025-06-18 13:23 ` Jason Gunthorpe
2025-06-19 9:05 ` lizhe.67
2025-06-19 12:35 ` Jason Gunthorpe
2025-06-19 12:49 ` lizhe.67
2025-06-17 4:18 ` [PATCH v4 3/3] vfio/type1: optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 7:43 ` David Hildenbrand
2025-06-17 9:21 ` [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked() lizhe.67
2025-06-17 9:27 ` David Hildenbrand
2025-06-17 9:47 ` [PATCH v4 3/3] vfio/type1: optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 9:49 ` David Hildenbrand
2025-06-17 12:42 ` lizhe.67
2025-06-17 13:47 ` David Hildenbrand
2025-06-18 6:11 ` lizhe.67
2025-06-18 7:22 ` lizhe.67
2025-06-18 8:54 ` David Hildenbrand
2025-06-18 9:39 ` 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=9c31da33-8579-414a-9b2a-21d7d8049050@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex.williamson@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizhe.67@bytedance.com \
--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