From: Oscar Salvador <osalvador@suse.de>
To: Jane Chu <jane.chu@oracle.com>
Cc: akpm@linux-foundation.org, david@kernel.org,
muchun.song@linux.dev, 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 6/6] hugetlb: pass hugetlb reservation ranges in base-page indices
Date: Wed, 15 Apr 2026 10:01:41 +0200 [thread overview]
Message-ID: <ad9F5duupm8Rn-Yw@localhost.localdomain> (raw)
In-Reply-To: <20260409234158.837786-7-jane.chu@oracle.com>
On Thu, Apr 09, 2026 at 05:41:57PM -0600, Jane Chu wrote:
> hugetlb_reserve_pages() consume indices in hugepage granularity although
> some callers naturally compute offsets in PAGE_SIZE units.
>
> Teach the reservation helpers to accept base-page index ranges and
> convert to hugepage indices internally before operating on the
> reservation map. This keeps the internal representation unchanged while
> making the API contract more uniform for callers.
>
> Update hugetlbfs and memfd call sites to pass base-page indices, and
> adjust the documentation to describe the new calling convention. Add
> alignment warnings in hugetlb_reserve_pages() to catch invalid ranges
> early.
>
> No functional changes.
>
> Signed-off-by: Jane Chu <jane.chu@oracle.com>
> ---
> Documentation/mm/hugetlbfs_reserv.rst | 12 +++++------
> fs/hugetlbfs/inode.c | 29 ++++++++++++---------------
> mm/hugetlb.c | 26 ++++++++++++++++--------
> mm/memfd.c | 9 +++++----
> 4 files changed, 42 insertions(+), 34 deletions(-)
>
> diff --git a/Documentation/mm/hugetlbfs_reserv.rst b/Documentation/mm/hugetlbfs_reserv.rst
> index a49115db18c7..60a52b28f0b4 100644
> --- a/Documentation/mm/hugetlbfs_reserv.rst
> +++ b/Documentation/mm/hugetlbfs_reserv.rst
> @@ -112,8 +112,8 @@ flag was specified in either the shmget() or mmap() call. If NORESERVE
> was specified, then this routine returns immediately as no reservations
> are desired.
>
> -The arguments 'from' and 'to' are huge page indices into the mapping or
> -underlying file. For shmget(), 'from' is always 0 and 'to' corresponds to
> +The arguments 'from' and 'to' are base page indices into the mapping or
> +underlying file. For shmget(), 'from' is always 0 and 'to' corresponds to
> the length of the segment/mapping. For mmap(), the offset argument could
> be used to specify the offset into the underlying file. In such a case,
> the 'from' and 'to' arguments have been adjusted by this offset.
> @@ -136,10 +136,10 @@ to indicate this VMA owns the reservations.
>
> The reservation map is consulted to determine how many huge page reservations
> are needed for the current mapping/segment. For private mappings, this is
> -always the value (to - from). However, for shared mappings it is possible that
> -some reservations may already exist within the range (to - from). See the
> -section :ref:`Reservation Map Modifications <resv_map_modifications>`
> -for details on how this is accomplished.
> +always the number of huge pages covered by the range [from, to). However,
> +for shared mappings it is possible that some reservations may already exist
> +within the range [from, to). See the section :ref:`Reservation Map Modifications
> +<resv_map_modifications>` for details on how this is accomplished.
>
> The mapping may be associated with a subpool. If so, the subpool is consulted
> to ensure there is sufficient space for the mapping. It is possible that the
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index a72d46ff7980..ec05ed30b70f 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -157,10 +157,8 @@ static int hugetlbfs_file_mmap_prepare(struct vm_area_desc *desc)
> if (inode->i_flags & S_PRIVATE)
> vma_flags_set(&vma_flags, VMA_NORESERVE_BIT);
>
> - if (hugetlb_reserve_pages(inode,
> - desc->pgoff >> huge_page_order(h),
> - len >> huge_page_shift(h), desc,
> - vma_flags) < 0)
> + if (hugetlb_reserve_pages(inode, desc->pgoff, len >> PAGE_SHIFT, desc,
> + vma_flags) < 0)
Ok, this is something that I have been thinking every time I looked
into hugetlb reserve code, but I think we should be really starting to
put some meaningful names for from and to, and pass that to
hugetlb_reserve_pages.
Because "desc->pgoff" and "len >> PAGE_SHIFT", meh, and it is not that
many places we need to touch, but we might want in clarity.
The same goes for hugetlb_unreserve_pages() of course.
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 47ef41b6fb2e..eb4ab5bd0c9f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6532,10 +6532,11 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
> }
[...]
> @@ -6558,6 +6560,12 @@ long hugetlb_reserve_pages(struct inode *inode,
> return -EINVAL;
> }
>
> + VM_WARN_ON(!IS_ALIGNED(from, 1UL << huge_page_order(h)));
> + VM_WARN_ON(!IS_ALIGNED(to, 1UL << huge_page_order(h)));
If we want to scream if someone passes us unaligned indices, we might
want to do the same in hugetlb_unreserve_pages() ?
> diff --git a/mm/memfd.c b/mm/memfd.c
> index 56c8833c4195..59c174c7533c 100644
> --- a/mm/memfd.c
> +++ b/mm/memfd.c
> @@ -80,14 +80,15 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t index)
> struct inode *inode = file_inode(memfd);
> struct hstate *h = hstate_file(memfd);
> long nr_resv;
> - pgoff_t idx;
> + pgoff_t next_index;
> int err = -ENOMEM;
>
> gfp_mask = htlb_alloc_mask(h);
> gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
> - idx = index >> huge_page_order(h);
> + next_index = index + pages_per_huge_page(h);
Trailing white space.
--
Oscar Salvador
SUSE Labs
next prev parent reply other threads:[~2026-04-15 8:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 23:41 [PATCH 0/6] hugetlb: normalize exported interfaces to use " 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-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 [this message]
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
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=ad9F5duupm8Rn-Yw@localhost.localdomain \
--to=osalvador@suse.de \
--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=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