mm, compaction: avoid uninitialized variable use
Subsystems (2)
PATCH 1/1 mm, compaction: avoid uninitialized variable use
A recent rework of the compaction code introduced a warning about an uninitialized variable when CONFIG_COMPACTION is disabled and __alloc_pages_direct_compact() does not set its 'compact_result' output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This adds another check for CONFIG_COMPACTION to ensure we never evaluate the uninitialized variable in this configuration, which is probably the simplest way to avoid the warning.
A more elaborate rework might make this more readable.
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
@@ -3640,7 +3640,8 @@ retry: goto got_pg;/* Checks for THP-specific high-order allocations */ -if (is_thp_gfp_mask (gfp_mask)) { +if (IS_ENABLED (CONFIG_COMPACTION ) && +is_thp_gfp_mask (gfp_mask)) {/* * If compaction is deferred for high-order allocations, it is * because sync compaction recently failed. If this is the case
Signature · 1 line
2.7.0
Quoted 11 lines · Arnd Bergmann
A recent rework of the compaction code introduced a warning about an uninitialized variable when
CONFIG_COMPACTIONis disabled and__alloc_pages_direct_compact()does not set its 'compact_result' output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]This adds another check for
CONFIG_COMPACTIONto ensure we never evaluate the uninitialized variable in this configuration, which is probably the simplest way to avoid the warning.
I think that hiding this into __alloc_pages_direct_compact is a better idea. See the diff below
Quoted 5 lines
A more elaborate rework might make this more readable.
Signed-off-by Arnd Bergmann <[email protected]>Fixes 13cff7b81275 ("mm, compaction: simplify __alloc_pages_direct_compact feedback interface")
Please do not use SHA for mmotm commits because they are unstable and change each linux-next release.
---
mm/page_alloc.c +1 -0
@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context *ac, enum migrate_mode mode, enum compact_result *compact_result) { + *compact_result =COMPACT_DEFERRED ;return NULL ; }
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · On Wednesday 11 May 2016 16:44:07 Michal Hocko wrote:
Quoted 8 lines · Arnd Bergmann
A recent rework of the compaction code introduced a warning about an uninitialized variable when
CONFIG_COMPACTIONis disabled and__alloc_pages_direct_compact()does not set its 'compact_result' output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Quoted 6 lines
Quoted 3 lines
This adds another check for
CONFIG_COMPACTIONto ensure we never evaluate the uninitialized variable in this configuration, which is probably the simplest way to avoid the warning.I think that hiding this into
__alloc_pages_direct_compactis a better idea. See the diff below
Ok, sounds good.
mm/page_alloc.c __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, · line 3306
Quoted 13 lines
---
mm/page_alloc.c +1
-0@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context *ac, enum migrate_mode mode, enum compact_result *compact_result) { + *compact_result =COMPACT_DEFERRED ;return NULL ; }
I thought about this but didn't know which COMPACT_* value was appropriate here.
The behavior then changes a bit with your approach compared to mine, because
if (compact_result == COMPACT_DEFERRED)
goto nopage;is true now. I assume this is what we want though.
Arnd
Quoted 35 lines · Arnd Bergmann
Quoted 9 lines · On Wednesday 11 May 2016 16:44:07 Michal Hocko wrote:
Quoted 8 lines · Arnd Bergmann
A recent rework of the compaction code introduced a warning about an uninitialized variable when
CONFIG_COMPACTIONis disabled and__alloc_pages_direct_compact()does not set its 'compact_result' output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]Quoted 6 lines
Quoted 3 lines
This adds another check for
CONFIG_COMPACTIONto ensure we never evaluate the uninitialized variable in this configuration, which is probably the simplest way to avoid the warning.I think that hiding this into
__alloc_pages_direct_compactis a better idea. See the diff belowOk, sounds good.
mm/page_alloc.c __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, · line 3306
Quoted 13 lines
---
mm/page_alloc.c +1
-0@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context *ac, enum migrate_mode mode, enum compact_result *compact_result) { + *compact_result =COMPACT_DEFERRED ;return NULL ; }I thought about this but didn't know which COMPACT_* value was appropriate here.
Quoted 7 lines
The behavior then changes a bit with your approach compared to mine, because
if (compact_result == COMPACT_DEFERRED) goto nopage;is true now. I assume this is what we want though.
No, we actually want to try to reclaim, that's why COMPACT_SKIPPED is more appropriate. COMPACT_SKIPPED is even correct semantically because the compaction wasn't invoked.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 30 lines · Michal Hocko
Quoted 11 lines · Arnd Bergmann
A recent rework of the compaction code introduced a warning about an uninitialized variable when
CONFIG_COMPACTIONis disabled and__alloc_pages_direct_compact()does not set its 'compact_result' output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]This adds another check for
CONFIG_COMPACTIONto ensure we never evaluate the uninitialized variable in this configuration, which is probably the simplest way to avoid the warning.I think that hiding this into
__alloc_pages_direct_compactis a better idea. See the diff belowQuoted 5 lines
A more elaborate rework might make this more readable.
Signed-off-by Arnd Bergmann <[email protected]>Fixes 13cff7b81275 ("mm, compaction: simplify __alloc_pages_direct_compact feedback interface")Please do not use SHA for mmotm commits because they are unstable and change each linux-next release.
---
mm/page_alloc.c +0
-0
mm/page_alloc.c __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, · line 3303
Quoted 4 lines
mm/page_alloc.c +1
-0@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context *ac, enum migrate_mode mode, enum compact_result *compact_result) { + *compact_result =COMPACT_DEFERRED ;
Sorry, this should have been COMPACT_SKIPPED.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
I think this would be slightly better than your proposal. Andrew, could you fold it into the original mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch patch?
---
Quoted 15 lines · Michal Hocko
I think this would be slightly better than your proposal. Andrew, could you fold it into the original mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch patch?
---
From434bc8b6f3787724327499998c4fe651e8ce5d68Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 May 2016 08:10:33 +0200
Subject: [PATCH] mmotm:
mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface-fixArnd has reported the following compilation warning:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Quoted 8 lines
This should be a false positive
TRANSPARENT_HUGEPAGEdepends on COMPACTION sois_thp_gfp_maskshouldn't be true.GFP_TRANSHUGEis a bit tricky and somebody might be using this accidently. Make sure thatcompact_resultis defined also for !CONFIG_COMPACT and set it toCOMPACT_SKIPPEDbecause the compaction was really withdrawn.Reported-by Arnd Bergmann <[email protected]>Signed-off-by Michal Hocko <[email protected]>
Ack.
Quoted 10 lines
--- mm/page_alloc.c | 1 + 1 file changed, 1 insertion(+)mm/page_alloc.c +0
-0
mm/page_alloc.c __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, · line 3306
Quoted 7 lines
mm/page_alloc.c +1
-0@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context *ac, enum migrate_mode mode, enum compact_result *compact_result) { + *compact_result =COMPACT_SKIPPED ;return NULL ; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Arnd Bergmann
Acked-byQuoted 15 lines · On Thursday 12 May 2016 08:16:36 Michal Hocko wrote:
I think this would be slightly better than your proposal. Andrew, could you fold it into the original mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch patch?
---
From434bc8b6f3787724327499998c4fe651e8ce5d68Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 May 2016 08:10:33 +0200
Subject: [PATCH] mmotm:
mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface-fixArnd has reported the following compilation warning:
mm/page_alloc.c: In function '__alloc_pages_nodemask':mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Quoted 9 lines
This should be a false positive
TRANSPARENT_HUGEPAGEdepends on COMPACTION sois_thp_gfp_maskshouldn't be true.GFP_TRANSHUGEis a bit tricky and somebody might be using this accidently. Make sure thatcompact_resultis defined also for !CONFIG_COMPACT and set it toCOMPACT_SKIPPEDbecause the compaction was really withdrawn.Reported-by Arnd Bergmann <[email protected]>Signed-off-by Michal Hocko <[email protected]>
Looks much nicer than my version.
Arnd