From bd59d85850ba6ac17ae35d2df09c75d21c356b1c Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Fri, 13 Apr 2007 18:50:03 +0000 Subject: [PATCH] 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 +- sys/contrib/opensolaris/uts/common/fs/zfs/arc.c | 4 ++-- sys/contrib/opensolaris/uts/common/fs/zfs/dbuf.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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 f3d7ee63ebb..6d361d9ecbc 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 1fde66f6f2a..bd6d50b3738 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: diff --git a/sys/contrib/opensolaris/uts/common/fs/zfs/arc.c b/sys/contrib/opensolaris/uts/common/fs/zfs/arc.c index f3d7ee63ebb..6d361d9ecbc 100644 --- a/sys/contrib/opensolaris/uts/common/fs/zfs/arc.c +++ b/sys/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/contrib/opensolaris/uts/common/fs/zfs/dbuf.c b/sys/contrib/opensolaris/uts/common/fs/zfs/dbuf.c index 1fde66f6f2a..bd6d50b3738 100644 --- a/sys/contrib/opensolaris/uts/common/fs/zfs/dbuf.c +++ b/sys/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: -- 2.45.2