From c76eb501ab6152a525b9164265a203b8a771d1d4 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 5 Apr 2006 07:17:11 +0000 Subject: [PATCH] Revert cache-purge task, go back to purging inline --- servers/slapd/back-bdb/back-bdb.h | 1 - servers/slapd/back-bdb/cache.c | 81 +++++++------------------------ 2 files changed, 18 insertions(+), 64 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 4405d82f50..c6788417e9 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -180,7 +180,6 @@ struct bdb_info { u_int32_t bi_txn_cp_kbyte; struct re_s *bi_txn_cp_task; struct re_s *bi_index_task; - struct re_s *bi_cache_task; int bi_lock_detect; long bi_shm_key; diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index db71ca70ce..4bff759a9e 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -186,8 +186,10 @@ bdb_cache_entryinfo_destroy( EntryInfo *e ) } \ (cache)->c_lruhead = (ei); \ (ei)->bei_lruprev = NULL; \ - if ( (cache)->c_lrutail == NULL ) { \ - (cache)->c_lrutail = (ei); \ + if ( !ldap_pvt_thread_mutex_trylock( &(cache)->lru_tail_mutex )) { \ + if ( (cache)->c_lrutail == NULL ) \ + (cache)->c_lrutail = (ei); \ + ldap_pvt_thread_mutex_unlock( &(cache)->lru_tail_mutex ); \ } \ } while(0) @@ -529,15 +531,25 @@ int hdb_cache_load( } #endif -static void * -bdb_cache_lru_purge(void *ctx, void *arg) +/* caller must have lru_head_mutex locked. mutex + * will be unlocked on return. + */ +static void +bdb_cache_lru_add( + struct bdb_info *bdb, + EntryInfo *ei ) { - struct re_s *rtask = arg; - struct bdb_info *bdb = rtask->arg; DB_LOCK lock, *lockp; EntryInfo *elru, *elprev; int count = 0; + LRU_ADD( &bdb->bi_cache, ei ); + ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.lru_head_mutex ); + + /* See if we're above the cache size limit */ + if ( bdb->bi_cache.c_cursize <= bdb->bi_cache.c_maxsize ) + return; + if ( bdb->bi_cache.c_locker ) { lockp = &lock; } else { @@ -610,63 +622,6 @@ bdb_cache_lru_purge(void *ctx, void *arg) } ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.lru_tail_mutex ); - - /* If we're running as a task, drop the task */ - if ( ctx ) { - ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); - ldap_pvt_runqueue_stoptask( &slapd_rq, rtask ); - /* Defer processing till we're needed again */ - ldap_pvt_runqueue_resched( &slapd_rq, rtask, 1 ); - ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - } - - return NULL; -} - -/* caller must have lru_head_mutex locked. mutex - * will be unlocked on return. - */ -static void -bdb_cache_lru_add( - struct bdb_info *bdb, - EntryInfo *ei ) -{ - LRU_ADD( &bdb->bi_cache, ei ); - ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.lru_head_mutex ); - - /* See if we're above the cache size limit */ - if ( bdb->bi_cache.c_cursize > bdb->bi_cache.c_maxsize ) { - if ( slapMode & SLAP_TOOL_MODE ) { - struct re_s rtask; - - rtask.arg = bdb; - bdb_cache_lru_purge( NULL, &rtask ); - } else { - int wake = 0; - ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); - if ( bdb->bi_cache_task ) { - if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, - bdb->bi_cache_task )) { - /* We want it to start right now */ - bdb->bi_cache_task->interval.tv_sec = 0; - ldap_pvt_runqueue_resched( &slapd_rq, bdb->bi_cache_task, - 0 ); - /* But don't try to reschedule it while it's running */ - bdb->bi_cache_task->interval.tv_sec = 3600; - wake = 1; - } - } else { - bdb->bi_cache_task = ldap_pvt_runqueue_insert( &slapd_rq, 3600, - bdb_cache_lru_purge, bdb, "bdb_cache_lru_purge", - bdb->bi_dbenv_home ); - wake = 1; - } - ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - /* Don't bother waking if the purge task is already running */ - if ( wake ) - slap_wake_listener(); - } - } } EntryInfo * -- 2.39.5