Commit 8a8270af authored by Baolin Wang's avatar Baolin Wang Committed by Nanyong Sun
Browse files

mm: khugepaged: use the number of pages in the folio to check the reference count

mainline inclusion
from mainline-v6.12-rc1
commit d6b8f296e8d74d685627fd746558745c13b8bd32
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAXCD2

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

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

Use the number of pages in the folio to check the reference count as
preparation for supporting shmem mTHP collapse.

Link: https://lkml.kernel.org/r/9ea49262308de28957596cc6e8edc2d3a4f54659.1724140601.git.baolin.wang@linux.alibaba.com


Signed-off-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Cc: Barry Song <21cnbao@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarNanyong Sun <sunnanyong@huawei.com>
parent 274d54e5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2002,9 +2002,9 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
		VM_BUG_ON_FOLIO(folio != xa_load(xas.xa, index), folio);

		/*
		 * We control three references to the folio:
		 * We control 2 + nr_pages references to the folio:
		 *  - we hold a pin on it;
		 *  - one reference from page cache;
		 *  - nr_pages reference from page cache;
		 *  - one from lru_isolate_folio;
		 * If those are the only references, then any new usage
		 * of the folio will have to fetch it from the page
@@ -2012,7 +2012,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
		 * truncate, so any new usage will be blocked until we
		 * unlock folio after collapse/during rollback.
		 */
		if (folio_ref_count(folio) != 3) {
		if (folio_ref_count(folio) != 2 + folio_nr_pages(folio)) {
			result = SCAN_PAGE_COUNT;
			xas_unlock_irq(&xas);
			folio_putback_lru(folio);
@@ -2195,7 +2195,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
		folio_clear_active(folio);
		folio_clear_unevictable(folio);
		folio_unlock(folio);
		folio_put_refs(folio, 3);
		folio_put_refs(folio, 2 + folio_nr_pages(folio));
	}

	goto out;