As posted to http://www.openldap.org/lists/openldap-devel/200610/msg00027.html

This is Sleepycat bug #14908. The provided patch is for 4.2.52. The
same bug is present in all versions up to 4.5.20 where it is fixed.

-------- Original Message --------
Subject: region size bug Re: [BDB-Alpha] Berkeley DB 4.5.8 ALPHA
Date: Mon, 10 Jul 2006 13:37:33 -0700
From: Howard Chu <hyc@symas.com>
To: support@sleepycat.com
CC: support@symas.com
References: <45A742B5-7DD5-4512-A204-A10FE8FC5DFC@oracle.com>


I just ran into this in 4.2.52 but the same calculation occurs in 4.4
and 4.5.8 alpha:

This computation gives the wrong results when the number of cache
regions is greater than the number of gigabytes (which we encounter on
Linux using shared memory regions, which are constrained to much smaller
than a gigabyte each).


in mp/mp_region.c:


   roff_t reg_size;


   /* Figure out how big each cache region is. */
   reg_size = (roff_t)(dbenv->mp_gbytes / dbenv->mp_ncache) * GIGABYTE;
   reg_size += ((roff_t)(dbenv->mp_gbytes %
       dbenv->mp_ncache) * GIGABYTE) / dbenv->mp_ncache;
   reg_size += dbenv->mp_bytes / dbenv->mp_ncache;
   *reg_sizep = reg_size;


The first reg_size calculation always goes to zero when mp_ncache >
mp_gbytes.
This should have been, instead:
   reg_size = GIGABYTE / dbenv->mp_ncache * dbenv->mp_gbytes;

--- mp/mp_region.c.O	2003-06-30 10:20:19.000000000 -0700
+++ mp/mp_region.c	2006-10-27 23:25:05.000000000 -0700
@@ -43,9 +43,7 @@
 	int htab_buckets, ret;
 
 	/* Figure out how big each cache region is. */
-	reg_size = (dbenv->mp_gbytes / dbenv->mp_ncache) * GIGABYTE;
-	reg_size += ((dbenv->mp_gbytes %
-	    dbenv->mp_ncache) * GIGABYTE) / dbenv->mp_ncache;
+	reg_size = GIGABYTE / dbenv->mp_ncache * dbenv->mp_gbytes;
 	reg_size += dbenv->mp_bytes / dbenv->mp_ncache;
 
 	/*
