Skip to contentSkip to conversation

mm/vmscan: fix some -Wenum-conversion warnings

PATCH Superseded Qian Cai 2 participants 3 messages Nov 15, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 mm/vmscan: fix some -Wenum-conversion warnings

The -next commit "mm: vmscan: enforce inactive:active ratio at the reclaim root" [1] introduced some GCC -Wenum-conversion warnings,

mm/vmscan.c:2216:39: warning: implicit conversion from enumeration type 'enum lru_list' to different enumeration type 'enum node_stat_item' [-Wenum-conversion]

        inactive = lruvec_page_state(lruvec, inactive_lru);
                   ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~~~
mm/vmscan.c:2217:37: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        active = lruvec_page_state(lruvec, active_lru);
                 ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~
mm/vmscan.c:2746:42: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);
               ~~~~~~~~~~~~~~~~~                ^~~~~~~~~~~~~~~~~

Fix them by adding casts where it is safe.

[1] http://lkml.kernel.org/r/[email protected]

---
 mm/vmscan.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/vmscan.c +5 -3
index 122b3920aaa4..16c005ddfd9e 100644
@@ -2213,8 +2213,9 @@ static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
 	unsigned long inactive_ratio;
 	unsigned long gb;
 
-	inactive = lruvec_page_state(lruvec, inactive_lru);
-	active = lruvec_page_state(lruvec, active_lru);
+	inactive = lruvec_page_state(lruvec,
+				     (enum node_stat_item)inactive_lru);
+	active = lruvec_page_state(lruvec, (enum node_stat_item)active_lru);
 
 	gb = (inactive + active) >> (30 - PAGE_SHIFT);
 	if (gb)
@@ -2743,7 +2744,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 	 * thrashing, try to reclaim those first before touching
 	 * anonymous pages.
 	 */
-	file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);
+	file = lruvec_page_state(target_lruvec,
+				 (enum node_stat_item)LRU_INACTIVE_FILE);
 	if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
 		sc->cache_trim_mode = 1;
 	else
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 6 lines · Qian Cai

The -next commit "mm: vmscan: enforce inactive:active ratio at the reclaim root" [1] introduced some GCC -Wenum-conversion warnings,

mm/vmscan.c:2216:39: warning: implicit conversion from enumeration type 'enum lru_list' to different enumeration type 'enum node_stat_item' [-Wenum-conversion]

Quoted 11 lines
        inactive = lruvec_page_state(lruvec, inactive_lru);
                   ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~~~
mm/vmscan.c:2217:37: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        active = lruvec_page_state(lruvec, active_lru);
                 ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~
mm/vmscan.c:2746:42: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);

Interesting, it doesn't show these for me with gcc-9.2.0.

We should definitely fix these!

mm/vmscan.c static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru) · line 2218

Quoted 9 lines
mm/vmscan.c +3 -2
@@ -2213,8 +2213,9 @@ static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
 	unsigned long inactive_ratio;
 	unsigned long gb;
 
-	inactive = lruvec_page_state(lruvec, inactive_lru);
-	active = lruvec_page_state(lruvec, active_lru);
+	inactive = lruvec_page_state(lruvec,
+				     (enum node_stat_item)inactive_lru);
+	active = lruvec_page_state(lruvec, (enum node_stat_item)active_lru);

This is fragile, as it relies on the absolute values being identical, which we don't guarantee. However, we do guarantee the relative order between the LRU items, and we use NR_LRU_BASE for the translation.

Please use NR_LRU_BASE + (in)active_lru here.

mm/vmscan.c static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) · line 2748

Quoted 7 lines
mm/vmscan.c +2 -1
@@ -2743,7 +2744,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 	 * thrashing, try to reclaim those first before touching
 	 * anonymous pages.
 	 */
-	file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);
+	file = lruvec_page_state(target_lruvec,
+				 (enum node_stat_item)LRU_INACTIVE_FILE);

This should just directly use NR_INACTIVE_FILE instead.

Thanks

author
#2 lore raw
Quoted 19 lines · Johannes Weiner
Quoted 6 lines · Qian Cai

The -next commit "mm: vmscan: enforce inactive:active ratio at the reclaim root" [1] introduced some GCC -Wenum-conversion warnings,

mm/vmscan.c:2216:39: warning: implicit conversion from enumeration type 'enum lru_list' to different enumeration type 'enum node_stat_item' [-Wenum-conversion]

Quoted 11 lines
        inactive = lruvec_page_state(lruvec, inactive_lru);
                   ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~~~
mm/vmscan.c:2217:37: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        active = lruvec_page_state(lruvec, active_lru);
                 ~~~~~~~~~~~~~~~~~         ^~~~~~~~~~
mm/vmscan.c:2746:42: warning: implicit conversion from enumeration type
'enum lru_list' to different enumeration type 'enum node_stat_item'
[-Wenum-conversion]
        file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);
Quoted 1 line

Interesting, it doesn't show these for me with gcc-9.2.0.

Sorry, I meant to say it is clang.

Quoted 30 lines

We should definitely fix these!

mm/vmscan.c static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru) · line 2218

Quoted 9 lines
mm/vmscan.c +3 -2
@@ -2213,8 +2213,9 @@ static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
 	unsigned long inactive_ratio;
 	unsigned long gb;
 
-	inactive = lruvec_page_state(lruvec, inactive_lru);
-	active = lruvec_page_state(lruvec, active_lru);
+	inactive = lruvec_page_state(lruvec,
+				     (enum node_stat_item)inactive_lru);
+	active = lruvec_page_state(lruvec, (enum node_stat_item)active_lru);

This is fragile, as it relies on the absolute values being identical, which we don't guarantee. However, we do guarantee the relative order between the LRU items, and we use NR_LRU_BASE for the translation.

Please use NR_LRU_BASE + (in)active_lru here.

mm/vmscan.c static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) · line 2748

Quoted 7 lines
mm/vmscan.c +2 -1
@@ -2743,7 +2744,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 	 * thrashing, try to reclaim those first before touching
 	 * anonymous pages.
 	 */
-	file = lruvec_page_state(target_lruvec, LRU_INACTIVE_FILE);
+	file = lruvec_page_state(target_lruvec,
+				 (enum node_stat_item)LRU_INACTIVE_FILE);

This should just directly use NR_INACTIVE_FILE instead.

Thanks