* [PATCH] ubi: fastmap: harmonize medium erase-counter seek algorithm
@ 2012-05-29 13:48 Shmulik Ladkani
2012-05-30 10:18 ` Richard Weinberger
0 siblings, 1 reply; 2+ messages in thread
From: Shmulik Ladkani @ 2012-05-29 13:48 UTC (permalink / raw)
To: Artem Bityutskiy, Richard Weinberger
Cc: Heinz.Egger, tglx, linux-mtd, tim.bird
Currently, there are two different locations where a wear-leveling entry
with a medium erase counter is looked-for, with the same search algorithm
duplicated.
Harmonize this by introducing a common function 'find_mean_wl_entry'.
Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
---
Compile tested.
Applies to branch fastmap on linux-ubi.
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 7d34495..6727b6c 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -386,6 +386,29 @@ static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff)
}
/**
+ * find_mean_wl_entry - find wear-leveling entry with medium erase counter.
+ * @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)
+{
+ 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)
+ e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
+ else
+ e = find_wl_entry(root, WL_FREE_MAX_DIFF/2);
+
+ return e;
+}
+
+/**
* find_early_wl_entry - find wear-leveling entry with the lowest pnum.
* @root: the RB-tree where to look for
* @max_pnum: highest possible pnum
@@ -419,7 +442,7 @@ static struct ubi_wl_entry *find_early_wl_entry(struct rb_root *root,
int ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
{
int ret = -ENOSPC;
- struct ubi_wl_entry *e, *first, *last;
+ struct ubi_wl_entry *e;
if (!ubi->free.rb_node) {
ubi_err("no free eraseblocks");
@@ -427,18 +450,9 @@ int ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
goto out;
}
- if (max_pnum < 0) {
- first = rb_entry(rb_first(&ubi->free),
- struct ubi_wl_entry, u.rb);
- last = rb_entry(rb_last(&ubi->free),
- struct ubi_wl_entry, u.rb);
-
- if (last->ec - first->ec < WL_FREE_MAX_DIFF)
- e = rb_entry(ubi->free.rb_node,
- struct ubi_wl_entry, u.rb);
- else
- e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
- } else
+ if (max_pnum < 0)
+ e = find_mean_wl_entry(&ubi->free);
+ else
e = find_early_wl_entry(&ubi->free, max_pnum);
if (!e)
@@ -464,7 +478,7 @@ out:
static int __ubi_wl_get_peb(struct ubi_device *ubi)
{
int err;
- struct ubi_wl_entry *e, *first, *last;
+ struct ubi_wl_entry *e;
retry:
spin_lock(&ubi->wl_lock);
@@ -483,13 +497,7 @@ retry:
goto retry;
}
- first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb);
- last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb);
-
- if (last->ec - first->ec < WL_FREE_MAX_DIFF)
- e = rb_entry(ubi->free.rb_node, struct ubi_wl_entry, u.rb);
- else
- e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
+ e = find_mean_wl_entry(&ubi->free);
self_check_in_wl_tree(ubi, e, &ubi->free);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ubi: fastmap: harmonize medium erase-counter seek algorithm
2012-05-29 13:48 [PATCH] ubi: fastmap: harmonize medium erase-counter seek algorithm Shmulik Ladkani
@ 2012-05-30 10:18 ` Richard Weinberger
0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2012-05-30 10:18 UTC (permalink / raw)
To: Shmulik Ladkani; +Cc: Heinz.Egger, tglx, linux-mtd, tim.bird, Artem Bityutskiy
[-- Attachment #1: Type: text/plain, Size: 394 bytes --]
Am 29.05.2012 15:48, schrieb Shmulik Ladkani:
> Currently, there are two different locations where a wear-leveling entry
> with a medium erase counter is looked-for, with the same search algorithm
> duplicated.
>
> Harmonize this by introducing a common function 'find_mean_wl_entry'.
>
> Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Applied!
Thanks,
//richard
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-30 10:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-29 13:48 [PATCH] ubi: fastmap: harmonize medium erase-counter seek algorithm Shmulik Ladkani
2012-05-30 10:18 ` Richard Weinberger
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).