From 07cc016152a495aba24cd4bca7fc449750d28749 Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 13 Apr 2007 18:50:03 +0000 Subject: Fix overflow, which was causing endless loops when 32bit machine had more than 2GB of RAM. This was because our physmem is long and 'physmem*PAGESIZE' can be negative for more than 2GB of memory. Reported by: Andrey V. Elsukov It is not yet tested by Andrey, so there can be other problems, but this was definiately a bug, so I'm committing a fix now. --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c | 4 ++-- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sys/cddl') diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c index f3d7ee6..6d361d9 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c @@ -624,7 +624,7 @@ buf_init(void) * with an average 64K block size. The table will take up * totalmem*sizeof(void*)/64K (eg. 128KB/GB with 8-byte pointers). */ - while (hsize * 65536 < physmem * PAGESIZE) + while (hsize * 65536 < (uint64_t)physmem * PAGESIZE) hsize <<= 1; retry: buf_hash_table.ht_mask = hsize - 1; @@ -2801,7 +2801,7 @@ arc_init(void) #ifdef _KERNEL /* Warn about ZFS memory requirements. */ - if ((physmem * PAGESIZE) < (256 + 128 + 64) * (1 << 20)) { + if (((uint64_t)physmem * PAGESIZE) < (256 + 128 + 64) * (1 << 20)) { printf("ZFS WARNING: Recomended minimum of RAM size is 512MB, " "expect unstable behaviour.\n"); } else if (kmem_size() < 256 * (1 << 20)) { diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c index 1fde66f..bd6d50b 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c @@ -250,7 +250,7 @@ dbuf_init(void) * with an average 4K block size. The table will take up * totalmem*sizeof(void*)/4K (i.e. 2MB/GB with 8-byte pointers). */ - while (hsize * 4096 < physmem * PAGESIZE) + while (hsize * 4096 < (uint64_t)physmem * PAGESIZE) hsize <<= 1; retry: -- cgit v1.1