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

Richard Weinberger richard at nod.at
Sun Nov 30 04:22:37 PST 2014


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 at nod.at>
---
 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




More information about the linux-mtd mailing list