Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Use 64-bit math to calculate pool sizes. Fixes ove...



details:   https://anonhg.NetBSD.org/src/rev/6828d50c3d2b
branches:  trunk
changeset: 368503:6828d50c3d2b
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Jul 16 10:20:21 2022 +0000

description:
Use 64-bit math to calculate pool sizes.  Fixes overflow errors for
pools larger than 4GB and gives the correct output for kernel pool pages
in "vmstat -s" output.

diffstat:

 sys/kern/subr_pool.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r b4ea97fa19ea -r 6828d50c3d2b sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Sat Jul 16 09:32:27 2022 +0000
+++ b/sys/kern/subr_pool.c      Sat Jul 16 10:20:21 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.284 2022/05/29 10:47:40 andvar Exp $   */
+/*     $NetBSD: subr_pool.c,v 1.285 2022/07/16 10:20:21 simonb Exp $   */
 
 /*
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018,
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.284 2022/05/29 10:47:40 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.285 2022/07/16 10:20:21 simonb Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1795,10 +1795,11 @@
        uint64_t total = 0;
 
        TAILQ_FOREACH(pp, &pool_head, pr_poollist) {
-               uint64_t bytes = pp->pr_npages * pp->pr_alloc->pa_pagesz;
+               uint64_t bytes =
+                   (uint64_t)pp->pr_npages * pp->pr_alloc->pa_pagesz;
 
                if ((pp->pr_roflags & PR_RECURSIVE) != 0)
-                       bytes -= (pp->pr_nout * pp->pr_size);
+                       bytes -= ((uint64_t)pp->pr_nout * pp->pr_size);
                total += bytes;
        }
 



Home | Main Index | Thread Index | Old Index