Re: [PATCH v8 14/15] filemap: Add support for authoritative mappings
[email protected] Tue, 4 Aug 2026 00:02:50 -0700
| Newsgroups | gmane.linux.file-systems,gmane.linux.kernel.mm |
|---|---|
| Message-ID | <[email protected]> |
On 7/31/2026 1:07 PM, Matthew Wilcox (Oracle) wrote: > An authoritative mapping knows about all the folios in the mapping. If=20 > read() finds a missing folio, there's no reason to allocate one and try=20 > to read it because we know it's a zero region of the file. We can just=20 > call iov_iter_zero() instead.=E2=80=8A >=20 >=20 > An authoritative mapping knows about all the folios in the mapping. > If read() finds a missing folio, there's no reason to allocate one and > try to read it because we know it's a zero region of the file. We can > just call iov_iter_zero() instead. >=20 > Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> > --- > include/linux/pagemap.h | 11 +++++++++++ > mm/filemap.c | 18 ++++++++++++++++++ > 2 files changed, 29 insertions(+) >=20 > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index 968b791cfd14..22d48935ffda 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -210,6 +210,7 @@ enum mapping_flags { > AS_WRITEBACK_MAY_DEADLOCK_ON_RECLAIM =3D 9, > AS_KERNEL_FILE =3D 10, /* mapping for a fake kernel file that shouldn't > account usage to user cgroups */ > + AS_AUTHORITATIVE =3D 11, /* If we miss in the page cache, it's a hole */ > /* Bits 16-25 are used for FOLIO_ORDER */ > AS_FOLIO_ORDER_BITS =3D 5, > AS_FOLIO_ORDER_MIN =3D 16, > @@ -345,6 +346,16 @@ static inline bool mapping_writeback_may_deadlock_on= _reclaim(const struct addres > return test_bit(AS_WRITEBACK_MAY_DEADLOCK_ON_RECLAIM, &mapping->flags); > } > =20 > +static inline void mapping_set_authoritative(struct address_space *mappi= ng) > +{ > + set_bit(AS_AUTHORITATIVE, &mapping->flags); > +} > + > +static inline bool mapping_is_authoritative(const struct address_space *= mapping) > +{ > + return test_bit(AS_AUTHORITATIVE, &mapping->flags); > +} > + > static inline gfp_t mapping_gfp_mask(const struct address_space *mappin= g) > { > return mapping->gfp_mask; > diff --git a/mm/filemap.c b/mm/filemap.c > index 26a5f18121f9..5a8cc20e624e 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2697,6 +2697,8 @@ static int filemap_get_pages(struct kiocb *iocb, si= ze_t count, > if (!folio_batch_count(fbatch)) { > DEFINE_READAHEAD(ractl, filp, &filp->f_ra, mapping, index); > =20 > + if (mapping_is_authoritative(mapping)) > + return 0; > if (iocb->ki_flags & IOCB_NOIO) > return -EAGAIN; > if (iocb->ki_flags & IOCB_NOWAIT) > @@ -2853,6 +2855,22 @@ ssize_t filemap_read(struct kiocb *iocb, struct io= v_iter *iter, > goto put_folios; > end_offset =3D min_t(loff_t, isize, iocb->ki_pos + iter->count); > =20 > + if (!folio_batch_count(&fbatch)) { > + size_t fsize =3D mapping_min_folio_nrbytes(mapping); > + size_t offset =3D iocb->ki_pos & (fsize - 1); > + size_t bytes =3D min_t(loff_t, end_offset - iocb->ki_pos, > + fsize - offset); > + size_t copied =3D iov_iter_zero(bytes, iter); > + > + already_read +=3D copied; > + iocb->ki_pos +=3D copied; > + last_pos =3D iocb->ki_pos; > + > + if (copied < bytes) > + error =3D -EFAULT; > + continue; > + } > + > /* > * Once we start copying data, we don't want to be touching any > * cachelines that might be contended: > --=20 > 2.47.3 >=20 Very nice change. Reviewed-by: Jane Chu <[email protected]> thanks, -jane