linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com,
	Heinz.Egger@linutronix.de, thomas.wucher@linutronix.de,
	shmulik.ladkani@gmail.com, tglx@linutronix.de,
	tim.bird@am.sony.com, Marius.Mazarel@ugal.ro,
	artem.bityutskiy@linux.intel.com, nyoushchenko@mvista.com,
	Richard Weinberger <richard@nod.at>
Subject: [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool.
Date: Sat, 23 Jun 2012 15:03:18 +0200	[thread overview]
Message-ID: <1340456602-46050-4-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1340456602-46050-1-git-send-email-richard@nod.at>

If we have no fastmap on flash make sure that not all anchor
PEBs go into a WL pool such that at least one can be used
by fastmap.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/wl.c |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index b4d4358..8b2af8f4 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -342,16 +342,18 @@ static void prot_queue_add(struct ubi_device *ubi, struct ubi_wl_entry *e)
 
 /**
  * find_wl_entry - find wear-leveling entry closest to certain erase counter.
+ * @ubi: UBI device description object
  * @root: the RB-tree where to look for
  * @diff: maximum possible difference from the smallest erase counter
  *
  * This function looks for a wear leveling entry with erase counter closest to
  * min + @diff, where min is the smallest erase counter.
  */
-static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff)
+static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi, struct rb_root *root,
+					  int diff)
 {
 	struct rb_node *p;
-	struct ubi_wl_entry *e;
+	struct ubi_wl_entry *e, *prev_e = NULL;
 	int max;
 
 	e = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb);
@@ -366,32 +368,48 @@ static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff)
 			p = p->rb_left;
 		else {
 			p = p->rb_right;
+			prev_e = e;
 			e = e1;
 		}
 	}
 
+	/* If no fastmap has been written and this WL entry can be used
+	 * as anchor PEB, hold it back and return the second best WL entry
+	 * such that fastmap can use the anchor PEB later. */
+	if (!ubi->fm && e->pnum < UBI_FM_MAX_START)
+		return prev_e;
+
 	return e;
 }
 
 /**
  * find_mean_wl_entry - find wear-leveling entry with medium erase counter.
+ * @ubi: UBI device description object
  * @root: the RB-tree where to look for
  *
  * This function looks for a wear leveling entry with medium erase counter,
  * but not greater or equivalent than the lowest erase counter plus
  * %WL_FREE_MAX_DIFF/2.
  */
-static struct ubi_wl_entry *find_mean_wl_entry(struct rb_root *root)
+static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
+					       struct rb_root *root)
 {
 	struct ubi_wl_entry *e, *first, *last;
 
 	first = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb);
 	last = rb_entry(rb_last(root), struct ubi_wl_entry, u.rb);
 
-	if (last->ec - first->ec < WL_FREE_MAX_DIFF)
+	if (last->ec - first->ec < WL_FREE_MAX_DIFF) {
 		e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
+
+		/* If no fastmap has been written and this WL entry can be used
+		 * as anchor PEB, hold it back and return the second best WL entry
+		 * such that fastmap can use the anchor PEB later. */
+		if (e && !ubi->fm && e->pnum < UBI_FM_MAX_START)
+			e = rb_entry(rb_next(root->rb_node), struct ubi_wl_entry, u.rb);
+	}
 	else
-		e = find_wl_entry(root, WL_FREE_MAX_DIFF/2);
+		e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2);
 
 	return e;
 }
@@ -452,7 +470,7 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
 	}
 
 	if (max_pnum < 0)
-		e = find_mean_wl_entry(&ubi->free);
+		e = find_mean_wl_entry(ubi, &ubi->free);
 	else
 		e = find_anchor_wl_entry(&ubi->free, max_pnum);
 
@@ -494,7 +512,7 @@ retry:
 		goto retry;
 	}
 
-	e = find_mean_wl_entry(&ubi->free);
+	e = find_mean_wl_entry(ubi, &ubi->free);
 
 	self_check_in_wl_tree(ubi, e, &ubi->free);
 
@@ -547,7 +565,7 @@ static void refill_wl_pool(struct ubi_device *ubi)
 		if (!ubi->free.rb_node)
 			break;
 
-		e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);
+		e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
 		self_check_in_wl_tree(ubi, e, &ubi->free);
 		rb_erase(&e->u.rb, &ubi->free);
 
@@ -1241,7 +1259,7 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested)
 		 * %UBI_WL_THRESHOLD.
 		 */
 		e1 = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb);
-		e2 = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);
+		e2 = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF);
 
 		if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD))
 			goto out_unlock;
-- 
1.7.6.5


  parent reply	other threads:[~2012-06-23 13:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
2012-06-23 13:03 ` [PATCH 1/7] UBI: Fastmap: Modify the WL sub-system to prodcue a free anchor PEB Richard Weinberger
2012-06-23 13:03 ` [PATCH 2/7] UBI: Fastmap: Fix WARN_ON() Richard Weinberger
2012-06-23 13:03 ` Richard Weinberger [this message]
2012-06-23 13:03 ` [PATCH 4/7] UBI: Fastmap: Fix ubi_assert() Richard Weinberger
2012-06-23 13:03 ` [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic Richard Weinberger
2012-06-23 13:03 ` [PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are available Richard Weinberger
2012-06-23 13:03 ` [PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex Richard Weinberger
2012-06-27  4:20 ` UBI fastmap updates Namjae Jeon
2012-06-27  6:48   ` Nikita V. Youshchenko
2012-06-27  7:17     ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340456602-46050-4-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=Heinz.Egger@linutronix.de \
    --cc=Marius.Mazarel@ugal.ro \
    --cc=adrian.hunter@intel.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nyoushchenko@mvista.com \
    --cc=shmulik.ladkani@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.wucher@linutronix.de \
    --cc=tim.bird@am.sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).