[Date Prev][Date Next] [Chronological] [Thread] [Top]

[Fwd: BerkeleyDB region size bug]



This is Sleepycat bug #14908. I thought I posted it here before but apparently not. Fixed in current 4.5.20, but still broken in all earlier releases.

-------- 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;

Or in unidiff:
--- mp_region.c.O       2006-06-19 08:37:58.000000000 -0700
+++ mp_region.c 2006-07-10 13:36:43.000000000 -0700
@@ -260,9 +260,7 @@
       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 = GIGABYTE / dbenv->mp_ncache * dbenv->mp_gbytes;
       reg_size += dbenv->mp_bytes / dbenv->mp_ncache;
       *reg_sizep = reg_size;



--
  -- Howard Chu
  Chief Architect, Symas Corp.  http://www.symas.com
  Director, Highland Sun        http://highlandsun.com/hyc
  OpenLDAP Core Team            http://www.openldap.org/project/