Re: [RFC PATCH] block, fs: use FOLL_LONGTERM as gup_flags for direct IO

Christoph Hellwig
2025-03-12T16:21:12Z

On Wed, Mar 12, 2025 at 09:06:02AM -0700, Suren Baghdasaryan wrote:
> > Any file or anonymous folio can be temporarily pinned for I/O and only
> > moved once that completes. Direct I/O is one use case for that but there
> > are plenty others. I'm not sure how you define "beforehand", but the
> > pinning is visible in the _pincount field.
>
> Well, by "beforehand" I mean that when allocating for Direct I/O
> operation we know this memory will be pinned,

Direct I/O is performed on anonymous (or more rarely) file backed pages
that are allocated from the normal allocators. Some callers might know
that they are eventually going to perform direct I/O on them, but most
won't as that information is a few layers removed from them or totally
hidden in libraries.

The same is true for other pin_user_pages operations. If you want memory
that is easily available for CMA allocations it better not be given out
as anonymous memory, and probably also not as file backed memory. Which
just leaves you with easily migratable kernel allocations, i.e. not much.