]> git.sur5r.net Git - openldap/commitdiff
Add EntryInfo free list
authorHoward Chu <hyc@openldap.org>
Sat, 27 Sep 2003 04:58:36 +0000 (04:58 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 27 Sep 2003 04:58:36 +0000 (04:58 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/cache.c
servers/slapd/back-bdb/proto-bdb.h

index 1146546160c98f8e02fca754cf242ed102190ec2..ed32c6b6fc5c8edb96b74aa75cc2f4a4fe1120e0 100644 (file)
@@ -113,6 +113,7 @@ typedef struct bdb_cache {
        int             c_maxsize;
        int             c_cursize;
        EntryInfo       c_dntree;
+       EntryInfo       *c_eifree;      /* free list */
        Avlnode         *c_idtree;
        EntryInfo       *c_lruhead;     /* lru - add accessed entries here */
        EntryInfo       *c_lrutail;     /* lru - rem lru entries from here */
index e5875e0c37324bf2f8356537db24305aceac5e87..baf2230e989a23222bce2b312f45412ee1497f19 100644 (file)
@@ -23,12 +23,24 @@ static void bdb_lru_print(Cache *cache);
 #endif
 
 static EntryInfo *
-bdb_cache_entryinfo_new( )
+bdb_cache_entryinfo_new( Cache *cache )
 {
-       EntryInfo *ei;
+       EntryInfo *ei = NULL;
 
-       ei = ch_calloc(1, sizeof(struct bdb_entry_info));
-       ldap_pvt_thread_mutex_init( &ei->bei_kids_mutex );
+       if ( cache->c_eifree ) {
+               ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
+               if ( cache->c_eifree ) {
+                       ei = cache->c_eifree;
+                       cache->c_eifree = ei->bei_lrunext;
+               }
+               ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+       }
+       if ( ei ) {
+               ei->bei_lrunext = NULL;
+       } else {
+               ei = ch_calloc(1, sizeof(struct bdb_entry_info));
+               ldap_pvt_thread_mutex_init( &ei->bei_kids_mutex );
+       }
 
        return ei;
 }
@@ -200,7 +212,7 @@ bdb_entryinfo_add_internal(
 
        *res = NULL;
 
-       ei2 = bdb_cache_entryinfo_new();
+       ei2 = bdb_cache_entryinfo_new( &bdb->bi_cache );
 
        ldap_pvt_thread_rdwr_wlock( &bdb->bi_cache.c_rwlock );
        bdb_cache_entryinfo_lock( ei->bei_parent );
@@ -356,7 +368,7 @@ hdb_cache_find_parent(
                ei2 = ein;
 
                /* Create a new node for the current ID */
-               ein = bdb_cache_entryinfo_new();
+               ein = bdb_cache_entryinfo_new( &bdb->bi_cache );
                ein->bei_id = ei.bei_id;
                ein->bei_kids = ei.bei_kids;
                ein->bei_nrdn = ei.bei_nrdn;
@@ -890,15 +902,36 @@ bdb_cache_delete(
 
 void
 bdb_cache_delete_cleanup(
+       Cache *cache,
        Entry *e
 )
 {
-       bdb_cache_entryinfo_unlock( BEI(e) );
-       bdb_cache_entryinfo_destroy( e->e_private );
+       EntryInfo *ei = BEI(e);
+
+       ei->bei_e = NULL;
        e->e_private = NULL;
        bdb_entry_return( e );
+
+       free( ei->bei_nrdn.bv_val );
+       ei->bei_nrdn.bv_val = NULL;
+#ifdef BDB_HIER
+       free( ei->bei_rdn.bv_val );
+       ei->bei_rdn.bv_val = NULL;
+       ei->bei_modrdns = 0;
+       ei->bei_ckids = 0;
+       ei->bei_dkids = 0;
+#endif
+       ei->bei_parent = NULL;
+       ei->bei_kids = NULL;
+       ei->bei_lruprev = NULL;
+
+       ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
+       ei->bei_lrunext = cache->c_eifree;
+       cache->c_eifree = ei;
+       ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+       bdb_cache_entryinfo_unlock( ei );
 }
-       
+
 static int
 bdb_cache_delete_internal(
     Cache      *cache,
@@ -1087,7 +1120,7 @@ bdb_cache_delete_entry(
        DB_LOCK *lock )
 {
        ldap_pvt_thread_rdwr_wlock( &bdb->bi_cache.c_rwlock );
-       if ( bdb_cache_entry_db_lock( bdb->bi_dbenv, locker, ei, 1, 1, &lock ) == 0 ) {
+       if ( bdb_cache_entry_db_lock( bdb->bi_dbenv, locker, ei, 1, 1, lock ) == 0 ) {
                if ( ei->bei_e && !(ei->bei_state & CACHE_ENTRY_NOT_LINKED )) {
                        LRU_DELETE( &bdb->bi_cache, ei );
                        ei->bei_e->e_private = NULL;
@@ -1095,7 +1128,7 @@ bdb_cache_delete_entry(
                        ei->bei_e = NULL;
                        --bdb->bi_cache.c_cursize;
                }
-               bdb_cache_entry_db_unlock( bdb->bi_dbenv, &lock );
+               bdb_cache_entry_db_unlock( bdb->bi_dbenv, lock );
        }
        ldap_pvt_thread_rdwr_wunlock( &bdb->bi_cache.c_rwlock );
 }
index 9ad2193503537c90c39b6923ce7be3e4b47f7274..aabcfa8de33912c659219dda02335ef5472afa1a 100644 (file)
@@ -476,6 +476,7 @@ int bdb_cache_delete(
        DB_LOCK *lock
 );
 void bdb_cache_delete_cleanup(
+       Cache   *cache,
        Entry   *e
 );
 void bdb_cache_release_all( Cache *cache );