From 97199066bae97fc85b62d80d765bb44fdf54d1bb Mon Sep 17 00:00:00 2001 From: Jongyul Kim Date: Wed, 19 Jun 2024 11:57:41 -0500 Subject: [PATCH] Fix underflow bug. --- linux/mm/htmm_migrater.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/linux/mm/htmm_migrater.c b/linux/mm/htmm_migrater.c index a37dae0b7..b5df17840 100644 --- a/linux/mm/htmm_migrater.c +++ b/linux/mm/htmm_migrater.c @@ -138,6 +138,7 @@ static bool need_toptier_demotion(pg_data_t *pgdat, struct mem_cgroup *memcg, un unsigned long fasttier_max_watermark, fasttier_min_watermark; int target_nid = htmm_cxl_mode ? 1 : next_demotion_node(pgdat->node_id); pg_data_t *target_pgdat; + long long nr_exceeded_signed; if (target_nid == NUMA_NO_NODE) return false; @@ -171,7 +172,13 @@ static bool need_toptier_demotion(pg_data_t *pgdat, struct mem_cgroup *memcg, un return false; } - *nr_exceeded = nr_lru_pages + nr_need_promoted + fasttier_max_watermark - max_nr_pages; +// *nr_exceeded = nr_lru_pages + nr_need_promoted + fasttier_max_watermark - max_nr_pages; + + // Prevent an underflow. + nr_exceeded_signed = (long long)nr_lru_pages + nr_need_promoted + + fasttier_max_watermark - max_nr_pages; + *nr_exceeded = nr_exceeded_signed < 0 ? 0 : nr_exceeded_signed; + return true; }