Commit 274d54e5 authored by Baolin Wang's avatar Baolin Wang Committed by Nanyong Sun
Browse files

mm: khugepaged: expand the is_refcount_suitable() to support file folios

mainline inclusion
from mainline-v6.12-rc1
commit fda6d4de064a9d37414df36d45836898fff5e165
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=fda6d4de064a9d37414df36d45836898fff5e165

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

Patch series "support shmem mTHP collapse", v2.

Shmem already supports mTHP allocation[1], and this patchset adds support
for shmem mTHP collapse, as well as adding relevant test cases.

This patch (of 5):

Expand the is_refcount_suitable() to support reference checks for file
folios, as preparation for supporting shmem mTHP collapse.

Link: https://lkml.kernel.org/r/cover.1724140601.git.baolin.wang@linux.alibaba.com
Link: https://lkml.kernel.org/r/eae4cb3195ebbb654bfb7967cb7261d4e4e7c7fa.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 4e53fbf9
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -555,12 +555,14 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte,

static bool is_refcount_suitable(struct folio *folio)
{
	int expected_refcount;
	int expected_refcount = folio_mapcount(folio);

	expected_refcount = folio_mapcount(folio);
	if (folio_test_swapcache(folio))
	if (!folio_test_anon(folio) || folio_test_swapcache(folio))
		expected_refcount += folio_nr_pages(folio);

	if (folio_test_private(folio))
		expected_refcount++;

	return folio_ref_count(folio) == expected_refcount;
}

@@ -2300,8 +2302,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr,
			break;
		}

		if (folio_ref_count(folio) !=
		    1 + folio_mapcount(folio) + folio_test_private(folio)) {
		if (!is_refcount_suitable(folio)) {
			result = SCAN_PAGE_COUNT;
			break;
		}