From 5c7a7998a97f180d86ab368eb81a8f15a3667ef1 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@openldap.org>
Date: Tue, 27 Nov 2001 12:36:52 +0000
Subject: [PATCH] Set the id2entry database pagesize to BDB_ID2ENTRY_PAGESIZE
 to avoid overflow/fragmentation. (This is now 16K vs default 4K.) It turns
 out that the entries' on-disk format is quite space-inefficient, storing 4
 bytes per pointer or integer when typically >50% of those bytes are zero. Oh
 well. It's about a 2:1 space increase over ldbm now, vs 4:1 before when all
 the entries were overflowing the 4K pages.

---
 servers/slapd/back-bdb/back-bdb.h | 9 +++++++++
 servers/slapd/back-bdb/init.c     | 4 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h
index 9932bfb8bb..ec71844477 100644
--- a/servers/slapd/back-bdb/back-bdb.h
+++ b/servers/slapd/back-bdb/back-bdb.h
@@ -44,6 +44,15 @@ LDAP_BEGIN_DECL
 #define BDB_DN2ID		1
 #define BDB_NDB			2
 
+/* The bdb on-disk entry format is pretty space-inefficient. Average
+ * sized user entries are 3-4K each. You need at least two entries to
+ * fit into a single database page, more is better. 64K is BDB's
+ * upper bound.
+ */
+#ifndef BDB_ID2ENTRY_PAGESIZE
+#define	BDB_ID2ENTRY_PAGESIZE	16384
+#endif
+
 #define BDB_INDICES		128
 
 struct bdb_db_info {
diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c
index ac97844cbe..8e5f5b51af 100644
--- a/servers/slapd/back-bdb/init.c
+++ b/servers/slapd/back-bdb/init.c
@@ -232,10 +232,12 @@ bdb_db_open( BackendDB *be )
 		if( i == BDB_ID2ENTRY ) {
 			rc = db->bdi_db->set_bt_compare( db->bdi_db,
 				bdb_bt_compare );
+			rc = db->bdi_db->set_pagesize( db->bdi_db,
+				BDB_ID2ENTRY_PAGESIZE );
 		}
 		rc = db->bdi_db->open( db->bdi_db,
 			bdbi_databases[i].file,
-			bdbi_databases[i].name,
+		/*	bdbi_databases[i].name, */ NULL,
 			bdbi_databases[i].type,
 			bdbi_databases[i].flags | flags,
 			bdb->bi_dbenv_mode );
-- 
GitLab