From cbf8777042df422bf537c02eb51470e449e9a3ce Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Mon, 4 Nov 2019 10:22:10 -0800 Subject: [PATCH] Reset objects outside cache lock Also update TODO --- TODO | 5 ----- dm-compress/lbatpage.c | 16 ++++++---------- dm-compress/lbatview.c | 16 ++++++---------- dm-compress/lbd.c | 18 ++++++------------ dm-compress/pbat.c | 16 ++++++---------- 5 files changed, 24 insertions(+), 47 deletions(-) diff --git a/TODO b/TODO index b805e88..8f81adb 100644 --- a/TODO +++ b/TODO @@ -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. diff --git a/dm-compress/lbatpage.c b/dm-compress/lbatpage.c index eafb99b..2729862 100644 --- a/dm-compress/lbatpage.c +++ b/dm-compress/lbatpage.c @@ -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; } diff --git a/dm-compress/lbatview.c b/dm-compress/lbatview.c index 34a448d..821f268 100644 --- a/dm-compress/lbatview.c +++ b/dm-compress/lbatview.c @@ -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; } diff --git a/dm-compress/lbd.c b/dm-compress/lbd.c index ba723b7..ff55b49 100644 --- a/dm-compress/lbd.c +++ b/dm-compress/lbd.c @@ -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; } diff --git a/dm-compress/pbat.c b/dm-compress/pbat.c index 1a47ad8..bfb2207 100644 --- a/dm-compress/pbat.c +++ b/dm-compress/pbat.c @@ -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; }