summaryrefslogtreecommitdiff
path: root/nscd/cache.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-05-18 21:54:43 +0000
committerUlrich Drepper <drepper@redhat.com>2008-05-18 21:54:43 +0000
commit528741cb6c7218e7f2f764fa10aa7e67699eadaa (patch)
tree8efc5ed6f0928d593cb6fff0fe2275aba2f07b68 /nscd/cache.c
parent5811d72b73328601ace56b3ef41043b3e9eec84f (diff)
downloadglibc-528741cb6c7218e7f2f764fa10aa7e67699eadaa.tar.gz
* nscd/cache.c (cache_add): Take additional parameter specifying
whether this is in response of a cache refill. Check alignment of package data. Revamp waking of pruning thread. (prune_cache): Small optimization. * nscd/nscd.h: Adjust cache_add prototypes. * nscd/aicache.c: Adjust cache_add calls. * nscd/grpcache.c: Likewise. * nscd/hstcache.c: Likewise. * nscd/initgrcache.c: Likewise. * nscd/pwdcache.c: Likewise. * nscd/servicescache.c: Likewise. * nscd/connections.c (restart): Really disable cache use before exec attempt. If it fails, reenable cache. (nscd_run_prune): Initialize wakeup_time. After wakeup, set wakeup time to max to be able to notice concurrent cache additions. Unlock prune_lock while performing gc. Afterwards compute wakeup time with current wakeup_time value in mind.
Diffstat (limited to 'nscd/cache.c')
-rw-r--r--nscd/cache.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/nscd/cache.c b/nscd/cache.c
index f4a9de530a..2faaf3403e 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -135,7 +135,7 @@ cache_search (request_type type, void *key, size_t len,
int
cache_add (int type, const void *key, size_t len, struct datahead *packet,
bool first, struct database_dyn *table,
- uid_t owner)
+ uid_t owner, bool prune_wakeup)
{
if (__builtin_expect (debug_level >= 2, 0))
{
@@ -180,6 +180,7 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
assert (newp->key + newp->len <= table->head->first_free);
newp->owner = owner;
newp->packet = (char *) packet - table->data;
+ assert ((newp->packet & BLOCK_ALIGN_M1) == 0);
/* Put the new entry in the first position. */
do
@@ -211,19 +212,27 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
(char *) &table->head->array[hash] - (char *) table->head
+ sizeof (ref_t), MS_ASYNC);
- /* Perhaps the prune thread for the data is not running in a long
- time. Wake it if necessary. */
- time_t next_wakeup = table->wakeup_time;
- while (next_wakeup + CACHE_PRUNE_INTERVAL > packet->timeout)
- if (atomic_compare_and_exchange_bool_acq (&table->wakeup_time,
- packet->timeout,
- next_wakeup) == 0)
- {
+ /* We do not have to worry about the pruning thread if we are
+ re-adding the data since this is done by the pruning thread. We
+ also do not have to do anything in case this is not the first
+ time the data is entered since different data heads all have the
+ same timeout. */
+ if (first && prune_wakeup)
+ {
+ /* Perhaps the prune thread for the table is not running in a long
+ time. Wake it if necessary. */
+ pthread_mutex_lock (&table->prune_lock);
+ time_t next_wakeup = table->wakeup_time;
+ bool do_wakeup = false;
+ if (next_wakeup > packet->timeout + CACHE_PRUNE_INTERVAL)
+ {
+ table->wakeup_time = packet->timeout;
+ do_wakeup = true;
+ }
+ pthread_mutex_unlock (&table->prune_lock);
+ if (do_wakeup)
pthread_cond_signal (&table->prune_cond);
- break;
- }
- else
- next_wakeup = table->wakeup_time;
+ }
/* Mark the in-flight memory as unused. */
for (enum in_flight idx = 0; idx < IDX_last; ++idx)
@@ -436,7 +445,8 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
ref_t *old = &table->head->array[first];
ref_t run = table->head->array[first];
- while (run != ENDREF)
+ assert (run != ENDREF);
+ do
{
struct hashentry *runp = (struct hashentry *) (data + run);
struct datahead *dh
@@ -462,6 +472,7 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
run = runp->next;
}
}
+ while (run != ENDREF);
}
++first;