Commit 2c13d1d0 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Liu Shixin
Browse files

mm: add pmd_folio()

mainline inclusion
from mainline-v6.10-rc1
commit e06d03d5590ae1c257b8aa2cfbfe6765e0755c14
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAIHQO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e06d03d5590ae1c257b8aa2cfbfe6765e0755c14

--------------------------------

Convert directly from a pmd to a folio without going through another
representation first.  For now this is just a slightly shorter way to
write it, but it might end up being more efficient later.

Link: https://lkml.kernel.org/r/20240326202833.523759-4-willy@infradead.org


Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Conflicts:
	mm/mempolicy.c
	mm/userfaultfd.c
[ Context conflicts in mm/mempolicy.c due to miss commit 5beaee54a324.
  Not covert in mm/userfaultfd.c due to miss commit adef440691ba ]
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent 66b4f555
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@
#define pmd_pgtable(pmd) pmd_page(pmd)
#endif

#define pmd_folio(pmd) page_folio(pmd_page(pmd))

/*
 * A page table page can be thought of an array like this: pXd_t[PTRS_PER_PxD]
 *
+3 −3
Original line number Diff line number Diff line
@@ -2066,7 +2066,7 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
		goto out;
	}

	folio = pfn_folio(pmd_pfn(orig_pmd));
	folio = pmd_folio(orig_pmd);
	/*
	 * If other processes are mapping this folio, we couldn't discard
	 * the folio unless they all do MADV_FREE so let's skip the folio.
@@ -2337,7 +2337,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
		if (pmd_protnone(*pmd))
			goto unlock;

		folio = page_folio(pmd_page(*pmd));
		folio = pmd_folio(*pmd);
		toptier = node_is_toptier(folio_nid(folio));
		/*
		 * Skip scanning top tier node if normal numa
@@ -2776,7 +2776,7 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
		 * It's safe to call pmd_page when folio is set because it's
		 * guaranteed that pmd is present.
		 */
		if (folio && folio != page_folio(pmd_page(*pmd)))
		if (folio && folio != pmd_folio(*pmd))
			goto out;
		__split_huge_pmd_locked(vma, pmd, range.start, freeze);
	}
+1 −1
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
			goto huge_unlock;
		}

		folio = pfn_folio(pmd_pfn(orig_pmd));
		folio = pmd_folio(orig_pmd);

		/* Do not interfere with other mappings of this folio */
		if (folio_likely_mapped_shared(folio))
+1 −1
Original line number Diff line number Diff line
@@ -471,7 +471,7 @@ static int queue_folios_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr,
		ret = -EIO;
		goto unlock;
	}
	folio = pfn_folio(pmd_pfn(*pmd));
	folio = pmd_folio(*pmd);
	if (is_huge_zero_page(&folio->page)) {
		walk->action = ACTION_CONTINUE;
		goto unlock;
+1 −1
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr,
			goto out;
		if (is_huge_zero_pmd(*pmd))
			goto out;
		folio = page_folio(pmd_page(*pmd));
		folio = pmd_folio(*pmd);
		if (vma->vm_flags & VM_LOCKED)
			mlock_folio(folio);
		else