* UBI fastmap updates
@ 2012-06-23 13:03 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
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko
This is the next round of UBI fastmap updates.
The highlights are:
- Fastmap produces anchor PEBs if none are available
(creating a fastmap on an image created by ubinize works now)
- Fastmap is now able to reuse all PEBs if no empty PEBs are available
- Minor fixes
If you want to test fastmap you can use my git repo:
git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubi2.git ubi2/v13
Enjoy!
//richard
[PATCH 1/7] UBI: Fastmap: Modify the WL sub-system to prodcue a free
[PATCH 2/7] UBI: Fastmap: Fix WARN_ON()
[PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a
[PATCH 4/7] UBI: Fastmap: Fix ubi_assert()
[PATCH 5/7] UBI: Fastmap: Kill max_pnum logic
[PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are
[PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/7] UBI: Fastmap: Modify the WL sub-system to prodcue a free anchor PEB
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
@ 2012-06-23 13:03 ` Richard Weinberger
2012-06-23 13:03 ` [PATCH 2/7] UBI: Fastmap: Fix WARN_ON() Richard Weinberger
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 6 ++++
drivers/mtd/ubi/ubi.h | 3 ++
drivers/mtd/ubi/wl.c | 60 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 582f5ee..4793ba8 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1374,6 +1374,12 @@ int ubi_update_fastmap(struct ubi_device *ubi)
return 0;
}
+ ret = ubi_ensure_anchor_pebs(ubi);
+ if (ret) {
+ mutex_unlock(&ubi->fm_mutex);
+ return ret;
+ }
+
new_fm = kzalloc(sizeof(*new_fm), GFP_KERNEL);
if (!new_fm) {
mutex_unlock(&ubi->fm_mutex);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 534e851..56b1c5c 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -663,6 +663,7 @@ struct ubi_attach_info {
* @func: worker function
* @e: physical eraseblock to erase
* @torture: if the physical eraseblock has to be tortured
+ * @anchor: produce a anchor PEB to by used by fastmap
*
* The @func pointer points to the worker function. If the @cancel argument is
* not zero, the worker has to free the resources and exit immediately. The
@@ -675,6 +676,7 @@ struct ubi_work {
/* The below fields are only relevant to erasure works */
struct ubi_wl_entry *e;
int torture;
+ int anchor;
};
#include "debug.h"
@@ -759,6 +761,7 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum);
int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *used_e, int torture);
int ubi_is_erase_work(struct ubi_work *wrk);
void ubi_refill_pools(struct ubi_device *ubi);
+int ubi_ensure_anchor_pebs(struct ubi_device *ubi);
/* io.c */
int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 6771f30..b4d4358 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -419,6 +419,18 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root,
return victim;
}
+static int anchor_pebs_avalible(struct rb_root *root, int max_pnum)
+{
+ struct rb_node *p;
+ struct ubi_wl_entry *e;
+
+ ubi_rb_for_each_entry(p, e, root, u.rb)
+ if (e->pnum < max_pnum)
+ return 1;
+
+ return 0;
+}
+
/**
* ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
* @ubi: UBI device description object
@@ -901,10 +913,11 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
int cancel)
{
int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
- int vol_id = -1, uninitialized_var(lnum);
+ int anchor, vol_id = -1, uninitialized_var(lnum);
struct ubi_wl_entry *e1, *e2;
struct ubi_vid_hdr *vid_hdr;
+ anchor = wrk->anchor;
kfree(wrk);
if (cancel)
return 0;
@@ -935,7 +948,23 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
goto out_cancel;
}
- if (!ubi->scrub.rb_node) {
+ /* Check whether we need to produce an anchor PEB */
+ if (!anchor)
+ anchor = !anchor_pebs_avalible(&ubi->free, UBI_FM_MAX_START);
+
+ if (anchor) {
+ e1 = find_anchor_wl_entry(&ubi->used, UBI_FM_MAX_START);
+ if (!e1)
+ goto out_cancel;
+ e2 = get_peb_for_wl(ubi);
+ if (!e2)
+ goto out_cancel;
+
+ self_check_in_wl_tree(ubi, e1, &ubi->used);
+ rb_erase(&e1->u.rb, &ubi->used);
+ dbg_wl("anchor-move PEB %d to PEB %d", e1->pnum, e2->pnum);
+ }
+ else if (!ubi->scrub.rb_node) {
/*
* Now pick the least worn-out used physical eraseblock and a
* highly worn-out free physical eraseblock. If the erase
@@ -1229,6 +1258,7 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested)
goto out_cancel;
}
+ wrk->anchor = 0;
wrk->func = &wear_leveling_worker;
if (nested)
__schedule_ubi_work(ubi, wrk);
@@ -1244,6 +1274,32 @@ out_unlock:
return err;
}
+int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
+{
+ struct ubi_work *wrk;
+
+ spin_lock(&ubi->wl_lock);
+ if (ubi->wl_scheduled) {
+ spin_unlock(&ubi->wl_lock);
+ return 0;
+ }
+ ubi->wl_scheduled = 1;
+ spin_unlock(&ubi->wl_lock);
+
+ wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
+ if (!wrk) {
+ spin_lock(&ubi->wl_lock);
+ ubi->wl_scheduled = 0;
+ spin_unlock(&ubi->wl_lock);
+ return -ENOMEM;
+ }
+
+ wrk->anchor = 1;
+ wrk->func = &wear_leveling_worker;
+ schedule_ubi_work(ubi, wrk);
+ return 0;
+}
+
/**
* erase_worker - physical eraseblock erase worker function.
* @ubi: UBI device description object
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/7] UBI: Fastmap: Fix WARN_ON()
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 ` Richard Weinberger
2012-06-23 13:03 ` [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool Richard Weinberger
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
ubi->bad_peb_count is not jet valid, use ai->
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 4793ba8..2ff0681 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1005,7 +1005,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
* and we cannot fall back to scanning.
*/
if (WARN_ON(self_check_fastmap(ai) != ubi->peb_count -
- ubi->bad_peb_count - used_blocks)) {
+ ai->bad_peb_count - used_blocks)) {
ret = UBI_BAD_FASTMAP;
kfree(fm);
goto free_hdr;
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool.
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
2012-06-23 13:03 ` [PATCH 4/7] UBI: Fastmap: Fix ubi_assert() Richard Weinberger
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/7] UBI: Fastmap: Fix ubi_assert()
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
` (2 preceding siblings ...)
2012-06-23 13:03 ` [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool Richard Weinberger
@ 2012-06-23 13:03 ` Richard Weinberger
2012-06-23 13:03 ` [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic Richard Weinberger
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
An EC value of zero is allowed
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/wl.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 8b2af8f4..5f6e81e 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -905,7 +905,7 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e,
*/
if (!e) {
e = fm_e;
- ubi_assert(e->ec);
+ ubi_assert(e->ec >= 0);
ubi->lookuptbl[pnum] = e;
} else {
e->ec = fm_e->ec;
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
` (3 preceding siblings ...)
2012-06-23 13:03 ` [PATCH 4/7] UBI: Fastmap: Fix ubi_assert() Richard Weinberger
@ 2012-06-23 13:03 ` Richard Weinberger
2012-06-23 13:03 ` [PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are available Richard Weinberger
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
UBI_FM_MAX_START is constant, no need to mess around with max_pnum.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 4 ++--
drivers/mtd/ubi/ubi.h | 2 +-
drivers/mtd/ubi/wl.c | 26 +++++++++++---------------
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2ff0681..acd0561 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1420,7 +1420,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
for (i = 1; i < new_fm->used_blocks; i++) {
spin_lock(&ubi->wl_lock);
- tmp_e = ubi_wl_get_fm_peb(ubi, -1);
+ tmp_e = ubi_wl_get_fm_peb(ubi, 0);
spin_unlock(&ubi->wl_lock);
if (!tmp_e) {
@@ -1439,7 +1439,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
}
spin_lock(&ubi->wl_lock);
- tmp_e = ubi_wl_get_fm_peb(ubi, UBI_FM_MAX_START);
+ tmp_e = ubi_wl_get_fm_peb(ubi, 1);
spin_unlock(&ubi->wl_lock);
if (old_fm) {
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 56b1c5c..a2c1bcc 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -757,7 +757,7 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum);
int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
void ubi_wl_close(struct ubi_device *ubi);
int ubi_thread(void *u);
-struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum);
+struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor);
int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *used_e, int torture);
int ubi_is_erase_work(struct ubi_work *wrk);
void ubi_refill_pools(struct ubi_device *ubi);
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 5f6e81e..4f8b06a 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -417,19 +417,16 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
/**
* find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
* @root: the RB-tree where to look for
- * @max_pnum: highest possible pnum
*/
-static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root,
- int max_pnum)
+static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
{
struct rb_node *p;
struct ubi_wl_entry *e, *victim = NULL;
int max_ec = UBI_MAX_ERASECOUNTER;
ubi_rb_for_each_entry(p, e, root, u.rb) {
- if (e->pnum < max_pnum && e->ec < max_ec) {
+ if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) {
victim = e;
- max_pnum = e->pnum;
max_ec = e->ec;
}
}
@@ -437,13 +434,13 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root,
return victim;
}
-static int anchor_pebs_avalible(struct rb_root *root, int max_pnum)
+static int anchor_pebs_avalible(struct rb_root *root)
{
struct rb_node *p;
struct ubi_wl_entry *e;
ubi_rb_for_each_entry(p, e, root, u.rb)
- if (e->pnum < max_pnum)
+ if (e->pnum < UBI_FM_MAX_START)
return 1;
return 0;
@@ -452,14 +449,13 @@ static int anchor_pebs_avalible(struct rb_root *root, int max_pnum)
/**
* ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
* @ubi: UBI device description object
- * @max_pnum: the highest acceptable erase block number
+ * @anchor: This PEB will be used as anchor PEB by fastmap
*
* The function returns a physical erase block with a given maximal number
* and removes it from the wl subsystem.
- * If max_pnum is negative a PEB with a mean EC will be selected.
* Must be called with wl_lock held!
*/
-struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
+struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
{
struct ubi_wl_entry *e = NULL;
@@ -469,10 +465,10 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
goto out;
}
- if (max_pnum < 0)
- e = find_mean_wl_entry(ubi, &ubi->free);
+ if (anchor)
+ e = find_anchor_wl_entry(&ubi->free);
else
- e = find_anchor_wl_entry(&ubi->free, max_pnum);
+ e = find_mean_wl_entry(ubi, &ubi->free);
if (!e)
goto out;
@@ -968,10 +964,10 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
/* Check whether we need to produce an anchor PEB */
if (!anchor)
- anchor = !anchor_pebs_avalible(&ubi->free, UBI_FM_MAX_START);
+ anchor = !anchor_pebs_avalible(&ubi->free);
if (anchor) {
- e1 = find_anchor_wl_entry(&ubi->used, UBI_FM_MAX_START);
+ e1 = find_anchor_wl_entry(&ubi->used);
if (!e1)
goto out_cancel;
e2 = get_peb_for_wl(ubi);
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are available
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
` (4 preceding siblings ...)
2012-06-23 13:03 ` [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic Richard Weinberger
@ 2012-06-23 13:03 ` 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
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 42 ++++++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index acd0561..ecbed52 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1423,7 +1423,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
tmp_e = ubi_wl_get_fm_peb(ubi, 0);
spin_unlock(&ubi->wl_lock);
- if (!tmp_e) {
+ if (!tmp_e && !old_fm) {
int j;
ubi_err("could not get any free erase block");
@@ -1432,10 +1432,28 @@ int ubi_update_fastmap(struct ubi_device *ubi)
ret = -ENOSPC;
goto err;
- }
+ } else if (!tmp_e && old_fm) {
+ ret = erase_block(ubi, old_fm->e[i]->pnum);
+ if (ret < 0) {
+ int j;
+
+ for (j = 1; j < i; j++)
+ ubi_wl_put_fm_peb(ubi, new_fm->e[j], 0);
+
+ ubi_err("could not erase old fastmap PEB");
+ goto err;
+ }
- new_fm->e[i]->pnum = tmp_e->pnum;
- new_fm->e[i]->ec = tmp_e->ec;
+ new_fm->e[i]->pnum = old_fm->e[i]->pnum;
+ new_fm->e[i]->ec = old_fm->e[i]->ec;
+ } else {
+ new_fm->e[i]->pnum = tmp_e->pnum;
+ new_fm->e[i]->ec = tmp_e->ec;
+
+ if (old_fm)
+ ubi_wl_put_fm_peb(ubi, old_fm->e[i],
+ old_fm->to_be_tortured[i]);
+ }
}
spin_lock(&ubi->wl_lock);
@@ -1447,7 +1465,11 @@ int ubi_update_fastmap(struct ubi_device *ubi)
if (!tmp_e) {
ret = erase_block(ubi, old_fm->e[0]->pnum);
if (ret < 0) {
+ int i;
ubi_err("could not erase old anchor PEB");
+
+ for (i = 1; i < new_fm->used_blocks; i++)
+ ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
goto err;
}
@@ -1461,14 +1483,14 @@ int ubi_update_fastmap(struct ubi_device *ubi)
new_fm->e[0]->pnum = tmp_e->pnum;
new_fm->e[0]->ec = tmp_e->ec;
}
-
- /* return all other fastmap block to the wl system */
- for (i = 1; i < old_fm->used_blocks; i++)
- ubi_wl_put_fm_peb(ubi, old_fm->e[i],
- old_fm->to_be_tortured[i]);
} else {
if (!tmp_e) {
- ubi_err("could not find an anchor PEB");
+ int i;
+ ubi_err("could not find any anchor PEB");
+
+ for (i = 1; i < new_fm->used_blocks; i++)
+ ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
+
ret = -ENOSPC;
goto err;
}
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
` (5 preceding siblings ...)
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 ` Richard Weinberger
2012-06-27 4:20 ` UBI fastmap updates Namjae Jeon
7 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-23 13:03 UTC (permalink / raw)
To: linux-mtd
Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
shmulik.ladkani, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
nyoushchenko, Richard Weinberger
This mutex is no longer needed.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/build.c | 1 -
drivers/mtd/ubi/ubi.h | 2 --
drivers/mtd/ubi/wl.c | 4 ----
3 files changed, 0 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 611d0c4..d00101e 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -906,7 +906,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
mutex_init(&ubi->buf_mutex);
mutex_init(&ubi->ckvol_mutex);
mutex_init(&ubi->device_mutex);
- mutex_init(&ubi->fm_pool_mutex);
mutex_init(&ubi->fm_mutex);
init_rwsem(&ubi->fm_sem);
spin_lock_init(&ubi->volumes_lock);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index a2c1bcc..2ff1807 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -382,7 +382,6 @@ struct ubi_wl_entry;
*
* @fm: in-memory data structure of the currently used fastmap
* @fm_pool: in-memory data structure of the fastmap pool
- * @fm_pool_mutex: serializes ubi_wl_get_peb()
* @fm_mutex: serializes ubi_update_fastmap()
* @fm_sem: allows ubi_update_fastmap() to block EBA table changes
* @fm_work: fastmap work queue
@@ -486,7 +485,6 @@ struct ubi_device {
struct ubi_fm_pool fm_wl_pool;
struct rw_semaphore fm_sem;
struct mutex fm_mutex;
- struct mutex fm_pool_mutex;
struct work_struct fm_work;
int attached_by_scanning;
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 4f8b06a..dc45bd3 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -609,8 +609,6 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
struct ubi_fm_pool *pool = &ubi->fm_pool;
struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool;
- mutex_lock(&ubi->fm_pool_mutex);
-
if (!pool->size || !wl_pool->size || pool->used == pool->size ||
wl_pool->used == wl_pool->size)
ubi_update_fastmap(ubi);
@@ -625,8 +623,6 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
spin_unlock(&ubi->wl_lock);
}
- mutex_unlock(&ubi->fm_pool_mutex);
-
return ret;
}
--
1.7.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: UBI fastmap updates
2012-06-23 13:03 UBI fastmap updates Richard Weinberger
` (6 preceding siblings ...)
2012-06-23 13:03 ` [PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex Richard Weinberger
@ 2012-06-27 4:20 ` Namjae Jeon
2012-06-27 6:48 ` Nikita V. Youshchenko
7 siblings, 1 reply; 11+ messages in thread
From: Namjae Jeon @ 2012-06-27 4:20 UTC (permalink / raw)
To: Richard Weinberger
Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
thomas.wucher, shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
artem.bityutskiy, nyoushchenko
Hi. Richard.
Would you infom me how much UBI attach time is improved with fastmap ?
Thanks.
2012/6/23, Richard Weinberger <richard@nod.at>:
> This is the next round of UBI fastmap updates.
>
> The highlights are:
> - Fastmap produces anchor PEBs if none are available
> (creating a fastmap on an image created by ubinize works now)
> - Fastmap is now able to reuse all PEBs if no empty PEBs are available
> - Minor fixes
>
> If you want to test fastmap you can use my git repo:
> git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubi2.git ubi2/v13
>
> Enjoy!
> //richard
>
> [PATCH 1/7] UBI: Fastmap: Modify the WL sub-system to prodcue a free
> [PATCH 2/7] UBI: Fastmap: Fix WARN_ON()
> [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a
> [PATCH 4/7] UBI: Fastmap: Fix ubi_assert()
> [PATCH 5/7] UBI: Fastmap: Kill max_pnum logic
> [PATCH 6/7] UBI: Fastmap: Reuse all fastmap PEB if no free PEBs are
> [PATCH 7/7] UBI: Fastmap: Get rid of fm_pool_mutex
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: UBI fastmap updates
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
0 siblings, 1 reply; 11+ messages in thread
From: Nikita V. Youshchenko @ 2012-06-27 6:48 UTC (permalink / raw)
To: Namjae Jeon
Cc: Richard Weinberger, linux-mtd, linux-kernel, adrian.hunter,
Heinz.Egger, thomas.wucher, shmulik.ladkani, tglx, tim.bird,
Marius.Mazarel, artem.bityutskiy
> Hi. Richard.
>
> Would you infom me how much UBI attach time is improved with fastmap ?
I'm not Richard but still.
On board I'm currently working on, ubi attach time for 1G chip without
fastmap is more than 5 seconds. With fastmap, it is less than 250
milliseconds.
Nikita
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: UBI fastmap updates
2012-06-27 6:48 ` Nikita V. Youshchenko
@ 2012-06-27 7:17 ` Richard Weinberger
0 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger @ 2012-06-27 7:17 UTC (permalink / raw)
To: Nikita V. Youshchenko
Cc: Namjae Jeon, linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
thomas.wucher, shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
artem.bityutskiy
[-- Attachment #1: Type: text/plain, Size: 530 bytes --]
Am 27.06.2012 08:48, schrieb Nikita V. Youshchenko:
>> Would you infom me how much UBI attach time is improved with fastmap ?
>
> I'm not Richard but still.
>
> On board I'm currently working on, ubi attach time for 1G chip without
> fastmap is more than 5 seconds. With fastmap, it is less than 250
> milliseconds.
I can confirm these numbers.
On all of my boards the attach time dropped from a few seconds to
less than 500 milliseconds.
(The worst case I've seen was ~800 milliseconds)
Thanks,
//richard
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-06-27 7:17 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/7] UBI: Fastmap: Ensure that not all anchor PEBs go into a pool Richard Weinberger
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
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).