All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sarthak Sharma" <sarthak.sharma@arm.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"David Hildenbrand" <david@kernel.org>
Cc: "Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>, "Shuah Khan" <shuah@kernel.org>,
	"Zi Yan" <ziy@nvidia.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>,
	"Anshuman Khandual" <anshuman.khandual@arm.com>,
	"Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH 4/4] selftests/mm: add a THP compaction selftest
Date: Fri, 13 Nov 2026 09:03:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-212498@kernel.org> (raw)
In-Reply-To: <20261112090250.334344-5-sarthak.sharma@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests/mm: unwritten last_page freed via zero page on
  split in main()
- [Low] selftests/mm: missing MADV_NOHUGEPAGE before split_huge_pages()
  in main()
--

commit 8fc76b939a1f641b9678f19aaded037c1f80ae5b
Author: Sarthak Sharma <sarthak.sharma@arm.com>

selftests/mm: add a THP compaction selftest

This commit adds a selftest that allocates PMD-sized THPs, splits them to
order 0 while retaining one base page per range, and verifies that a
subsequent mapping can recover THPs via memory compaction.

> diff --git a/tools/testing/selftests/mm/thp-compaction.c b/tools/testing/selftests/mm/thp-compaction.c
> new file mode 100644
> index 0000000000000..8935f1968a6da
> --- /dev/null
> +++ b/tools/testing/selftests/mm/thp-compaction.c
> @@ -0,0 +1,215 @@

[ ... ]

> +int main(void)
> +{

[ ... ]

> +	/*
> +	 * Split all allocated THPs to order 0, keeping only the final base page
> +	 * from each THP
> +	 */
> +	for (size_t i = 0; i < nr_initial; i++) {
> +		p = initial + i * pmd_size;
> +		last_page = p + pmd_size - psize();
> +
> +		if (!is_backed_by_folio(p, pmd_order, pagemap_fd, kpageflags_fd)) {
> +			ksft_test_result_skip(
> +				"Initial range is not backed by a resident PMD sized folio\n");
> +			ksft_finished();
> +		}
> +
> +		initial_pfns[i] = pagemap_get_pfn(pagemap_fd, p);
> +
> +		split_huge_pages(p, psize(), 0);
> +		if (!is_backed_by_folio(last_page, 0, pagemap_fd, kpageflags_fd)) {
> +			ksft_test_result_fail("Failed to split THP to order 0\n");
> +			ksft_finished();
> +		}
> +		if (madvise(p, pmd_size - psize(), MADV_DONTNEED))
> +			ksft_exit_fail_perror("MADV_DONTNEED");
> +	}

[Severity: Medium]
Does split_huge_pages() replace last_page with the shared zero page and
free its physical page?

allocate_transhuge() only writes to the first word at p, leaving last_page
zero-filled.  When splitting an anonymous THP to order 0,
__folio_freeze_split_anon() passes TTU_USE_SHARED_ZEROPAGE to
remap_anon_folio(), which remaps zero-filled tail pages to the shared zero
page and frees their physical folios.  madvise(MADV_DONTNEED) then frees
subpage 0, leaving the entire PMD range free in the buddy allocator rather
than fragmented.  Because the shared zero page is present in pagemap and
has no compound flags in kpageflags, both is_backed_by_folio() and
PAGEMAP_PRESENT() succeed, so the retry phase allocates from free buddy
pages without exercising compaction.

Writing non-zero data to last_page before split_huge_pages() will keep the
physical tail page mapped.

[Severity: Low]
Could khugepaged collapse ranges in initial back into THPs during the split
and retry loops?

allocate_transhuge() calls madvise(MADV_HUGEPAGE) on each range in initial,
registering the VMA with khugepaged.  Without clearing VM_HUGEPAGE before
splitting, khugepaged can collapse p before is_backed_by_folio() checks the
order-0 split, or collapse the single-page-retained ranges (which have
HPAGE_PMD_NR - 1 pte_none entries, matching the default max_ptes_none) and
consume compacted THPs meant for the retry mapping.  Calling
madvise(MADV_NOHUGEPAGE) on initial before the split loop would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112090250.334344-1-sarthak.sharma@arm.com?part=4


      reply	other threads:[~2026-11-13  9:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  9:02 [PATCH 0/4] selftests/mm: replace transhuge-stress with a THP compaction selftest Sarthak Sharma
2026-11-12  9:02 ` [PATCH 1/4] selftests/mm: remove transhuge-stress Sarthak Sharma
2026-11-12  9:02 ` [PATCH 2/4] selftests/mm: detect masked PFNs in allocate_transhuge() Sarthak Sharma
2026-11-12  9:02 ` [PATCH 3/4] selftests/mm: factor out THP split helpers Sarthak Sharma
2026-11-12  9:02 ` [PATCH 4/4] selftests/mm: add a THP compaction selftest Sarthak Sharma
2026-11-13  9:03   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-212498@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sarthak.sharma@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.