[PATCH 04/11] mm, compaction: cover all compaction mode in compact_zone

From: Michal Hocko
Date: Tue Apr 05 2016 - 07:27:50 EST


From: Michal Hocko <mhocko@xxxxxxxx>

the compiler is complaining after "mm, compaction: change COMPACT_
constants into enum"

mm/compaction.c: In function âcompact_zoneâ:
mm/compaction.c:1350:2: warning: enumeration value âCOMPACT_DEFERREDâ not handled in switch [-Wswitch]
switch (ret) {
^
mm/compaction.c:1350:2: warning: enumeration value âCOMPACT_COMPLETEâ not handled in switch [-Wswitch]
mm/compaction.c:1350:2: warning: enumeration value âCOMPACT_NO_SUITABLE_PAGEâ not handled in switch [-Wswitch]
mm/compaction.c:1350:2: warning: enumeration value âCOMPACT_NOT_SUITABLE_ZONEâ not handled in switch [-Wswitch]
mm/compaction.c:1350:2: warning: enumeration value âCOMPACT_CONTENDEDâ not handled in switch [-Wswitch]

compaction_suitable is allowed to return only COMPACT_PARTIAL,
COMPACT_SKIPPED and COMPACT_CONTINUE so other cases are simply
impossible. Put a VM_BUG_ON to catch an impossible return value.

Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
Acked-by: Vlastimil Babka <vbabka@xxxxxxx>
Acked-by: Hillf Danton <hillf.zj@xxxxxxxxxxxxxxx>
---
mm/compaction.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 8ae7b1c46c72..b06de27b7f72 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1433,15 +1433,12 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro

ret = compaction_suitable(zone, cc->order, cc->alloc_flags,
cc->classzone_idx);
- switch (ret) {
- case COMPACT_PARTIAL:
- case COMPACT_SKIPPED:
- /* Compaction is likely to fail */
+ /* Compaction is likely to fail */
+ if (ret == COMPACT_PARTIAL || ret == COMPACT_SKIPPED)
return ret;
- case COMPACT_CONTINUE:
- /* Fall through to compaction */
- ;
- }
+
+ /* huh, compaction_suitable is returning something unexpected */
+ VM_BUG_ON(ret != COMPACT_CONTINUE);

/*
* Clear pageblock skip if there were failures recently and compaction
--
2.8.0.rc3