From: Howard Chu Date: Sat, 27 Sep 2003 04:58:36 +0000 (+0000) Subject: Add EntryInfo free list X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~643 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=121c73d838b06469e295cdd4a5a5c0d475a44023;p=openldap Add EntryInfo free list --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 1146546160..ed32c6b6fc 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -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 */ diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index e5875e0c37..baf2230e98 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -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 ); } diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 9ad2193503..aabcfa8de3 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -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 );