Hi Gregory!

On 10/14/26 11:27 PM, Gregory Price (Meta) wrote:
> madvise(2) accepts a zero-length range, rejects an unaligned start, and
> reports an unmapped gap in the range with ENOMEM while still applying the
> advice to the mapped pages on either side.
> 
> Check each of these for both hints. Around the gap, only MADV_PAGEOUT has
> an effect the test can observe, so only MADV_PAGEOUT is checked for
> paging out both neighbours, after a control page shows that swap works.
> 
> Signed-off-by: Gregory Price (Meta) <[email protected]>
> ---

[...]

> +/*
> + * An unmapped gap in the range makes either hint fail with ENOMEM, after
> + * advising the mapped pages on both sides of the gap. Only MADV_PAGEOUT has
> + * an effect on those pages that the test can observe.
> + */
> +TEST_F(madvise, unmapped_gap_fails_after_advising)
> +{
> +     char *mapping, *control;
> +     bool swapped = false;
> +     int retry;
> +
> +     pin_to_current_cpu(_metadata);
> +
> +     /* Make sure MADV_PAGEOUT can swap at all before relying on it. */
> +     control = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
> +                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +     ASSERT_NE(control, MAP_FAILED);
> +     control[0] = 1;
> +     if (!pageout_until_swapped(_metadata, control, page_size,
> +                                self->pagemap_fd))
> +             SKIP(return, "MADV_PAGEOUT did not swap the page");

This test is checking for both MADV_COLD and MADV_PAGEOUT. So if we skip
here because we couldn't pageout, then we don't test for MADV_COLD
behaviour at all. Do we want it this way, or should the tests for both
of these be separate?

> +
> +     mapping = mmap(NULL, 3 * page_size, PROT_READ | PROT_WRITE,
> +                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +     ASSERT_NE(mapping, MAP_FAILED);
> +     mapping[0] = 1;
> +     mapping[2 * page_size] = 1;
> +     ASSERT_EQ(munmap(mapping + page_size, page_size), 0);
> +
> +     ASSERT_EQ(madvise(mapping, 3 * page_size, MADV_COLD), -1);
> +     ASSERT_EQ(errno, ENOMEM);
> +     ASSERT_EQ(mapping[0], 1);
> +     ASSERT_EQ(mapping[2 * page_size], 1);
> +
> +     for (retry = 0; retry < PAGEOUT_RETRIES && !swapped; retry++) {
> +             ASSERT_EQ(madvise(mapping, 3 * page_size, MADV_PAGEOUT), -1);
> +             ASSERT_EQ(errno, ENOMEM);
> +             swapped = pagemap_is_swapped(self->pagemap_fd, mapping) &&
> +                       pagemap_is_swapped(self->pagemap_fd,
> +                                          mapping + 2 * page_size);
> +             if (!swapped)
> +                     usleep(10000);
> +     }
> +     ASSERT_TRUE(swapped)
> +             TH_LOG("MADV_PAGEOUT did not page out both sides of the gap");
> +     ASSERT_EQ(mapping[0], 1);
> +     ASSERT_EQ(mapping[2 * page_size], 1);
> +
> +     ASSERT_EQ(munmap(mapping, page_size), 0);
> +     ASSERT_EQ(munmap(mapping + 2 * page_size, page_size), 0);
> +     ASSERT_EQ(munmap(control, page_size), 0);
> +}
> +
>  /* Neither hint may fault a swapped page back in. */
>  static void check_skips_swapped_pte(struct __test_metadata *_metadata,
>                                   int pagemap_fd, int advice)


Reply via email to