From 76cff6da816c3cee31c63d33dced9e1a292c35b1 Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Fri, 14 Jun 2019 05:58:49 -0400 Subject: [PATCH] lib/ftl: Remove band from active/pending queue In case high priority band was added for relocation it should be removed from active/pending queue if it was already on one of them. Change-Id: Id0591b1d3a4174dd05eb1c32227e4d3b3a9cbcd0 Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458057 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto Reviewed-by: Konrad Sztyber --- lib/ftl/ftl_reloc.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/ftl/ftl_reloc.c b/lib/ftl/ftl_reloc.c index 2f24e1751..2a77a88ef 100644 --- a/lib/ftl/ftl_reloc.c +++ b/lib/ftl/ftl_reloc.c @@ -539,10 +539,10 @@ ftl_reloc_release(struct ftl_band_reloc *breloc) struct ftl_reloc *reloc = breloc->parent; struct ftl_band *band = breloc->band; - if (band->high_prio) { + if (band->high_prio && breloc->num_lbks == 0) { band->high_prio = 0; TAILQ_REMOVE(&reloc->prio_queue, breloc, entry); - } else { + } else if (!band->high_prio) { TAILQ_REMOVE(&reloc->active_queue, breloc, entry); } @@ -553,7 +553,7 @@ ftl_reloc_release(struct ftl_band_reloc *breloc) breloc->active = 0; reloc->num_active--; - if (breloc->num_lbks) { + if (!band->high_prio && breloc->num_lbks) { TAILQ_INSERT_TAIL(&reloc->pending_queue, breloc, entry); return; } @@ -785,6 +785,23 @@ ftl_reloc_add(struct ftl_reloc *reloc, struct ftl_band *band, size_t offset, } if (prio) { + struct ftl_band_reloc *iter_breloc; + + /* If priority band is already on pending or active queue, remove it from it */ + TAILQ_FOREACH(iter_breloc, &reloc->pending_queue, entry) { + if (breloc == iter_breloc) { + TAILQ_REMOVE(&reloc->pending_queue, breloc, entry); + break; + } + } + + TAILQ_FOREACH(iter_breloc, &reloc->active_queue, entry) { + if (breloc == iter_breloc) { + TAILQ_REMOVE(&reloc->active_queue, breloc, entry); + break; + } + } + TAILQ_INSERT_TAIL(&reloc->prio_queue, breloc, entry); ftl_band_acquire_lba_map(breloc->band); }