Skip to content

Commit e5251fd

Browse files
punitagrawaltorvalds
authored andcommitted
mm/hugetlb: introduce set_huge_swap_pte_at() helper
set_huge_pte_at(), an architecture callback to populate hugepage ptes, does not provide the range of virtual memory that is targeted. This leads to ambiguity when dealing with swap entries on architectures that support hugepages consisting of contiguous ptes. Fix the problem by introducing an overridable helper that is called when populating the page tables with swap entries. The size of the targeted region is provided to the helper to help determine the number of entries to be updated. Provide a default implementation that maintains the current behaviour. [[email protected]: v4] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: add an empty definition for set_huge_swap_pte_at()] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Punit Agrawal <[email protected]> Acked-by: Steve Capper <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9386fac commit e5251fd

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

include/linux/hugetlb.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,14 @@ static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
516516
{
517517
atomic_long_sub(l, &mm->hugetlb_usage);
518518
}
519+
520+
#ifndef set_huge_swap_pte_at
521+
static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
522+
pte_t *ptep, pte_t pte, unsigned long sz)
523+
{
524+
set_huge_pte_at(mm, addr, ptep, pte);
525+
}
526+
#endif
519527
#else /* CONFIG_HUGETLB_PAGE */
520528
struct hstate {};
521529
#define alloc_huge_page(v, a, r) NULL
@@ -565,6 +573,11 @@ static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
565573
static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
566574
{
567575
}
576+
577+
static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
578+
pte_t *ptep, pte_t pte, unsigned long sz)
579+
{
580+
}
568581
#endif /* CONFIG_HUGETLB_PAGE */
569582

570583
static inline spinlock_t *huge_pte_lock(struct hstate *h,

mm/hugetlb.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,9 +3276,10 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
32763276
*/
32773277
make_migration_entry_read(&swp_entry);
32783278
entry = swp_entry_to_pte(swp_entry);
3279-
set_huge_pte_at(src, addr, src_pte, entry);
3279+
set_huge_swap_pte_at(src, addr, src_pte,
3280+
entry, sz);
32803281
}
3281-
set_huge_pte_at(dst, addr, dst_pte, entry);
3282+
set_huge_swap_pte_at(dst, addr, dst_pte, entry, sz);
32823283
} else {
32833284
if (cow) {
32843285
huge_ptep_set_wrprotect(src, addr, src_pte);
@@ -4295,7 +4296,8 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
42954296

42964297
make_migration_entry_read(&entry);
42974298
newpte = swp_entry_to_pte(entry);
4298-
set_huge_pte_at(mm, address, ptep, newpte);
4299+
set_huge_swap_pte_at(mm, address, ptep,
4300+
newpte, huge_page_size(h));
42994301
pages++;
43004302
}
43014303
spin_unlock(ptl);

0 commit comments

Comments
 (0)