]> git.sur5r.net Git - openldap/commitdiff
From ITS#2183, use a long-lived IDL stack per thread.
authorHoward Chu <hyc@openldap.org>
Tue, 10 Dec 2002 17:59:21 +0000 (17:59 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 10 Dec 2002 17:59:21 +0000 (17:59 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/search.c

index b896191e27b9cbd8c4f439db1dd29fd57d17b6b9..b41aed3a3e59487a6ce1768b9ce3c9dbe567f8e1 100644 (file)
@@ -99,6 +99,7 @@ struct bdb_info {
        slap_mask_t     bi_defaultmask;
        Cache           bi_cache;
        Avlnode         *bi_attrs;
+       void            *bi_search_stack;
 #ifdef BDB_HIER
        Avlnode         *bi_tree;
        ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
index 2ad1e9668928b66e24219c3476cc47e5a67728a1..bd9ac9590a7d8a43f9225f24ebc022c0f88c3549 100644 (file)
@@ -957,6 +957,40 @@ static int oc_filter(
        return rc;
 }
 
+#define SRCH_STACK_SIZE        16
+
+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( SRCH_STACK_SIZE * 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,
@@ -1053,11 +1087,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 > SRCH_STACK_SIZE ) {
+               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 > SRCH_STACK_SIZE ) {
+               ch_free( stack );
+       }
 
        if( rc ) {
 #ifdef NEW_LOGGING