Skip to contentSkip to conversation

pin_user_pages_fast failure count increased

RFC Jaewon Kim 4 participants 6 messages Apr 28, 2025 – May 22, 2025 Memory management

lore
Share & tools
lore

Jaewon Kim

author
#0 lore raw

Hi

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

Our GPU driver uses pin_user_pages_fast.
After the recent kernel update, pin_user_pages_fast sometimes does not pin all the pages, nr_pinned < nr_pages.

I think the following patch affected the pin_user_pages_fast behavior. 1aaf8c122918 mm: gup: fix infinite loop within __get_longterm_locked

BR
Jaewon Kim

#1 lore raw
Quoted 1 line · Jaewon Kim

Hi

Hi,

Quoted 4 lines

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

It should continue from the first-not-pinned-one. If there is an error, it will be reported, otherwise it will make progress.

Quoted 4 lines

Our GPU driver uses pin_user_pages_fast.
After the recent kernel update, pin_user_pages_fast sometimes does not pin all the pages, nr_pinned < nr_pages.

Yeah, that can happen as documented.

Signature · 3 lines
Cheers,

David / dhildenb
#2 lore raw
In reply to Jaewon Kim
Quoted 6 lines · Jaewon Kim

Hi

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

Approaches vary, for handling partial success of pin_user_pages().

* Many drivers unpin everything and either bail out entirely, or retry pinning the entire original range.

* A few drivers try to pin the remain pages, in a retry loop (I think the gpu/drm drivers IIRC).

It's really up to the driver author, how to respond to the inability (which may be temporary) to pin the entire range all at once.

Quoted 7 lines

Our GPU driver uses pin_user_pages_fast.
After the recent kernel update, pin_user_pages_fast sometimes does not pin all the pages, nr_pinned < nr_pages.

I think the following patch affected the pin_user_pages_fast behavior. 1aaf8c122918 mm: gup: fix infinite loop within __get_longterm_locked

OK. If you see a bug or a problem, please elaborate.

thanks,

Signature · 1 line
John Hubbard
#3 lore raw
Quoted 8 lines · John Hubbard
Quoted 6 lines · Jaewon Kim

Hi

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

Quoted 4 lines

Approaches vary, for handling partial success of pin_user_pages().

* Many drivers unpin everything and either bail out entirely, or retry pinning the entire original range.

Hm, unpinning + trying to repin the entire range can easily result in an endless loop on persistent errors IIRC?

Signature · 3 lines
Cheers,

David / dhildenb
#4 lore raw
Quoted 9 lines · David Hildenbrand
Quoted 8 lines · John Hubbard
Quoted 6 lines · Jaewon Kim

Hi

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

Quoted 7 lines
Quoted 4 lines

Approaches vary, for handling partial success of pin_user_pages().

* Many drivers unpin everything and either bail out entirely, or retry pinning the entire original range.

Hm, unpinning + trying to repin the entire range can easily result in an endless loop on persistent errors IIRC?

I vaguely recall a limited number of retries, yes.

thanks,

Signature · 1 line
John Hubbard
#5 lore raw
Quoted 15 lines · John Hubbard
Quoted 14 lines · David Hildenbrand
Quoted 12 lines · John Hubbard
Quoted 6 lines · Jaewon Kim

Hi

If pin_user_pages_fast does not pin all the requested number of pages, then drivers calling to pin_user_pages_fast should retry until the gup pins all?

Approaches vary, for handling partial success of pin_user_pages().

* Many drivers unpin everything and either bail out entirely, or retry pinning the entire original range.

Quoted 11 lines
Quoted 3 lines

Hm, unpinning + trying to repin the entire range can easily result in an endless loop on persistent errors IIRC?

I vaguely recall a limited number of retries, yes.

thanks,

Signature · 1 line
John Hubbard

Hi,

I'd like to report a potential issue introduced by a recent change in 1aaf8c122918 mm: gup: fix infinite loop within __get_longterm_locked

Previously, the call to migrate_longterm_unpinnable_folio() was guarded by the collected variable. This meant that if a CMA page was temporarily held in the pagevec and failed LRU isolation, it wouldn't be added to the movable_page_list, but the collected counter would still be incremented.

As a result, migrate_longterm_unpinnable_folio() would return -EAGAIN, and the process would be retried until migration of the CMA page succeeded.

However, in the recent patch merged into mainline, the logic now only checks whether movable_page_list is empty, and no longer relies on the collected count. This can cause CMA pages that fail isolation to bypass retry logic and remain pinned.

Effectively,long-term pinning is now possible for CMA pages — something that previously would have been avoided through repeated attempts.

We've observed this behavior in practice, which has led to issues such as CMA allocation failures under memory pressure. This may indicate a regression in the logic that prevents pinning of unmovable CMA pages.

I believe this warrants further discussion or possibly a fix to restore the intended retry behavior for pages that fail LRU isolation.

Thanks,
Hyesoo Yu.