Hi Gregory!

On 10/14/26 11:27 PM, Gregory Price (Meta) wrote:
> MADV_PAGEOUT only pages out file pages for a caller that owns the file or
> could open it for writing, per can_do_file_pageout(). Any other caller
> gets nothing from a shared file mapping, and only the anonymous COW pages
> from a private one.
> 
> Check that the owner of a read-only file can evict a clean page of it,
> once a writable file page shows that file pages can be paged out at all.
> That test runs as an unprivileged owner even when started as root, so
> that capabilities cannot stand in for ownership.
> 
> Also check that an unauthorized caller leaves a shared file page resident,
> and that it pages out the COW page of a private mapping but not the file
> page next to it. These need root to change credentials, and skip if that
> fails.
> 
> Signed-off-by: Gregory Price (Meta) <[email protected]>
> ---

[...]
>  
> +/*
> + * The owner of a file may page out its clean page-cache pages. Run as an
> + * unprivileged owner, so that capabilities cannot stand in for ownership.
> + */
> +TEST_F(madvise, pageout_evicts_owned_file_page)
> +{
> +     char *mapping, *control;
> +
> +     if (!geteuid() && !drop_privileges())
> +             SKIP(return, "could not drop privileges");
> +     pin_to_current_cpu(_metadata);

Is there a reason why we are pinning to the current CPU here and not in
the next two tests?

IIUC (please let me know if I am wrong here), without pinning, say in
the test pageout_private_file_reclaims_only_cow:

[...]

> + * A caller that neither owns nor may write a file may page out the anonymous
> + * COW pages of a private mapping of it, but must leave the file pages
> + * resident.
> + */
> +TEST_F(madvise, pageout_private_file_reclaims_only_cow)
> +{
> +     char *mapping;
> +     bool swapped;
> +
> +     if (geteuid())
> +             SKIP(return, "requires root to change credentials");
> +     mapping = map_temp_file(_metadata, 2 * page_size, MAP_PRIVATE,
> +                             0400);
> +     if (!drop_privileges())
> +             SKIP(return, "could not drop privileges");
> +
> +     ASSERT_EQ(mapping[0], 0);
> +     ASSERT_EQ(mapping[page_size], 0);
> +     mapping[0] = 1;

If both pages are on CPU 1's per CPU LRU batch here and then hte task
migrates to CPU 2 here

> +
> +     ASSERT_EQ(madvise(mapping, 2 * page_size, MADV_PAGEOUT), 0);

Then this can cause lru_add_drain() on CPU 2, and therefore both pages
do not reach the main LRU list. Thus they won't be reclaimed and the
test can skip here since the CoW page wasn't swapped.

> +     ASSERT_TRUE(pagemap_is_populated(self->pagemap_fd,
> +                                      mapping + page_size));
> +     swapped = pagemap_is_swapped(self->pagemap_fd, mapping);
> +     ASSERT_EQ(mapping[0], 1);
> +     ASSERT_EQ(mapping[page_size], 0);
> +     if (!swapped)
> +             SKIP(return, "MADV_PAGEOUT did not swap the COW page");

Also, here we skip if we couldn't swap out the CoW page. Won't it make
more sense to check with pageout_until_swapped() first if pages can be
skipped, and then fail here if the CoW page wasn't skipped after all the
retries, similar to how some other tests implement it?

> +
> +     ASSERT_EQ(munmap(mapping, 2 * page_size), 0);
> +}
> +
>  TEST_HARNESS_MAIN


Reply via email to