osdc: For read w/ DONTNEED, if read data contain all cached data, move this object into the tail of LRU.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
This commit is contained in:
Jianpeng Ma 2015-01-30 13:21:44 +08:00
parent 3dca5ef508
commit ed209a5ea2
2 changed files with 25 additions and 0 deletions

View File

@ -176,6 +176,22 @@ bool ObjectCacher::Object::is_cached(loff_t cur, loff_t left)
return true;
}
/*
* all cached data in this range[off, off+len]
*/
bool ObjectCacher::Object::include_all_cached_data(loff_t off, loff_t len)
{
assert(oc->lock.is_locked());
if (data.empty())
return true;
map<loff_t, BufferHead*>::iterator first = data.begin();
map<loff_t, BufferHead*>::reverse_iterator last = data.rbegin();
if (first->second->start() >= off && last->second->end() <= (off + len))
return true;
else
return false;
}
/*
* map a range of bytes into buffer_heads.
* - create missing buffer_heads as necessary.
@ -1096,6 +1112,8 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish,
if (allzero) {
ldout(cct, 10) << "readx ob has all zero|rx, returning ENOENT" << dendl;
delete rd;
if (dontneed)
bottouch_ob(o);
return -ENOENT;
}
}
@ -1236,6 +1254,9 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish,
}
assert(f_it == ex_it->buffer_extents.end());
assert(opos == (loff_t)ex_it->offset + (loff_t)ex_it->length);
if (dontneed && o->include_all_cached_data(ex_it->offset, ex_it->length))
bottouch_ob(o);
}
}

View File

@ -288,6 +288,7 @@ class ObjectCacher {
void try_merge_bh(BufferHead *bh);
bool is_cached(loff_t off, loff_t len);
bool include_all_cached_data(loff_t off, loff_t len);
int map_read(OSDRead *rd,
map<loff_t, BufferHead*>& hits,
map<loff_t, BufferHead*>& missing,
@ -421,6 +422,9 @@ class ObjectCacher {
void touch_ob(Object *ob) {
ob_lru.lru_touch(ob);
}
void bottouch_ob(Object *ob) {
ob_lru.lru_bottouch(ob);
}
// bh states
void bh_set_state(BufferHead *bh, int s);