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: 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(). - Implement vectorized lbatview_elem_pblk().
- Dirty flag in compress header.
- Implement stats. - Implement stats.
- Keep working lbd, flush on timer. - Keep working lbd, flush on timer.
Need per-cpu lbd. Need per-cpu lbd.

View File

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

View File

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

View File

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

View File

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