Re: [PATCH v2 04/11] hugetlbfs,filemap: replace hugetlbfs_read_iter() with generic_file_read_iter()
From: Matthew Wilcox
Date: Wed Jun 17 2026 - 16:08:16 EST
On Wed, Jun 17, 2026 at 11:25:25AM -0600, Jane Chu wrote:
> +++ b/mm/filemap.c
> @@ -2672,20 +2672,30 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count,
> {
> struct file *filp = iocb->ki_filp;
> struct address_space *mapping = filp->f_mapping;
> + bool is_hugetlbfs = is_file_hugepages(filp);
> pgoff_t index = iocb->ki_pos >> PAGE_SHIFT;
> pgoff_t last_index;
> struct folio *folio;
> unsigned int flags;
> + size_t min_folio_bytes;
> int err = 0;
>
> /* "last_index" is the index of the folio beyond the end of the read */
> - last_index = round_up(iocb->ki_pos + count,
> - mapping_min_folio_nrbytes(mapping)) >> PAGE_SHIFT;
> + if (is_hugetlbfs)
> + min_folio_bytes = huge_page_size(hstate_file(filp));
> + else
> + min_folio_bytes = mapping_min_folio_nrbytes(mapping);
> + last_index = round_up(iocb->ki_pos + count, min_folio_bytes) >> PAGE_SHIFT;
I don't love this. Is there a way we can get mapping_min_folio_nrbytes()
to give us the right number for hugetlbfs? I don't see why it wouldn't
be possible ...
> filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
> +
> + if (is_hugetlbfs)
> + goto done;
We don't actually need this, do we? For hugetlbfs, I don't think we
can get 0 folios in the batch, and then we won't find a folio with
readahead set, and they're always uptodate ... so we're just skipping a
few tests with this?