From: Matthew Wilcox <willy@infradead.org>
To: Jane Chu <jane.chu@oracle.com>
Cc: akpm@linux-foundation.org, david@kernel.org,
muchun.song@linux.dev, osalvador@suse.de,
lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
vbabka@kernel.org, rppt@kernel.org, surenb@google.com,
mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org,
hughd@google.com, baolin.wang@linux.alibaba.com,
peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] hugetlb: open-code hugetlb folio lookup index conversion
Date: Mon, 20 Apr 2026 19:27:15 +0100 [thread overview]
Message-ID: <aeZwAz6PcdlqSnJ2@casper.infradead.org> (raw)
In-Reply-To: <20260409234158.837786-2-jane.chu@oracle.com>
On Thu, Apr 09, 2026 at 05:41:52PM -0600, Jane Chu wrote:
> This patch removes `filemap_lock_hugetlb_folio()` and open-codes
> the index conversion at each call site, making it explicit when
> hugetlb code is translating a hugepage index into the base-page index
> expected by `filemap_lock_folio()`
I think this is too large a piece to break off in a single patch.
The first thing I did was look at hugetlbfs_read_iter() and wonder
why we're not able to use generic_file_read_iter() here? It used
to be necessary because we used to index the page cache in units
of hsize, but now we don't, it seems to me that we could use
generic_file_read_iter() instead.
Now, what hugetlbfs_read_iter() does have is support for hwpoison
handling. I suspect this is something we want in
generic_file_read_iter(), it's just nobody's done it yet.
So perhaps that's patch 1 -- add hwpoison support to
generic_file_read_iter(). Then patch 2 removes hugetlbfs_read_iter() in
favour of using generic_file_read_iter().
Patch 3 is purely this:
(and you can put my Reviewed-by on it).
> @@ -652,10 +652,10 @@ static void hugetlbfs_zero_partial_page(struct hstate *h,
> loff_t start,
> loff_t end)
> {
> - pgoff_t idx = start >> huge_page_shift(h);
> + pgoff_t index = start >> PAGE_SHIFT;
> struct folio *folio;
>
> - folio = filemap_lock_hugetlb_folio(h, mapping, idx);
> + folio = filemap_lock_folio(mapping, index);
> if (IS_ERR(folio))
> return;
>
Now for patch 4 ...
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index a786034ac95c..38b39eaf46cc 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5724,7 +5724,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
> * before we get page_table_lock.
> */
> new_folio = false;
> - folio = filemap_lock_hugetlb_folio(h, mapping, vmf->pgoff);
> + folio = filemap_lock_folio(mapping, vmf->pgoff << huge_page_order(h));
> if (IS_ERR(folio)) {
> size = i_size_read(mapping->host) >> huge_page_shift(h);
> if (vmf->pgoff >= size)
This points to a horrible problem. Everywhere else in the VM has
vmf->pgoff in PAGE_SIZE units, and of course hugetlb works in units of
hpagesize. So this is an entirely different piece of work where we
convert vmf->pgoff to be in units of PAGE_SIZE. That'll be fun!
> @@ -6208,7 +6208,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
>
> if (is_continue) {
> ret = -EFAULT;
> - folio = filemap_lock_hugetlb_folio(h, mapping, idx);
> + folio = filemap_lock_folio(mapping, idx << huge_page_order(h));
> if (IS_ERR(folio))
> goto out;
> folio_in_pagecache = true;
This is a much smaller (more contained) problem. At least idx is local
to this function, so you can calculate it using linear_page_index()
and modify the whole function.
Finally, you can delete filemap_lock_hugetlb_folio():
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 9c098a02a09e..c64c6e5e50f5 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -829,12 +829,6 @@ static inline unsigned int blocks_per_huge_page(struct hstate *h)
> return huge_page_size(h) / 512;
> }
>
> -static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
> - struct address_space *mapping, pgoff_t idx)
> -{
> - return filemap_lock_folio(mapping, idx << huge_page_order(h));
> -}
> -
> #include <asm/hugetlb.h>
>
> #ifndef is_hugepage_only_range
> @@ -1106,12 +1100,6 @@ static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio
> return NULL;
> }
>
> -static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
> - struct address_space *mapping, pgoff_t idx)
> -{
> - return NULL;
> -}
> -
> static inline int isolate_or_dissolve_huge_folio(struct folio *folio,
> struct list_head *list)
> {
next prev parent reply other threads:[~2026-04-20 18:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 23:41 [PATCH 0/6] hugetlb: normalize exported interfaces to use base-page indices Jane Chu
2026-04-09 23:41 ` [PATCH 1/6] hugetlb: open-code hugetlb folio lookup index conversion Jane Chu
2026-04-11 14:14 ` Mike Rapoport
2026-04-13 16:39 ` jane.chu
2026-04-13 16:22 ` Oscar Salvador
2026-04-13 16:30 ` jane.chu
2026-04-20 18:27 ` Matthew Wilcox [this message]
2026-04-09 23:41 ` [PATCH 2/6] hugetlb: remove the hugetlb_linear_page_index() helper Jane Chu
2026-04-13 16:48 ` Oscar Salvador
2026-04-09 23:41 ` [PATCH 3/6] hugetlb: make hugetlb_fault_mutex_hash() take PAGE_SIZE index Jane Chu
2026-04-10 11:24 ` Usama Arif
2026-04-10 17:51 ` jane.chu
2026-04-13 17:43 ` Oscar Salvador
2026-04-13 21:32 ` jane.chu
2026-04-09 23:41 ` [PATCH 4/6] hugetlb: drop vma_hugecache_offset() in favor of linear_page_index() Jane Chu
2026-04-14 9:53 ` Oscar Salvador
2026-04-14 17:14 ` jane.chu
2026-04-09 23:41 ` [PATCH 5/6] hugetlb: make hugetlb_add_to_page_cache() use PAGE_SIZE-based index Jane Chu
2026-04-14 10:23 ` Oscar Salvador
2026-04-09 23:41 ` [PATCH 6/6] hugetlb: pass hugetlb reservation ranges in base-page indices Jane Chu
2026-04-15 8:01 ` Oscar Salvador
2026-04-15 19:39 ` jane.chu
2026-04-10 6:45 ` [syzbot ci] Re: hugetlb: normalize exported interfaces to use " syzbot ci
2026-04-10 21:54 ` jane.chu
2026-04-15 8:03 ` [PATCH 0/6] " Oscar Salvador
2026-04-15 19:40 ` jane.chu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aeZwAz6PcdlqSnJ2@casper.infradead.org \
--to=willy@infradead.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=jane.chu@oracle.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox