From: Piotr Dałek Date: Mon, 18 Jan 2016 12:27:35 +0000 (+0100) Subject: common/buffer: replace RWLock with spinlocks X-Git-Tag: v10.0.4~176^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=507774a9020f0a1e9ecc47569e5f84cae46bf600;p=ceph.git common/buffer: replace RWLock with spinlocks This decreases buffer::raw size by about 100 bytes (since RWLock occupies 104 bytes and simple_spinlock_t just 4) and also significantly decreases time wasted by locking and unlocking, possibly reducing context switches too. Particularly visible when using small blocksizes. Signed-off-by: Piotr Dałek --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index e2de936d8c4..864c7eefb9e 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -162,16 +162,16 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; unsigned len; atomic_t nref; - mutable RWLock crc_lock; + mutable simple_spinlock_t crc_spinlock; map, pair > crc_map; raw(unsigned l) : data(NULL), len(l), nref(0), - crc_lock("buffer::raw::crc_lock", false) + crc_spinlock(SIMPLE_SPINLOCK_INITIALIZER) { } raw(char *c, unsigned l) : data(c), len(l), nref(0), - crc_lock("buffer::raw::crc_lock", false) + crc_spinlock(SIMPLE_SPINLOCK_INITIALIZER) { } virtual ~raw() {} @@ -208,32 +208,29 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; } bool get_crc(const pair &fromto, pair *crc) const { - crc_lock.get_read(); + simple_spin_lock(&crc_spinlock); map, pair >::const_iterator i = crc_map.find(fromto); if (i == crc_map.end()) { - crc_lock.unlock(); + simple_spin_unlock(&crc_spinlock); return false; } *crc = i->second; - crc_lock.unlock(); + simple_spin_unlock(&crc_spinlock); return true; } void set_crc(const pair &fromto, const pair &crc) { - crc_lock.get_write(); + simple_spin_lock(&crc_spinlock); crc_map[fromto] = crc; - crc_lock.unlock(); + simple_spin_unlock(&crc_spinlock); } void invalidate_crc() { - // don't own the write lock when map is empty - crc_lock.get_read(); + simple_spin_lock(&crc_spinlock); if (crc_map.size() != 0) { - crc_lock.unlock(); - crc_lock.get_write(); crc_map.clear(); } - crc_lock.unlock(); + simple_spin_unlock(&crc_spinlock); } };