From: "Kiryl Shutsemau (Meta)" <[email protected]>

Neither half of the name holds.  A bit is set only after the PTE has
passed every check the scan makes: uffd, lazyfree, anonymity and sharing
among them.  Presence is the first of those criteria, not the whole of
it.

mthp_collapse() then reads the bitmap starting at the PMD order, so the
bitmap is not specific to mTHP either.

Name the bitmap for what a set bit means: the scan accepted that PTE as
a collapse source.

No functional change.

Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <[email protected]>
---
 mm/collapse.h   |  4 ++--
 mm/khugepaged.c | 13 ++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/mm/collapse.h b/mm/collapse.h
index 26dbac7beddd..9c82e71533df 100644
--- a/mm/collapse.h
+++ b/mm/collapse.h
@@ -53,8 +53,8 @@ struct collapse_control {
        /* nodemask for allocation fallback */
        nodemask_t alloc_nmask;
 
-       /* Each bit represents a single occupied (!none/zero) page. */
-       DECLARE_BITMAP(mthp_present_ptes, MAX_PTRS_PER_PTE);
+       /* Each bit marks a PTE the scan accepted as a collapse source */
+       DECLARE_BITMAP(eligible_ptes, MAX_PTRS_PER_PTE);
 };
 
 #endif /* __MM_COLLAPSE_H */
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 804b1d35f52a..a12aafae8d9c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -576,7 +576,7 @@ static void collapse_control_init_scan(struct 
collapse_control *cc)
 {
        memset(cc->node_load, 0, sizeof(cc->node_load));
        nodes_clear(cc->alloc_nmask);
-       bitmap_zero(cc->mthp_present_ptes, MAX_PTRS_PER_PTE);
+       bitmap_zero(cc->eligible_ptes, MAX_PTRS_PER_PTE);
 }
 
 static void release_pte_folio(struct folio *folio)
@@ -1437,8 +1437,8 @@ static unsigned int max_order_from_offset(unsigned int 
offset)
  * mthp_collapse() consumes the bitmap that is generated during
  * collapse_scan_pmd() to determine what regions and mTHP orders fit best.
  *
- * Each bit in cc->mthp_present_ptes represents a single occupied (!none/zero)
- * page. We start at the PMD order and check if it is eligible for collapse;
+ * Each bit in cc->eligible_ptes marks a PTE the scan accepted as a collapse
+ * source. We start at the PMD order and check if it is eligible for collapse;
  * if not, we check the left and right halves of the PTE page table we are
  * examining at a lower order.
  *
@@ -1469,12 +1469,12 @@ static enum scan_result mthp_collapse(struct mm_struct 
*mm,
                        goto next_order;
 
                max_ptes_none = collapse_max_ptes_none(cc, NULL, order);
-               nr_occupied_ptes = bitmap_weight_from(cc->mthp_present_ptes, 
offset,
+               nr_occupied_ptes = bitmap_weight_from(cc->eligible_ptes, offset,
                                                      offset + nr_ptes);
 
                /*
                 * Swap PTEs accepted during the scan are counted in @unmapped,
-                * not in the present-PTE bitmap. Account them for the PMD-order
+                * not in the eligible bitmap. Account them for the PMD-order
                 * candidate.
                 */
                if (is_pmd_order(order))
@@ -1682,8 +1682,7 @@ static enum scan_result collapse_scan_pmd(struct 
mm_struct *mm,
                        }
                }
 
-               /* Set bit for occupied pages */
-               __set_bit(i, cc->mthp_present_ptes);
+               __set_bit(i, cc->eligible_ptes);
                /*
                 * Record which node the original page is from and save this
                 * information to cc->node_load[].
-- 
2.54.0


Reply via email to