Re: Extending page pinning into fs/direct-io.c

From: Christoph Hellwig
Date: Thu May 25 2023 - 05:52:25 EST


On Wed, May 24, 2023 at 09:47:10AM +0100, David Howells wrote:
> True - but I was thinking of just treating the zero_page specially and never
> hold a pin or a ref on it. It can be checked by address, e.g.:
>
> static inline void bio_release_page(struct bio *bio, struct page *page)
> {
> if (page == ZERO_PAGE(0))
> return;
> if (bio_flagged(bio, BIO_PAGE_PINNED))
> unpin_user_page(page);
> else if (bio_flagged(bio, BIO_PAGE_REFFED))
> put_page(page);
> }

That does sound good as well to me.

> I was looking at this:
>
> static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio)
> {
> ...
> if (dio->is_async && dio_op == REQ_OP_READ && dio->should_dirty)
> bio_set_pages_dirty(bio);
> ...
> }
>
> but looking again, the lock is taken briefly and the dirty bit is set - which
> is reasonable. However, should we be doing it before starting the I/O?

It is done before starting the I/O - the submit_bio is just below this.