]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Add IDL caching codes (only slab enabled)
authorKurt Zeilenga <kurt@openldap.org>
Thu, 12 Dec 2002 22:50:15 +0000 (22:50 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 12 Dec 2002 22:50:15 +0000 (22:50 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/search.c

index b896191e27b9cbd8c4f439db1dd29fd57d17b6b9..b7d208812a13b0f9cba640483e738d4f41d1a350 100644 (file)
@@ -60,6 +60,21 @@ LDAP_BEGIN_DECL
 
 #define DEFAULT_CACHE_SIZE     1000
 
+/* The default search IDL stack cache depth */
+#define DEFAULT_SEARCH_STACK_DEPTH     16
+
+/* for the (expermental) IDL cache */
+#ifdef SLAP_IDL_CACHE
+typedef struct bdb_idl_cache_entry_s {
+       struct berval kstr;
+       ldap_pvt_thread_rdwr_t idl_entry_rwlock;
+       ID      *idl;
+       DB      *db;
+       struct bdb_idl_cache_entry_s* idl_lru_prev;
+       struct bdb_idl_cache_entry_s* idl_lru_next;
+} bdb_idl_cache_entry_t;
+#endif
+
 /* for the in-core cache of entries */
 typedef struct bdb_cache {
         int             c_maxsize;
@@ -99,6 +114,8 @@ struct bdb_info {
        slap_mask_t     bi_defaultmask;
        Cache           bi_cache;
        Avlnode         *bi_attrs;
+       void            *bi_search_stack;
+       int             bi_search_stack_depth;
 #ifdef BDB_HIER
        Avlnode         *bi_tree;
        ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
@@ -116,6 +133,14 @@ struct bdb_info {
 #ifdef LDAP_CLIENT_UPDATE
        LDAP_LIST_HEAD(pl, slap_op) psearch_list;
 #endif
+#ifdef SLAP_IDL_CACHE
+       int             bi_idl_cache_max_size;
+       int             bi_idl_cache_size;
+       Avlnode         *bi_idl_tree;
+       bdb_idl_cache_entry_t   *bi_idl_lru_head;
+       bdb_idl_cache_entry_t   *bi_idl_lru_tail;
+       ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
+#endif
 };
 
 #define bi_id2entry    bi_databases[BDB_ID2ENTRY]
index 90f99672f38a5cc71f6ce3a5b9baf5649f577f65..4ce4913aaca2b2bec9a4dde22cf2d2a7390999af 100644 (file)
@@ -135,6 +135,28 @@ bdb_db_config(
                  }
                  bdb->bi_cache.c_maxsize = atoi( argv[1] );
 
+       /* depth of search stack cache in units of (IDL)s */
+        } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
+                 if ( argc < 2 ) {
+                         fprintf( stderr,
+                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
+                             fname, lineno );
+                         return( 1 );
+                 }
+                 bdb->bi_search_stack_depth = atoi( argv[1] );
+
+#ifdef SLAP_IDL_CACHE
+       /* size of the IDL cache in entries */
+        } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
+                 if ( argc < 2 ) {
+                         fprintf( stderr,
+                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
+                             fname, lineno );
+                         return( 1 );
+                 }
+                 bdb->bi_idl_cache_max_size = atoi( argv[1] );
+#endif
+
        /* anything else */
        } else {
                fprintf( stderr, "%s: line %d: "
index e61cb9bda9ade479ba77a60c278a340ad8c89bff..46b013455771a395f10acfdb2bba24f8268b354e 100644 (file)
@@ -92,6 +92,8 @@ bdb_db_init( BackendDB *be )
        bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
 
        bdb->bi_lock_detect = DB_LOCK_DEFAULT;
+       bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
+       bdb->bi_search_stack = NULL;
 
 #ifdef LDAP_CLIENT_UPDATE
        LDAP_LIST_INIT (&bdb->psearch_list);
@@ -106,6 +108,7 @@ bdb_db_init( BackendDB *be )
 #endif
 
        be->be_private = bdb;
+
        return 0;
 }
 
@@ -184,6 +187,13 @@ bdb_db_open( BackendDB *be )
        bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
        bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
 
+#ifdef SLAP_IDL_CACHE
+       if ( bdb->bi_idl_cache_max_size ) {
+               ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_mutex );
+               bdb->bi_idl_cache_size = 0;
+       }
+#endif
+
 #ifdef BDB_SUBDIRS
        {
                char dir[MAXPATHLEN];
@@ -402,6 +412,9 @@ bdb_db_close( BackendDB *be )
        int rc;
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        struct bdb_db_info *db;
+#ifdef SLAP_IDL_CACHE
+       bdb_idl_cache_entry_t *entry, *next_entry;
+#endif
 
        while( bdb->bi_ndatabases-- ) {
                db = bdb->bi_databases[bdb->bi_ndatabases];
@@ -416,6 +429,19 @@ bdb_db_close( BackendDB *be )
 
        bdb_cache_release_all (&bdb->bi_cache);
 
+#ifdef SLAP_IDL_CACHE
+       ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
+       entry = bdb->bi_idl_lru_head;
+       while ( entry != NULL ) {
+               next_entry = entry->idl_lru_next;
+               free( entry->idl );
+               free( entry->kstr.bv_val );
+               free( entry );
+               entry = next_entry;
+       }
+       ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
+#endif
+
        return 0;
 }
 
index 8253288810fe2ca59e5496a87ad6410c033ee971..40abe31cd7494835fe293d2b1ea5c257a42b00de 100644 (file)
@@ -897,6 +897,38 @@ static int oc_filter(
        return rc;
 }
 
+static void search_stack_free( void *key, void *data)
+{
+       ch_free(data);
+}
+
+static void *search_stack(
+       BackendDB *be,
+       Operation *op
+)
+{
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       void *ret = NULL;
+
+       if ( op->o_threadctx ) {
+               ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
+                       &ret, NULL );
+       } else {
+               ret = bdb->bi_search_stack;
+       }
+
+       if ( !ret ) {
+               ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE * sizeof( ID ) );
+               if ( op->o_threadctx ) {
+                       ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
+                               ret, search_stack_free );
+               } else {
+                       bdb->bi_search_stack = ret;
+               }
+       }
+       return ret;
+}
+
 static int search_candidates(
        BackendDB *be,
        Operation *op,
@@ -906,6 +938,7 @@ static int search_candidates(
        int deref,
        ID      *ids )
 {
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        int rc, depth = 1;
        Filter          f, scopef, rf, xf;
        ID              *stack;
@@ -993,11 +1026,17 @@ static int search_candidates(
 #endif
 
        /* Allocate IDL stack, plus 1 more for former tmp */
-       stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
+       if ( depth+1 > bdb->bi_search_stack_depth ) {
+               stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
+       } else {
+               stack = search_stack( be, op );
+       }
 
        rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
 
-       ch_free( stack );
+       if ( depth+1 > bdb->bi_search_stack_depth ) {
+               ch_free( stack );
+       }
 
        if( rc ) {
 #ifdef NEW_LOGGING