* [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page
@ 2025-04-18 16:57 nifan.cxl
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
` (4 more replies)
0 siblings, 5 replies; 16+ messages in thread
From: nifan.cxl @ 2025-04-18 16:57 UTC (permalink / raw)
To: muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, david, linux-mm, linux-kernel,
Fan Ni, Sidhartha Kumar
From: Fan Ni <fan.ni@samsung.com>
The function unmap_ref_private() has only user, which passes in
&folio->page. Let it take folio directly.
Signed-off-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
v2:
Picked up Reviewed-by tags;
v1:
https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#mbf9f3e8b49497755b414e1887b2376b3902ffb76
---
mm/hugetlb.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ccc4f08f8481..b5d1ac8290a7 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6064,7 +6064,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
* same region.
*/
static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
- struct page *page, unsigned long address)
+ struct folio *folio, unsigned long address)
{
struct hstate *h = hstate_vma(vma);
struct vm_area_struct *iter_vma;
@@ -6108,7 +6108,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
*/
if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER))
unmap_hugepage_range(iter_vma, address,
- address + huge_page_size(h), page, 0);
+ address + huge_page_size(h),
+ folio_page(folio, 0), 0);
}
i_mmap_unlock_write(mapping);
}
@@ -6231,8 +6232,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio,
hugetlb_vma_unlock_read(vma);
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
- unmap_ref_private(mm, vma, &old_folio->page,
- vmf->address);
+ unmap_ref_private(mm, vma, old_folio, vmf->address);
mutex_lock(&hugetlb_fault_mutex_table[hash]);
hugetlb_vma_lock_read(vma);
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
@ 2025-04-18 16:57 ` nifan.cxl
2025-04-22 8:52 ` David Hildenbrand
` (2 more replies)
2025-04-18 16:57 ` [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() " nifan.cxl
` (3 subsequent siblings)
4 siblings, 3 replies; 16+ messages in thread
From: nifan.cxl @ 2025-04-18 16:57 UTC (permalink / raw)
To: muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, david, linux-mm, linux-kernel,
Fan Ni, Sidhartha Kumar
From: Fan Ni <fan.ni@samsung.com>
The function unmap_hugepage_range() has two kinds of users:
1) unmap_ref_private(), which passes in the head page of a folio. Since
unmap_ref_private() already takes folio and there are no other uses
of the folio struct in the function, it is natural for
unmap_hugepage_range() to take folio also.
2) All other uses, which pass in NULL pointer.
In both cases, we can pass in folio. Refactor unmap_hugepage_range() to
take folio.
Signed-off-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
v2:
Picked up Reviewed-by tags;
v1:
https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m7ba630d783e08ae708453279579093d481c6e721
---
include/linux/hugetlb.h | 2 +-
mm/hugetlb.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index a57bed83c657..b7699f35c87f 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -128,7 +128,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *,
struct vm_area_struct *, struct vm_area_struct *);
void unmap_hugepage_range(struct vm_area_struct *,
- unsigned long, unsigned long, struct page *,
+ unsigned long, unsigned long, struct folio *folio,
zap_flags_t);
void __unmap_hugepage_range(struct mmu_gather *tlb,
struct vm_area_struct *vma,
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b5d1ac8290a7..3181dbe0c4bb 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6039,7 +6039,7 @@ void __hugetlb_zap_end(struct vm_area_struct *vma,
}
void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
- unsigned long end, struct page *ref_page,
+ unsigned long end, struct folio *ref_folio,
zap_flags_t zap_flags)
{
struct mmu_notifier_range range;
@@ -6051,7 +6051,8 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
mmu_notifier_invalidate_range_start(&range);
tlb_gather_mmu(&tlb, vma->vm_mm);
- __unmap_hugepage_range(&tlb, vma, start, end, ref_page, zap_flags);
+ __unmap_hugepage_range(&tlb, vma, start, end,
+ folio_page(ref_folio, 0), zap_flags);
mmu_notifier_invalidate_range_end(&range);
tlb_finish_mmu(&tlb);
@@ -6109,7 +6110,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER))
unmap_hugepage_range(iter_vma, address,
address + huge_page_size(h),
- folio_page(folio, 0), 0);
+ folio, 0);
}
i_mmap_unlock_write(mapping);
}
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
@ 2025-04-18 16:57 ` nifan.cxl
2025-04-22 8:56 ` David Hildenbrand
2025-04-23 3:19 ` Matthew Wilcox
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
` (2 subsequent siblings)
4 siblings, 2 replies; 16+ messages in thread
From: nifan.cxl @ 2025-04-18 16:57 UTC (permalink / raw)
To: muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, david, linux-mm, linux-kernel, Fan Ni
From: Fan Ni <fan.ni@samsung.com>
The function __unmap_hugepage_range() has two kinds of users:
1) unmap_hugepage_range(), which passes in the head page of a folio.
Since unmap_hugepage_range() already takes folio and there are no other
uses of the folio struct in the function, it is natural for
__unmap_hugepage_range() to take folio also.
2) All other uses, which pass in NULL pointer.
In both cases, we can pass in folio. Refactor __unmap_hugepage_range() to
take folio.
Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
v2: fixed issue mentioned here:
https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m2b9cc1743e1907e52658815b297b9d249474f387
v1:
https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m738e9e7f7d7fe4aab6b21782b4658dd65abf8fc4
---
include/linux/hugetlb.h | 4 ++--
mm/hugetlb.c | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index b7699f35c87f..ebaf95231934 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -133,7 +133,7 @@ void unmap_hugepage_range(struct vm_area_struct *,
void __unmap_hugepage_range(struct mmu_gather *tlb,
struct vm_area_struct *vma,
unsigned long start, unsigned long end,
- struct page *ref_page, zap_flags_t zap_flags);
+ struct folio *ref_folio, zap_flags_t zap_flags);
void hugetlb_report_meminfo(struct seq_file *);
int hugetlb_report_node_meminfo(char *buf, int len, int nid);
void hugetlb_show_meminfo_node(int nid);
@@ -452,7 +452,7 @@ static inline long hugetlb_change_protection(
static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
struct vm_area_struct *vma, unsigned long start,
- unsigned long end, struct page *ref_page,
+ unsigned long end, struct folio *ref_folio,
zap_flags_t zap_flags)
{
BUG();
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3181dbe0c4bb..7d280ab23784 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5833,7 +5833,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
unsigned long start, unsigned long end,
- struct page *ref_page, zap_flags_t zap_flags)
+ struct folio *ref_folio, zap_flags_t zap_flags)
{
struct mm_struct *mm = vma->vm_mm;
unsigned long address;
@@ -5910,8 +5910,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
* page is being unmapped, not a range. Ensure the page we
* are about to unmap is the actual page of interest.
*/
- if (ref_page) {
- if (page != ref_page) {
+ if (ref_folio) {
+ if (page != folio_page(ref_folio, 0)) {
spin_unlock(ptl);
continue;
}
@@ -5977,7 +5977,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
/*
* Bail out after unmapping reference page if supplied
*/
- if (ref_page)
+ if (ref_folio)
break;
}
tlb_end_vma(tlb, vma);
@@ -6052,7 +6052,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
tlb_gather_mmu(&tlb, vma->vm_mm);
__unmap_hugepage_range(&tlb, vma, start, end,
- folio_page(ref_folio, 0), zap_flags);
+ ref_folio, zap_flags);
mmu_notifier_invalidate_range_end(&range);
tlb_finish_mmu(&tlb);
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range()
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
2025-04-18 16:57 ` [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() " nifan.cxl
@ 2025-04-18 16:57 ` nifan.cxl
2025-04-21 15:08 ` Sidhartha Kumar
` (2 more replies)
2025-04-22 8:50 ` [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page David Hildenbrand
2025-04-23 3:17 ` Matthew Wilcox
4 siblings, 3 replies; 16+ messages in thread
From: nifan.cxl @ 2025-04-18 16:57 UTC (permalink / raw)
To: muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, david, linux-mm, linux-kernel, Fan Ni
From: Fan Ni <fan.ni@samsung.com>
In __unmap_hugepage_range(), the "page" pointer always points to the
first page of a huge page, which guarantees there is a folio associating
with it. Convert the "page" pointer to use folio.
Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
This is a new patch added to the series based on the discussion here:
https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m2b9cc1743e1907e52658815b297b9d249474f387
---
mm/hugetlb.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 7d280ab23784..8177a3fe47d7 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5840,7 +5840,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
pte_t *ptep;
pte_t pte;
spinlock_t *ptl;
- struct page *page;
+ struct folio *folio;
struct hstate *h = hstate_vma(vma);
unsigned long sz = huge_page_size(h);
bool adjust_reservation = false;
@@ -5904,14 +5904,14 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
continue;
}
- page = pte_page(pte);
+ folio = page_folio(pte_page(pte));
/*
* If a reference page is supplied, it is because a specific
* page is being unmapped, not a range. Ensure the page we
* are about to unmap is the actual page of interest.
*/
if (ref_folio) {
- if (page != folio_page(ref_folio, 0)) {
+ if (folio != ref_folio) {
spin_unlock(ptl);
continue;
}
@@ -5926,7 +5926,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
pte = huge_ptep_get_and_clear(mm, address, ptep, sz);
tlb_remove_huge_tlb_entry(h, tlb, ptep, address);
if (huge_pte_dirty(pte))
- set_page_dirty(page);
+ folio_mark_dirty(folio);
/* Leave a uffd-wp pte marker if needed */
if (huge_pte_uffd_wp(pte) &&
!(zap_flags & ZAP_FLAG_DROP_MARKER))
@@ -5934,7 +5934,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
make_pte_marker(PTE_MARKER_UFFD_WP),
sz);
hugetlb_count_sub(pages_per_huge_page(h), mm);
- hugetlb_remove_rmap(page_folio(page));
+ hugetlb_remove_rmap(folio);
/*
* Restore the reservation for anonymous page, otherwise the
@@ -5943,8 +5943,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
* reservation bit.
*/
if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
- folio_test_anon(page_folio(page))) {
- folio_set_hugetlb_restore_reserve(page_folio(page));
+ folio_test_anon(folio)) {
+ folio_set_hugetlb_restore_reserve(folio);
/* Reservation to be adjusted after the spin lock */
adjust_reservation = true;
}
@@ -5968,12 +5968,12 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
* count will not be incremented by free_huge_folio.
* Act as if we consumed the reservation.
*/
- folio_clear_hugetlb_restore_reserve(page_folio(page));
+ folio_clear_hugetlb_restore_reserve(folio);
else if (rc)
vma_add_reservation(h, vma, address);
}
- tlb_remove_page_size(tlb, page, huge_page_size(h));
+ tlb_remove_page_size(tlb, folio_page(folio, 0), huge_page_size(h));
/*
* Bail out after unmapping reference page if supplied
*/
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range()
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
@ 2025-04-21 15:08 ` Sidhartha Kumar
2025-04-22 9:00 ` David Hildenbrand
2025-04-23 3:22 ` Matthew Wilcox
2 siblings, 0 replies; 16+ messages in thread
From: Sidhartha Kumar @ 2025-04-21 15:08 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, david, linux-mm, linux-kernel, Fan Ni
On 4/18/25 12:57 PM, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> In __unmap_hugepage_range(), the "page" pointer always points to the
> first page of a huge page, which guarantees there is a folio associating
> with it. Convert the "page" pointer to use folio.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> ---
> This is a new patch added to the series based on the discussion here:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m2b9cc1743e1907e52658815b297b9d249474f387
> ---
> mm/hugetlb.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 7d280ab23784..8177a3fe47d7 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5840,7 +5840,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> pte_t *ptep;
> pte_t pte;
> spinlock_t *ptl;
> - struct page *page;
> + struct folio *folio;
> struct hstate *h = hstate_vma(vma);
> unsigned long sz = huge_page_size(h);
> bool adjust_reservation = false;
> @@ -5904,14 +5904,14 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> continue;
> }
>
> - page = pte_page(pte);
> + folio = page_folio(pte_page(pte));
> /*
> * If a reference page is supplied, it is because a specific
> * page is being unmapped, not a range. Ensure the page we
> * are about to unmap is the actual page of interest.
> */
> if (ref_folio) {
> - if (page != folio_page(ref_folio, 0)) {
> + if (folio != ref_folio) {
> spin_unlock(ptl);
> continue;
> }
> @@ -5926,7 +5926,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> pte = huge_ptep_get_and_clear(mm, address, ptep, sz);
> tlb_remove_huge_tlb_entry(h, tlb, ptep, address);
> if (huge_pte_dirty(pte))
> - set_page_dirty(page);
> + folio_mark_dirty(folio);
> /* Leave a uffd-wp pte marker if needed */
> if (huge_pte_uffd_wp(pte) &&
> !(zap_flags & ZAP_FLAG_DROP_MARKER))
> @@ -5934,7 +5934,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> make_pte_marker(PTE_MARKER_UFFD_WP),
> sz);
> hugetlb_count_sub(pages_per_huge_page(h), mm);
> - hugetlb_remove_rmap(page_folio(page));
> + hugetlb_remove_rmap(folio);
>
> /*
> * Restore the reservation for anonymous page, otherwise the
> @@ -5943,8 +5943,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> * reservation bit.
> */
> if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
> - folio_test_anon(page_folio(page))) {
> - folio_set_hugetlb_restore_reserve(page_folio(page));
> + folio_test_anon(folio)) {
> + folio_set_hugetlb_restore_reserve(folio);
> /* Reservation to be adjusted after the spin lock */
> adjust_reservation = true;
> }
> @@ -5968,12 +5968,12 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> * count will not be incremented by free_huge_folio.
> * Act as if we consumed the reservation.
> */
> - folio_clear_hugetlb_restore_reserve(page_folio(page));
> + folio_clear_hugetlb_restore_reserve(folio);
> else if (rc)
> vma_add_reservation(h, vma, address);
> }
>
> - tlb_remove_page_size(tlb, page, huge_page_size(h));
> + tlb_remove_page_size(tlb, folio_page(folio, 0), huge_page_size(h));
> /*
> * Bail out after unmapping reference page if supplied
> */
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
` (2 preceding siblings ...)
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
@ 2025-04-22 8:50 ` David Hildenbrand
2025-04-23 3:17 ` Matthew Wilcox
4 siblings, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2025-04-22 8:50 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, linux-mm, linux-kernel, Fan Ni,
Sidhartha Kumar
On 18.04.25 18:57, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> The function unmap_ref_private() has only user, which passes in
> &folio->page. Let it take folio directly.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> Reviewed-by: Muchun Song <muchun.song@linux.dev>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> v2:
> Picked up Reviewed-by tags;
>
> v1:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#mbf9f3e8b49497755b414e1887b2376b3902ffb76
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
@ 2025-04-22 8:52 ` David Hildenbrand
2025-04-22 8:55 ` David Hildenbrand
2025-04-23 3:15 ` Matthew Wilcox
2 siblings, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2025-04-22 8:52 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, linux-mm, linux-kernel, Fan Ni,
Sidhartha Kumar
On 18.04.25 18:57, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> The function unmap_hugepage_range() has two kinds of users:
> 1) unmap_ref_private(), which passes in the head page of a folio. Since
> unmap_ref_private() already takes folio and there are no other uses
> of the folio struct in the function, it is natural for
> unmap_hugepage_range() to take folio also.
> 2) All other uses, which pass in NULL pointer.
>
> In both cases, we can pass in folio. Refactor unmap_hugepage_range() to
> take folio.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> Reviewed-by: Muchun Song <muchun.song@linux.dev>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> v2:
> Picked up Reviewed-by tags;
>
> v1:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m7ba630d783e08ae708453279579093d481c6e721
> ---
> include/linux/hugetlb.h | 2 +-
> mm/hugetlb.c | 7 ++++---
> 2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index a57bed83c657..b7699f35c87f 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -128,7 +128,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
> int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *,
> struct vm_area_struct *, struct vm_area_struct *);
> void unmap_hugepage_range(struct vm_area_struct *,
> - unsigned long, unsigned long, struct page *,
> + unsigned long, unsigned long, struct folio *folio,
> zap_flags_t);
Note that no parameters are using names. While I am not a big fan of
that in general, we should keep it consistent.
Either name all or none.
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
2025-04-22 8:52 ` David Hildenbrand
@ 2025-04-22 8:55 ` David Hildenbrand
2025-04-23 3:15 ` Matthew Wilcox
2 siblings, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2025-04-22 8:55 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, linux-mm, linux-kernel, Fan Ni,
Sidhartha Kumar
On 18.04.25 18:57, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> The function unmap_hugepage_range() has two kinds of users:
> 1) unmap_ref_private(), which passes in the head page of a folio. Since
> unmap_ref_private() already takes folio and there are no other uses
> of the folio struct in the function, it is natural for
> unmap_hugepage_range() to take folio also.
> 2) All other uses, which pass in NULL pointer.
>
> In both cases, we can pass in folio. Refactor unmap_hugepage_range() to
> take folio.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> Reviewed-by: Muchun Song <muchun.song@linux.dev>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> v2:
> Picked up Reviewed-by tags;
>
> v1:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m7ba630d783e08ae708453279579093d481c6e721
> ---
> include/linux/hugetlb.h | 2 +-
> mm/hugetlb.c | 7 ++++---
> 2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index a57bed83c657..b7699f35c87f 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -128,7 +128,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
> int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *,
> struct vm_area_struct *, struct vm_area_struct *);
> void unmap_hugepage_range(struct vm_area_struct *,
> - unsigned long, unsigned long, struct page *,
> + unsigned long, unsigned long, struct folio *folio,
> zap_flags_t);
> void __unmap_hugepage_range(struct mmu_gather *tlb,
> struct vm_area_struct *vma,
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index b5d1ac8290a7..3181dbe0c4bb 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6039,7 +6039,7 @@ void __hugetlb_zap_end(struct vm_area_struct *vma,
> }
>
> void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
> - unsigned long end, struct page *ref_page,
> + unsigned long end, struct folio *ref_folio,
> zap_flags_t zap_flags)
Oh, and now I realize that you call it "folio" above and "ref_folio" here.
Can we just rename it to "folio" consistently or is there a reason to
use the weird "ref_" prefix?
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 ` [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() " nifan.cxl
@ 2025-04-22 8:56 ` David Hildenbrand
2025-04-23 3:19 ` Matthew Wilcox
1 sibling, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2025-04-22 8:56 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, linux-mm, linux-kernel, Fan Ni
On 18.04.25 18:57, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> The function __unmap_hugepage_range() has two kinds of users:
> 1) unmap_hugepage_range(), which passes in the head page of a folio.
> Since unmap_hugepage_range() already takes folio and there are no other
> uses of the folio struct in the function, it is natural for
> __unmap_hugepage_range() to take folio also.
> 2) All other uses, which pass in NULL pointer.
>
> In both cases, we can pass in folio. Refactor __unmap_hugepage_range() to
> take folio.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> ---
> v2: fixed issue mentioned here:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m2b9cc1743e1907e52658815b297b9d249474f387
>
> v1:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m738e9e7f7d7fe4aab6b21782b4658dd65abf8fc4
> ---
>
> include/linux/hugetlb.h | 4 ++--
> mm/hugetlb.c | 10 +++++-----
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index b7699f35c87f..ebaf95231934 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -133,7 +133,7 @@ void unmap_hugepage_range(struct vm_area_struct *,
> void __unmap_hugepage_range(struct mmu_gather *tlb,
> struct vm_area_struct *vma,
> unsigned long start, unsigned long end,
> - struct page *ref_page, zap_flags_t zap_flags);
> + struct folio *ref_folio, zap_flags_t zap_flags);
> void hugetlb_report_meminfo(struct seq_file *);
> int hugetlb_report_node_meminfo(char *buf, int len, int nid);
> void hugetlb_show_meminfo_node(int nid);
> @@ -452,7 +452,7 @@ static inline long hugetlb_change_protection(
>
> static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
> struct vm_area_struct *vma, unsigned long start,
> - unsigned long end, struct page *ref_page,
> + unsigned long end, struct folio *ref_folio,
> zap_flags_t zap_flags)
> {
Same comment as for the previous patch, can we just call this "folio"
instead of "ref_folio" if we are already touching it?
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range()
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
2025-04-21 15:08 ` Sidhartha Kumar
@ 2025-04-22 9:00 ` David Hildenbrand
2025-04-23 3:22 ` Matthew Wilcox
2 siblings, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2025-04-22 9:00 UTC (permalink / raw)
To: nifan.cxl, muchun.song, willy
Cc: mcgrof, a.manzanares, dave, akpm, linux-mm, linux-kernel, Fan Ni
On 18.04.25 18:57, nifan.cxl@gmail.com wrote:
> From: Fan Ni <fan.ni@samsung.com>
>
> In __unmap_hugepage_range(), the "page" pointer always points to the
> first page of a huge page, which guarantees there is a folio associating
> with it. Convert the "page" pointer to use folio.
>
> Signed-off-by: Fan Ni <fan.ni@samsung.com>
> ---
> This is a new patch added to the series based on the discussion here:
> https://lore.kernel.org/linux-mm/aAHUluy7T32ZlYg7@debian/T/#m2b9cc1743e1907e52658815b297b9d249474f387
> ---
> mm/hugetlb.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 7d280ab23784..8177a3fe47d7 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5840,7 +5840,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> pte_t *ptep;
> pte_t pte;
> spinlock_t *ptl;
> - struct page *page;
> + struct folio *folio;
> struct hstate *h = hstate_vma(vma);
> unsigned long sz = huge_page_size(h);
> bool adjust_reservation = false;
> @@ -5904,14 +5904,14 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> continue;
> }
>
> - page = pte_page(pte);
> + folio = page_folio(pte_page(pte));
> /*
> * If a reference page is supplied, it is because a specific
> * page is being unmapped, not a range. Ensure the page we
> * are about to unmap is the actual page of interest.
> */
> if (ref_folio) {
> - if (page != folio_page(ref_folio, 0)) {
> + if (folio != ref_folio) {
> spin_unlock(ptl);
> continue;
> }
What about something like (keeping in mind that I suggest renaming
"ref_folio" -> "folio" in previous patches)
const bool folio_provided = !!folio;
...
if (folio_provided) {
if (folio != page_folio(pte_page(pte))) {
spin_unlock(ptl);
continue;
}
...
} else {
folio = page_folio(pte_page(pte);
}
...
if (folio_supplied)
break;
...
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
2025-04-22 8:52 ` David Hildenbrand
2025-04-22 8:55 ` David Hildenbrand
@ 2025-04-23 3:15 ` Matthew Wilcox
2 siblings, 0 replies; 16+ messages in thread
From: Matthew Wilcox @ 2025-04-23 3:15 UTC (permalink / raw)
To: nifan.cxl
Cc: muchun.song, mcgrof, a.manzanares, dave, akpm, david, linux-mm,
linux-kernel, Fan Ni, Sidhartha Kumar
On Fri, Apr 18, 2025 at 09:57:40AM -0700, nifan.cxl@gmail.com wrote:
> void unmap_hugepage_range(struct vm_area_struct *,
> - unsigned long, unsigned long, struct page *,
> + unsigned long, unsigned long, struct folio *folio,
I'm fine with leaving the vma and folio unnamed, but it is a crime
against our fellow programmers to leave the two 'unsigned long's
unnamed. What the hell are they?
> void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
> - unsigned long end, struct page *ref_page,
> + unsigned long end, struct folio *ref_folio,
... start and end. I'd happily see a patch which only named those
parameters and left the struct folio unnamed.
> - __unmap_hugepage_range(&tlb, vma, start, end, ref_page, zap_flags);
> + __unmap_hugepage_range(&tlb, vma, start, end,
> + folio_page(ref_folio, 0), zap_flags);
I do not like this. Why should we pass in the first page here? It
seems to me that this is just "Now we will call a function which still
takes a struct page", and we *SHOULD* use &folio->page here to indicate
that we just haven't done the conversion yet.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
` (3 preceding siblings ...)
2025-04-22 8:50 ` [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page David Hildenbrand
@ 2025-04-23 3:17 ` Matthew Wilcox
2025-04-25 1:11 ` Fan Ni
4 siblings, 1 reply; 16+ messages in thread
From: Matthew Wilcox @ 2025-04-23 3:17 UTC (permalink / raw)
To: nifan.cxl
Cc: muchun.song, mcgrof, a.manzanares, dave, akpm, david, linux-mm,
linux-kernel, Fan Ni, Sidhartha Kumar
With regard to the Subject: line, you're not "refactoring". You're
passing a folio to the function.
> @@ -6108,7 +6108,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
> */
> if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER))
> unmap_hugepage_range(iter_vma, address,
> - address + huge_page_size(h), page, 0);
> + address + huge_page_size(h),
> + folio_page(folio, 0), 0);
As previously, use &folio->page here.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page
2025-04-18 16:57 ` [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() " nifan.cxl
2025-04-22 8:56 ` David Hildenbrand
@ 2025-04-23 3:19 ` Matthew Wilcox
1 sibling, 0 replies; 16+ messages in thread
From: Matthew Wilcox @ 2025-04-23 3:19 UTC (permalink / raw)
To: nifan.cxl
Cc: muchun.song, mcgrof, a.manzanares, dave, akpm, david, linux-mm,
linux-kernel, Fan Ni
On Fri, Apr 18, 2025 at 09:57:41AM -0700, nifan.cxl@gmail.com wrote:
> @@ -5910,8 +5910,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
> * page is being unmapped, not a range. Ensure the page we
> * are about to unmap is the actual page of interest.
> */
> - if (ref_page) {
> - if (page != ref_page) {
> + if (ref_folio) {
> + if (page != folio_page(ref_folio, 0)) {
I think this is actually wrong. Shouldn't it be:
if (page_folio(page) != ref_folio)
so that it doesn't matter which page in the folio we found; we just need
to know if the page belongs to the same folio or not?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range()
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
2025-04-21 15:08 ` Sidhartha Kumar
2025-04-22 9:00 ` David Hildenbrand
@ 2025-04-23 3:22 ` Matthew Wilcox
2025-04-23 22:17 ` Andrew Morton
2 siblings, 1 reply; 16+ messages in thread
From: Matthew Wilcox @ 2025-04-23 3:22 UTC (permalink / raw)
To: nifan.cxl
Cc: muchun.song, mcgrof, a.manzanares, dave, akpm, david, linux-mm,
linux-kernel, Fan Ni
On Fri, Apr 18, 2025 at 09:57:42AM -0700, nifan.cxl@gmail.com wrote:
>
> - tlb_remove_page_size(tlb, page, huge_page_size(h));
> + tlb_remove_page_size(tlb, folio_page(folio, 0), huge_page_size(h));
Surely this should be:
tlb_remove_page_size(tlb, folio_page(folio, 0), folio_size(folio));
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range()
2025-04-23 3:22 ` Matthew Wilcox
@ 2025-04-23 22:17 ` Andrew Morton
0 siblings, 0 replies; 16+ messages in thread
From: Andrew Morton @ 2025-04-23 22:17 UTC (permalink / raw)
To: Matthew Wilcox
Cc: nifan.cxl, muchun.song, mcgrof, a.manzanares, dave, david,
linux-mm, linux-kernel, Fan Ni
On Wed, 23 Apr 2025 04:22:42 +0100 Matthew Wilcox <willy@infradead.org> wrote:
> On Fri, Apr 18, 2025 at 09:57:42AM -0700, nifan.cxl@gmail.com wrote:
> >
> > - tlb_remove_page_size(tlb, page, huge_page_size(h));
> > + tlb_remove_page_size(tlb, folio_page(folio, 0), huge_page_size(h));
>
> Surely this should be:
> tlb_remove_page_size(tlb, folio_page(folio, 0), folio_size(folio));
Thanks, I removed this version of the series from mm.git's mm-new branch.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page
2025-04-23 3:17 ` Matthew Wilcox
@ 2025-04-25 1:11 ` Fan Ni
0 siblings, 0 replies; 16+ messages in thread
From: Fan Ni @ 2025-04-25 1:11 UTC (permalink / raw)
To: Matthew Wilcox
Cc: nifan.cxl, muchun.song, mcgrof, a.manzanares, dave, akpm, david,
linux-mm, linux-kernel, Sidhartha Kumar
On Wed, Apr 23, 2025 at 04:17:25AM +0100, Matthew Wilcox wrote:
>
> With regard to the Subject: line, you're not "refactoring". You're
> passing a folio to the function.
Hi Matthew,
Thanks for the review.
Are you suggesting something like "Passing folio instead of page to unmap_ref_private()"?
We do not change the behavior of the function, but only the interface, it
is kind of "refactoring" to me.
Fan
>
> > @@ -6108,7 +6108,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
> > */
> > if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER))
> > unmap_hugepage_range(iter_vma, address,
> > - address + huge_page_size(h), page, 0);
> > + address + huge_page_size(h),
> > + folio_page(folio, 0), 0);
>
> As previously, use &folio->page here.
>
>
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2025-04-25 1:11 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-18 16:57 [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page nifan.cxl
2025-04-18 16:57 ` [PATCH v2 2/4] mm/hugetlb: Refactor unmap_hugepage_range() " nifan.cxl
2025-04-22 8:52 ` David Hildenbrand
2025-04-22 8:55 ` David Hildenbrand
2025-04-23 3:15 ` Matthew Wilcox
2025-04-18 16:57 ` [PATCH v2 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() " nifan.cxl
2025-04-22 8:56 ` David Hildenbrand
2025-04-23 3:19 ` Matthew Wilcox
2025-04-18 16:57 ` [PATCH v2 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() nifan.cxl
2025-04-21 15:08 ` Sidhartha Kumar
2025-04-22 9:00 ` David Hildenbrand
2025-04-23 3:22 ` Matthew Wilcox
2025-04-23 22:17 ` Andrew Morton
2025-04-22 8:50 ` [PATCH v2 1/4] mm/hugetlb: Refactor unmap_ref_private() to take folio instead of page David Hildenbrand
2025-04-23 3:17 ` Matthew Wilcox
2025-04-25 1:11 ` Fan Ni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox