Re: [PATCH v2 1/1] selftests/proc: use RSS in /proc/pid/smaps_rollup tearing tests

From: Pedro Falcato

Date: Mon Nov 02 2026 - 08:11:04 EST


On Sun, Nov 01, 2026 at 11:01:00AM -0800, Andrew Morton wrote:
> On Sun, 1 Nov 2026 07:45:03 -0800 Suren Baghdasaryan <surenb@xxxxxxxxxx> wrote:
>
> > Pss metrics can be affected by map count even if VMA tree stays unchanged,
> > therefore tests checking VMA tree integrity can't use them. Use Rss instead
> > and pre-populate the VMAs so that Rss changes if a VMA gets skipped or
> > double-counted.
> >
> > To ensure all test VMAs are populated with anonymous pages, remain
> > mergeable across VMA operations, and do not have their Rss changed by
> > memory reclaim:
> > - Toggle PROT_EXEC instead of PROT_WRITE between adjacent test VMAs so
> > all test VMAs remain writable and MAP_POPULATE faults in anonymous pages
> > (rather than the shared zero page, which is not accounted in Rss).
> > - Use mprotect() instead of mmap(..., MAP_FIXED) in split_vma() and
> > merge_vma() so the first page of the split VMA stays resident.
> > mprotect(..., PROT_NONE) splits the VMA without unmapping the first page
> > (pte_present() remains true for PAGE_NONE PTEs), and
> > mprotect(..., self->mod_info->prot) merges it back. Both parts of the
> > split VMA retain their non-zero Rss.
> > - Lock all present pages in the child with mlockall(MCL_CURRENT |
> > MCL_FUTURE | MCL_ONFAULT) so memory pressure cannot reclaim pages and
> > alter Rss during the test.
> > - In remap_vma(), unlock next_addr before mremap(..., MREMAP_DONTUNMAP)
> > so next_addr is not split, use mmap(..., MAP_FIXED) in patch_vma() to
> > merge the middle VMA back into addr, and exclude smaps_rollup tests
> > from test_maps_tearing_from_remap since remapping moves and unmaps the
> > page from next_addr.
>
> Thanks. This is proving tricky.
>
> My evolving reviewbot still isn't happy:
>
> : This fixes the v1 RSS issues, but two things remain.
> :
> : Alternating PROT_EXEC breaks with READ_IMPLIES_EXEC: both mappings

This is nonsense btw. Not sure we'll ever support random personality()
flags being set on selftests.

--
Pedro