]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Add mdb_env_set_pagesize()
authorHoward Chu <hyc@openldap.org>
Mon, 6 Aug 2018 12:09:37 +0000 (13:09 +0100)
committerHoward Chu <hyc@openldap.org>
Sat, 10 Oct 2020 15:26:24 +0000 (16:26 +0100)
libraries/liblmdb/lmdb.h
libraries/liblmdb/mdb.c
libraries/liblmdb/mtest.c

index 67b666712732573e4984a1a5af0901b0403c3e05..d996f38bdfc947c7fd335812fa13dbb4786127bc 100644 (file)
@@ -908,6 +908,16 @@ int  mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
         */
 int  mdb_env_set_mapsize(MDB_env *env, mdb_size_t size);
 
+
+       /** @brief Set the size of DB pages in bytes.
+        *
+        * The size defaults to the OS page size. Smaller or larger values may be
+        * desired depending on the size of keys and values being used. Also, an
+        * explicit size may need to be set when using filesystems like ZFS which
+        * don't use the OS page size.
+        */
+int  mdb_env_set_pagesize(MDB_env *env, int size);
+
        /** @brief Set the maximum number of threads/reader slots for the environment.
         *
         * This defines the number of slots in the lock table that is used to track readers in the
index 5b2284124228c4e94958cc9733de44fcbf85d10d..68d1d212a5d38350ac86591dea2cad407c517212 100644 (file)
@@ -4439,6 +4439,8 @@ mdb_env_read_header(MDB_env *env, int prev, MDB_meta *meta)
                env->me_mapsize &= ~(VM_ALIGN-1);
                env->me_psize = env->me_os_psize;
                rc = mdb_env_map(env, NULL);
+               if (rc)
+                       return rc;
                p = (MDB_page *)env->me_map;
                for (i=0; i<NUM_METAS; i++) {
                        if (!F_ISSET(p->mp_flags, P_META))
@@ -11270,6 +11272,19 @@ mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *arg)
        return MDB_SUCCESS;
 }
 
+int ESECT
+mdb_env_set_pagesize(MDB_env *env, int size)
+{
+       if (!env || env->me_map)
+               return EINVAL;
+       if (size > MAX_PAGESIZE || size < 256)
+               return EINVAL;
+       if (size & (size-1))
+               return EINVAL;
+       env->me_os_psize = size;
+       return MDB_SUCCESS;
+}
+
 /** Common code for #mdb_stat() and #mdb_env_stat().
  * @param[in] env the environment to operate in.
  * @param[in] db the #MDB_db record containing the stats to return.
index c1c9abb8f70c22bead9d34a68089caf898fbc832..925f2d1ba705a5fb06b0c8521a6c2731122ee0c7 100644 (file)
@@ -47,6 +47,7 @@ int main(int argc,char * argv[])
                E(mdb_env_create(&env));
                E(mdb_env_set_maxreaders(env, 1));
                E(mdb_env_set_mapsize(env, 10485760));
+               E(mdb_env_set_pagesize(env, 1024));
                E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
 
                E(mdb_txn_begin(env, NULL, 0, &txn));