Reset objects outside cache lock

Also update TODO
This commit is contained in:
Tom Marshall 2019-11-04 10:22:10 -08:00
parent f37155f527
commit cbf8777042
5 changed files with 24 additions and 47 deletions

5
TODO
View File

@ -20,12 +20,7 @@ Cache object sizing:
TODO:
- Allocate pbat pages using allocv and vmap them
(but only when pbat_len() > 1).
Can we vmap compression workspace?
- In *cache_get, call *_reset outside cache lock.
- Implement vectorized lbatview_elem_pblk().
- Dirty flag in compress header.
- Implement stats.
- Keep working lbd, flush on timer.
Need per-cpu lbd.

View File

@ -242,9 +242,10 @@ lbatpagecache_get(struct lbatpagecache* lpc, u64 pblk)
if (lp->ref == 0) {
goto found;
}
mutex_unlock(&lpc->lock);
++lp->ref;
mutex_unlock(&lp->reflock);
goto out;
return lp;
}
mutex_unlock(&lp->reflock);
}
@ -267,24 +268,21 @@ lbatpagecache_get(struct lbatpagecache* lpc, u64 pblk)
n = lpc->len;
if (!lbatpagecache_realloc(lpc, lpc->len * 2)) {
printk(KERN_ERR "%s: realloc failed\n", __func__);
lp = NULL;
goto out;
mutex_unlock(&lpc->lock);
return NULL;
}
lp = lpc->cache[n];
mutex_lock(&lp->reflock);
found:
mutex_unlock(&lpc->lock);
if (lbatpage_reset(lp, pblk) != 0) {
mutex_unlock(&lp->reflock);
lp = NULL;
goto out;
return NULL;
}
lp->ref = 1;
mutex_unlock(&lp->reflock);
out:
mutex_unlock(&lpc->lock);
return lp;
}
@ -296,7 +294,6 @@ lbatpagecache_put(struct lbatpagecache* lpc, struct lbatpage* lp)
if (!lp) {
return 0;
}
mutex_lock(&lpc->lock);
mutex_lock(&lp->reflock);
if (--lp->ref == 0) {
ret = lbatpage_flush(lp);
@ -305,7 +302,6 @@ lbatpagecache_put(struct lbatpagecache* lpc, struct lbatpage* lp)
}
}
mutex_unlock(&lp->reflock);
mutex_unlock(&lpc->lock);
return ret;
}

View File

@ -555,9 +555,10 @@ lbatviewcache_get(struct lbatviewcache* lvc, u64 lblk)
if (lv->ref == 0) {
goto found;
}
mutex_unlock(&lvc->lock);
++lv->ref;
mutex_unlock(&lv->reflock);
goto out;
return lv;
}
mutex_unlock(&lv->reflock);
}
@ -580,24 +581,21 @@ lbatviewcache_get(struct lbatviewcache* lvc, u64 lblk)
n = lvc->len;
if (!lbatviewcache_realloc(lvc, lvc->len * 2)) {
printk(KERN_ERR "%s: realloc failed\n", __func__);
lv = NULL;
goto out;
mutex_unlock(&lvc->lock);
return NULL;
}
lv = lvc->cache[n];
mutex_lock(&lv->reflock);
found:
mutex_unlock(&lvc->lock);
if (lbatview_reset(lv, pblk, count) != 0) {
mutex_unlock(&lv->reflock);
lv = NULL;
goto out;
return NULL;
}
lv->ref = 1;
mutex_unlock(&lv->reflock);
out:
mutex_unlock(&lvc->lock);
return lv;
}
@ -609,7 +607,6 @@ lbatviewcache_put(struct lbatviewcache* lvc, struct lbatview* lv)
if (!lv) {
return 0;
}
mutex_lock(&lvc->lock);
mutex_lock(&lv->reflock);
if (--lv->ref == 0) {
ret = lbatview_flush(lv);
@ -618,7 +615,6 @@ lbatviewcache_put(struct lbatviewcache* lvc, struct lbatview* lv)
}
}
mutex_unlock(&lv->reflock);
mutex_unlock(&lvc->lock);
return ret;
}

View File

@ -697,9 +697,10 @@ lbdcache_get(struct lbdcache* lc, u64 lblk)
if (lbd->ref == 0) {
goto found;
}
mutex_unlock(&lc->lock);
++lbd->ref;
mutex_unlock(&lbd->reflock);
goto out;
return lbd;
}
mutex_unlock(&lbd->reflock);
}
@ -719,29 +720,24 @@ lbdcache_get(struct lbdcache* lc, u64 lblk)
}
mutex_unlock(&lbd->reflock);
}
printk(KERN_INFO "%s: all objects in use, realloc...\n", __func__);
n = lc->len;
if (!lbdcache_realloc(lc, lc->len * 2)) {
printk(KERN_ERR "%s: realloc failed\n", __func__);
lbd = NULL;
goto out;
mutex_unlock(&lc->lock);
return NULL;
}
printk(KERN_INFO "%s: realloc done, using n=%u\n", __func__, n);
lbd = lc->cache[n];
mutex_lock(&lbd->reflock);
found:
mutex_unlock(&lc->lock);
if (lbd_reset(lbd, lblk) != 0) {
mutex_unlock(&lbd->reflock);
lbd = NULL;
goto out;
return NULL;
}
lbd->ref = 1;
mutex_unlock(&lbd->reflock);
out:
mutex_unlock(&lc->lock);
return lbd;
}
@ -753,7 +749,6 @@ lbdcache_put(struct lbdcache* lc, struct lbd* lbd)
if (!lbd) {
return 0;
}
mutex_lock(&lc->lock);
mutex_lock(&lbd->reflock);
if (--lbd->ref == 0) {
ret = lbd_flush(lbd);
@ -762,7 +757,6 @@ lbdcache_put(struct lbdcache* lc, struct lbd* lbd)
}
}
mutex_unlock(&lbd->reflock);
mutex_unlock(&lc->lock);
return ret;
}

View File

@ -315,9 +315,10 @@ pbatcache_get(struct pbatcache* pc, u32 zone)
if (pbat->ref == 0) {
goto found;
}
mutex_unlock(&pc->lock);
++pbat->ref;
mutex_unlock(&pbat->reflock);
goto out;
return pbat;
}
mutex_unlock(&pbat->reflock);
}
@ -341,24 +342,21 @@ pbatcache_get(struct pbatcache* pc, u32 zone)
n = pc->len;
if (!pbatcache_realloc(pc, pc->len * 2)) {
printk(KERN_ERR "%s: realloc failed\n", __func__);
pbat = NULL;
goto out;
mutex_unlock(&pc->lock);
return NULL;
}
pbat = pc->cache[n];
mutex_lock(&pbat->reflock);
found:
mutex_unlock(&pc->lock);
if (pbat_reset(pbat, zone) != 0) {
mutex_unlock(&pbat->reflock);
pbat = NULL;
goto out;
return NULL;
}
pbat->ref = 1;
mutex_unlock(&pbat->reflock);
out:
mutex_unlock(&pc->lock);
return pbat;
}
@ -370,7 +368,6 @@ pbatcache_put(struct pbatcache* pc, struct pbat* pbat)
if (!pbat) {
return 0;
}
mutex_lock(&pc->lock);
mutex_lock(&pbat->reflock);
if (--pbat->ref == 0) {
ret = pbat_flush(pbat);
@ -379,7 +376,6 @@ pbatcache_put(struct pbatcache* pc, struct pbat* pbat)
}
}
mutex_unlock(&pbat->reflock);
mutex_unlock(&pc->lock);
return ret;
}