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 <bu7cher@yandex.ru>

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.
This commit is contained in:
Pawel Jakub Dawidek 2007-04-13 18:50:03 +00:00
parent 7c275b458a
commit bd59d85850
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=168696
4 changed files with 6 additions and 6 deletions

View File

@ -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)) {

View File

@ -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:

View File

@ -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)) {

View File

@ -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: