mm/page_alloc: Mark pagesets as __maybe_unused
Subsystems (2)
PATCH 1/1 mm/page_alloc: Mark pagesets as __maybe_unused
Commit 9983a9d577db ("locking/local_lock: Make the empty local_lock_*() function a macro.") in the -tip tree converted the local_lock_*() functions into macros, which causes a warning with clang with CONFIG_PREEMPT_RT=n + CONFIG_DEBUG_LOCK_ALLOC=n:
mm/page_alloc.c:131:40: error: variable 'pagesets' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]
static DEFINE_PER_CPU(struct pagesets, pagesets) = {
^1 error generated.
Prior to that change, clang was not able to tell that pagesets was unused in this configuration because it does not perform cross function analysis in the frontend. After that change, it sees that the macros just do a typecheck on the lock member of pagesets, which is evaluated at compile time (so the variable is technically "used"), meaning the variable is not needed in the final assembly, as the warning states.
Mark the variable as __maybe_unused to make it clear to clang that this is expected in this configuration so there is no more warning.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -128,7 +128,7 @@ static DEFINE_MUTEX(pcp_batch_high_lock);struct pagesets {local_lock_t lock; }; -static DEFINE_PER_CPU(struct pagesets, pagesets) = { +static DEFINE_PER_CPU(struct pagesets, pagesets) __maybe_unused = { .lock =INIT_LOCAL_LOCK (lock), };
base-commit: 10a64d66e319e6ea3a19f9d2e7c4f0dee90ce6e0
Signature · 1 line
2.35.1
Quoted 33 lines · Nathan Chancellor
Commit
9983a9d577db("locking/local_lock: Make the empty local_lock_*() function a macro.") in the -tip tree converted the local_lock_*() functions into macros, which causes a warning with clang withCONFIG_PREEMPT_RT=n+CONFIG_DEBUG_LOCK_ALLOC=n:
mm/page_alloc.c:131:40: error: variable 'pagesets' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]static DEFINE_PER_CPU(struct pagesets, pagesets) = { ^1 error generated.
Prior to that change, clang was not able to tell that pagesets was unused in this configuration because it does not perform cross function analysis in the frontend. After that change, it sees that the macros just do a typecheck on the lock member of pagesets, which is evaluated at compile time (so the variable is technically "used"), meaning the variable is not needed in the final assembly, as the warning states.
Mark the variable as
__maybe_unusedto make it clear to clang that this is expected in this configuration so there is no more warning.Reported-by "kernelci.org bot" <[email protected]>Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/page_alloc.c +0
-0
mm/page_alloc.c static DEFINE_MUTEX(pcp_batch_high_lock); · line 131
Quoted 5 lines
mm/page_alloc.c +1
-1@@ -128,7 +128,7 @@ static DEFINE_MUTEX(pcp_batch_high_lock);struct pagesets {local_lock_t lock; }; -static DEFINE_PER_CPU(struct pagesets, pagesets) = { +static DEFINE_PER_CPU(struct pagesets, pagesets) __maybe_unused = {
No, I need to think of something else then for the local_lock thing. I haven't seen it with gcc. There is probably more than just this one.
mm/page_alloc.c static DEFINE_MUTEX(pcp_batch_high_lock); · line 133
Quoted 2 lines
mm/page_alloc.c +0
-0.lock = INIT_LOCAL_LOCK(lock), };
Sebastian
Quoted 29 lines · Sebastian Andrzej Siewior
Quoted 28 lines · Nathan Chancellor
Commit
9983a9d577db("locking/local_lock: Make the empty local_lock_*() function a macro.") in the -tip tree converted the local_lock_*() functions into macros, which causes a warning with clang withCONFIG_PREEMPT_RT=n+CONFIG_DEBUG_LOCK_ALLOC=n:
mm/page_alloc.c:131:40: error: variable 'pagesets' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]static DEFINE_PER_CPU(struct pagesets, pagesets) = { ^1 error generated.
Prior to that change, clang was not able to tell that pagesets was unused in this configuration because it does not perform cross function analysis in the frontend. After that change, it sees that the macros just do a typecheck on the lock member of pagesets, which is evaluated at compile time (so the variable is technically "used"), meaning the variable is not needed in the final assembly, as the warning states.
Mark the variable as
__maybe_unusedto make it clear to clang that this is expected in this configuration so there is no more warning.Reported-by "kernelci.org bot" <[email protected]>Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
mm/page_alloc.c static DEFINE_MUTEX(pcp_batch_high_lock); · line 131
Quoted 10 lines
mm/page_alloc.c +1
-1@@ -128,7 +128,7 @@ static DEFINE_MUTEX(pcp_batch_high_lock);struct pagesets {local_lock_t lock; }; -static DEFINE_PER_CPU(struct pagesets, pagesets) = { +static DEFINE_PER_CPU(struct pagesets, pagesets) __maybe_unused = {No, I need to think of something else then for the
local_lockthing. I haven't seen it with gcc. There is probably more than just this one.
As far as I am aware, this is a clang only warning.
From my brief audit of uses of local_lock_t, I believe this is the only one that will trigger this warning because every other structure that has a local_lock_t also has another member that is unconditionally used, meaning an instance of that structure will not just be used at compile time. In this case, 'struct pagesets' ONLY contains a local_lock_t, which is only used at compile time in this configuration, hence the warning.
Of course, if you can think of something that works for your use case and doesn't make clang warn, that would be ideal but I don't see this patch as the worst solution. I'll run through my full set of builds tonight and see if there are any other instances of this warning; this particular instance was visible in several defconfigs so I fixed it first.
Cheers,
Nathan