[PATCH 4/4] UBI: Fastmap: Optimize anchor PEB search

From: Richard Weinberger
Date: Sun Nov 30 2014 - 07:23:28 EST


The UBI RB trees are sorted by the PEB number, hence
we don't have to traverse the whole tree because ubi_rb_for_each_entry()
walks the tree in sort order.

Signed-off-by: Richard Weinberger <richard@xxxxxx>
---
drivers/mtd/ubi/fastmap-wl.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index b2a6653..c7ad2a7 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -39,7 +39,10 @@ static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root)
int max_ec = UBI_MAX_ERASECOUNTER;

ubi_rb_for_each_entry(p, e, root, u.rb) {
- if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) {
+ if (e->pnum >= UBI_FM_MAX_START)
+ break;
+
+ if (e->ec < max_ec) {
victim = e;
max_ec = e->ec;
}
@@ -74,6 +77,8 @@ static int anchor_pebs_avalible(struct rb_root *root)
ubi_rb_for_each_entry(p, e, root, u.rb)
if (e->pnum < UBI_FM_MAX_START)
return 1;
+ else
+ break;

return 0;
}
--
1.8.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/