$OpenBSD: patch-servers_slapd_back-mdb_init_c,v 1.4 2017/08/06 10:50:05 sthen Exp $
Index: servers/slapd/back-mdb/init.c
--- servers/slapd/back-mdb/init.c.orig
+++ servers/slapd/back-mdb/init.c
@@ -166,6 +166,33 @@ mdb_db_open( BackendDB *be, ConfigReply *cr )
 
 	flags = mdb->mi_dbenv_flags;
 
+#ifdef __OpenBSD__
+	/*
+	 * Enforce that MDB_WRITEMAP is set.
+	 *
+	 * MDB assumes a unified buffer cache.
+	 *
+	 * See http://www.openldap.org/pub/hyc/mdm-paper.pdf section 3.1,
+	 * references 17, 18, and 19.
+	 *
+	 * From Howard Chu: "This requirement can be relaxed in the
+	 * current version of the library. If you create the environment
+	 * with the MDB_WRITEMAP option then all reads and writes are
+	 * performed using mmap, so the file buffer cache is irrelevant.
+	 * Of course then you lose the protection that the read-only
+	 * map offers."
+	 */
+
+	if ( !(flags & MDB_WRITEMAP) ) {
+		rc = MDB_INCOMPATIBLE;
+		Debug( LDAP_DEBUG_ANY,
+			LDAP_XSTRING(mdb_db_open) ": database \"%s\" does not have writemap. "
+			"This is required on systems without unified buffer cache.\n",
+			be->be_suffix[0].bv_val, rc, 0 );
+		goto fail;
+	}
+#endif
+
 	if ( slapMode & SLAP_TOOL_QUICK )
 		flags |= MDB_NOSYNC|MDB_WRITEMAP;
 
