Re: [PATCH] selftests/mm: use volatile keyword to not optimize mmap read variable

From: Zi Yan
Date: Thu Jun 06 2024 - 11:23:07 EST


On 6 Jun 2024, at 7:35, Matthew Wilcox wrote:

> On Thu, Jun 06, 2024 at 01:58:35PM +0000, Pankaj Raghav (Samsung) wrote:
>> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
>> @@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
>> char **addr)
>> {
>> size_t i;
>> - int __attribute__((unused)) dummy = 0;
>> + volatile int __attribute__((unused)) dummy = 0;
>
> The mistake made by whoever wrote this test was making 'dummy' a stack

That was me. :(

> variable. That lets the compiler figure out that it's unused. If you
> make it a top-level variable (not static) so the compiler can't tell
> whether it's referenced by a different compilation unit, it can't make
> that deduction. And you don't need the stupid attibute or volatile on it.

It is better to just move “dummy” like you suggested instead of adding more
keywords to fix it.

-
Best Regards,
Yan, Zi

Attachment: signature.asc
Description: OpenPGP digital signature