From db034acf546a72739ff6543241543f3bd651f3ae Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Tue, 11 Feb 2014 11:53:00 -0800 Subject: [PATCH] ObjectCacher: use uint64_t for target and max values All the options are uint64_t, but the ObjectCacher was converting them to int64_t. There's never any reason for these to be negative, so change the type. Adjust a few conditionals so that they only convert known-positive signed values to uint64_t before comparing with the target and max values. Leave the actual stats accounting as loff_t for now, since bugs in accounting will have bad effects if negative values wrap around. Backport: emperor, dumpling Signed-off-by: Josh Durgin --- src/osdc/ObjectCacher.cc | 10 ++++++---- src/osdc/ObjectCacher.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc index 7273a3d0767e3..29dcaaaba5fd0 100644 --- a/src/osdc/ObjectCacher.cc +++ b/src/osdc/ObjectCacher.cc @@ -953,7 +953,7 @@ void ObjectCacher::trim() << ", objects: max " << max_objects << " current " << ob_lru.lru_get_size() << dendl; - while (get_stat_clean() > max_size) { + while (get_stat_clean() > 0 && (uint64_t) get_stat_clean() > max_size) { BufferHead *bh = static_cast(bh_lru_rest.lru_expire()); if (!bh) break; @@ -1353,7 +1353,9 @@ void ObjectCacher::maybe_wait_for_writeback(uint64_t len) // - do not wait for bytes other waiters are waiting on. this means that // threads do not wait for each other. this effectively allows the cache // size to balloon proportional to the data that is in flight. - while (get_stat_dirty() + get_stat_tx() >= max_dirty + get_stat_dirty_waiting()) { + while (get_stat_dirty() + get_stat_tx() > 0 && + (uint64_t) (get_stat_dirty() + get_stat_tx()) >= + max_dirty + get_stat_dirty_waiting()) { ldout(cct, 10) << __func__ << " waiting for dirty|tx " << (get_stat_dirty() + get_stat_tx()) << " >= max " << max_dirty << " + dirty_waiting " @@ -1408,7 +1410,7 @@ int ObjectCacher::_wait_for_write(OSDWrite *wr, uint64_t len, ObjectSet *oset, M } // start writeback anyway? - if (get_stat_dirty() > target_dirty) { + if (get_stat_dirty() > 0 && (uint64_t) get_stat_dirty() > target_dirty) { ldout(cct, 10) << "wait_for_write " << get_stat_dirty() << " > target " << target_dirty << ", nudging flusher" << dendl; flusher_cond.Signal(); @@ -1432,7 +1434,7 @@ void ObjectCacher::flusher_entry() << max_dirty << " max)" << dendl; loff_t actual = get_stat_dirty() + get_stat_dirty_waiting(); - if (actual > target_dirty) { + if (actual > 0 && (uint64_t) actual > target_dirty) { // flush some dirty pages ldout(cct, 10) << "flusher " << get_stat_dirty() << " dirty + " << get_stat_dirty_waiting() diff --git a/src/osdc/ObjectCacher.h b/src/osdc/ObjectCacher.h index aacafded6bfe7..54f028fdd7430 100644 --- a/src/osdc/ObjectCacher.h +++ b/src/osdc/ObjectCacher.h @@ -332,7 +332,7 @@ class ObjectCacher { string name; Mutex& lock; - int64_t max_dirty, target_dirty, max_size, max_objects; + uint64_t max_dirty, target_dirty, max_size, max_objects; utime_t max_dirty_age; bool block_writes_upfront; @@ -615,7 +615,7 @@ public: // cache sizes - void set_max_dirty(int64_t v) { + void set_max_dirty(uint64_t v) { max_dirty = v; } void set_target_dirty(int64_t v) { -- 2.39.5