#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;
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;
#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]
}
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: "
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);
#endif
be->be_private = bdb;
+
return 0;
}
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];
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];
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;
}
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,
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;
#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