From 1038f87c4edcc66d7d9446efb9b0d9ed50beda19 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Thu, 6 Apr 2023 02:42:22 +0900 Subject: [PATCH] Fix some signedness issues in arc_evict() It may happen that "wanted total ARC size" (wt) is negative, that was expected. But multiplication product of it and unsigned fractions result in unsigned value, incorrectly shifted right with a sing loss. Reviewed-by: Brian Behlendorf Reviewed-by: Prakash Surya Reviewed-by: Paul Dagnelie Signed-off-by: Alexander Motin Sponsored by: iXsystems, Inc. Closes #14692 --- module/zfs/arc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/zfs/arc.c b/module/zfs/arc.c index e32707bbe5..c50228a268 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -4465,7 +4465,7 @@ arc_evict(void) */ int64_t prune = 0; int64_t dn = wmsum_value(&arc_sums.arcstat_dnode_size); - w = wt * (arc_meta >> 16) >> 16; + w = wt * (int64_t)(arc_meta >> 16) >> 16; if (zfs_refcount_count(&arc_mru->arcs_size[ARC_BUFC_METADATA]) + zfs_refcount_count(&arc_mfu->arcs_size[ARC_BUFC_METADATA]) - zfs_refcount_count(&arc_mru->arcs_esize[ARC_BUFC_METADATA]) - @@ -4481,7 +4481,7 @@ arc_evict(void) arc_prune_async(prune); /* Evict MRU metadata. */ - w = wt * (arc_meta * arc_pm >> 48) >> 16; + w = wt * (int64_t)(arc_meta * arc_pm >> 48) >> 16; e = MIN((int64_t)(asize - arc_c), (int64_t)(mrum - w)); bytes = arc_evict_impl(arc_mru, ARC_BUFC_METADATA, e); total_evicted += bytes; @@ -4489,7 +4489,7 @@ arc_evict(void) asize -= bytes; /* Evict MFU metadata. */ - w = wt * (arc_meta >> 16) >> 16; + w = wt * (int64_t)(arc_meta >> 16) >> 16; e = MIN((int64_t)(asize - arc_c), (int64_t)(m - w)); bytes = arc_evict_impl(arc_mfu, ARC_BUFC_METADATA, e); total_evicted += bytes; @@ -4498,7 +4498,7 @@ arc_evict(void) /* Evict MRU data. */ wt -= m - total_evicted; - w = wt * (arc_pd >> 16) >> 16; + w = wt * (int64_t)(arc_pd >> 16) >> 16; e = MIN((int64_t)(asize - arc_c), (int64_t)(mrud - w)); bytes = arc_evict_impl(arc_mru, ARC_BUFC_DATA, e); total_evicted += bytes;