From ea773779cdf8621c4d1ca13fed2fff4c239d3608 Mon Sep 17 00:00:00 2001 From: dormando Date: Mon, 9 Jan 2017 01:03:09 -0800 Subject: stop using atomics for item refcount management when I first split the locks up further I had a trick where "item_remove()" did not require holding the associated item lock. If an item were to be freed, it would then do the necessary work.; Since then, all calls to refcount_incr and refcount_decr only happen while the item is locked. This was mostly due to the slab mover being very tricky with locks. The atomic is no longer needed as the refcount is only ever checked after a lock to the item. Calling atomics is pretty expensive, especially in multicore/multisocket scenarios. This yields a notable performance increase. --- crawler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crawler.c') diff --git a/crawler.c b/crawler.c index 3ee2c39..43245ea 100644 --- a/crawler.c +++ b/crawler.c @@ -199,7 +199,7 @@ static void crawler_expired_eval(crawler_module_t *cm, item *search, uint32_t hv assert(search->slabs_clsid == 0); } else { s->seen++; - refcount_decr(&search->refcount); + refcount_decr(search); if (search->exptime == 0) { s->noexp++; } else if (search->exptime - current_time > 3599) { @@ -220,7 +220,7 @@ static void crawler_metadump_eval(crawler_module_t *cm, item *it, uint32_t hv, i /* Ignore expired content. */ if ((it->exptime != 0 && it->exptime < current_time) || is_flushed) { - refcount_decr(&it->refcount); + refcount_decr(it); return; } // TODO: uriencode directly into the buffer. @@ -232,7 +232,7 @@ static void crawler_metadump_eval(crawler_module_t *cm, item *it, uint32_t hv, i (unsigned long long)it->time + process_started, (unsigned long long)ITEM_get_cas(it), (it->it_flags & ITEM_FETCHED) ? "yes" : "no"); - refcount_decr(&it->refcount); + refcount_decr(it); // TODO: some way of tracking the errors. these are very unlikely though. if (total >= LRU_CRAWLER_WRITEBUF - 1 || total <= 0) { /* Failed to write, don't push it. */ @@ -366,8 +366,8 @@ static void *item_crawler_thread(void *arg) { continue; } /* Now see if the item is refcount locked */ - if (refcount_incr(&search->refcount) != 2) { - refcount_decr(&search->refcount); + if (refcount_incr(search) != 2) { + refcount_decr(search); if (hold_lock) item_trylock_unlock(hold_lock); pthread_mutex_unlock(&lru_locks[i]); -- cgit v1.2.1