Skip to contentSkip to conversation

ubi: Select fastmap anchor PEBs considering wear level rules

PATCH In review Arne Edholm 2 participants 10 messages Jan 13, 2020 – May 18, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubi: Select fastmap anchor PEBs considering wear level rules

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was just deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs gets a high erase count the PEBs will not be used by the pools but remain in ubi->free, even more increasing the likelihood they will be used as anchors.

Getting stuck using only a couple of PEBs continuously will result in an uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available. This is during rebuilding of the fastmap pools, after the unused pool PEBs are added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

- The anchor candidate for the next fastmap update is the most suited free PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for now. As all other non used anchor area PEBs should be even worse, free up the used anchor area PEB with the lowest erase count.

---
 drivers/mtd/ubi/fastmap-wl.c | 39 ++++++++++++++++++++++++---------------
 drivers/mtd/ubi/fastmap.c    | 11 +++++++++++
 drivers/mtd/ubi/ubi.h        |  4 +++-
 drivers/mtd/ubi/wl.c         | 28 +++++++++++++++++++---------
 4 files changed, 57 insertions(+), 25 deletions(-)
drivers/mtd/ubi/fastmap-wl.c +24 -15
index 426820ab9afe..97cb57a12440 100644
@@ -110,6 +110,21 @@ void ubi_refill_pools(struct ubi_device *ubi)
 	wl_pool->size = 0;
 	pool->size = 0;
 
+	if (ubi->fm_anchor) {
+		wl_tree_add(ubi->fm_anchor, &ubi->free);
+		ubi->free_count++;
+	}
+	if (ubi->fm_next_anchor) {
+		wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+		ubi->free_count++;
+	}
+
+	/* All available PEBs are in ubi->free, now is the time to get
+	 * the best anchor PEBs.
+	 */
+	ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1);
+	ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+
 	for (;;) {
 		enough = 0;
 		if (pool->size < pool->max_size) {
@@ -265,26 +280,20 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
 int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
 {
 	struct ubi_work *wrk;
-	struct ubi_wl_entry *anchor;
 
 	spin_lock(&ubi->wl_lock);
 
-	/* Do we already have an anchor? */
-	if (ubi->fm_anchor) {
-		spin_unlock(&ubi->wl_lock);
-		return 0;
-	}
-
-	/* See if we can find an anchor PEB on the list of free PEBs */
-	anchor = ubi_wl_get_fm_peb(ubi, 1);
-	if (anchor) {
-		ubi->fm_anchor = anchor;
-		spin_unlock(&ubi->wl_lock);
-		return 0;
+	/* Do we have a next anchor? */
+	if (!ubi->fm_next_anchor) {
+		ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+		if (!ubi->fm_next_anchor)
+			/* Tell wear leveling to produce a new anchor PEB */
+			ubi->fm_do_produce_anchor = 1;
 	}
 
-	/* No luck, trigger wear leveling to produce a new anchor PEB */
-	ubi->fm_do_produce_anchor = 1;
+	/* Do wear leveling to get a new anchor PEB or check the
+	 * existing next anchor candidate.
+	 */
 	if (ubi->wl_scheduled) {
 		spin_unlock(&ubi->wl_lock);
 		return 0;
drivers/mtd/ubi/fastmap.c +11 -0
index 1c7be4eb3ba6..02332f9ea996 100644
@@ -1220,6 +1220,17 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		fm_pos += sizeof(*fec);
 		ubi_assert(fm_pos <= ubi->fm_size);
 	}
+	if (ubi->fm_next_anchor) {
+		fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+		fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum);
+		set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs);
+		fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec);
+
+		free_peb_count++;
+		fm_pos += sizeof(*fec);
+		ubi_assert(fm_pos <= ubi->fm_size);
+	}
 	fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
 	ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
drivers/mtd/ubi/ubi.h +3 -1
index 9688b411c930..a12fdb137fa4 100644
@@ -491,7 +491,8 @@ struct ubi_debug_info {
  * @fm_work: fastmap work queue
  * @fm_work_scheduled: non-zero if fastmap work was scheduled
  * @fast_attach: non-zero if UBI was attached by fastmap
- * @fm_anchor: The next anchor PEB to use for fastmap
+ * @fm_anchor: The new anchor PEB used during fastmap update
+ * @fm_next_anchor: An anchor PEB candidate for the next time fastmap is updated
  * @fm_do_produce_anchor: If true produce an anchor PEB in wl
  *
  * @used: RB-tree of used physical eraseblocks
@@ -602,6 +603,7 @@ struct ubi_device {
 	int fm_work_scheduled;
 	int fast_attach;
 	struct ubi_wl_entry *fm_anchor;
+	struct ubi_wl_entry *fm_next_anchor;
 	int fm_do_produce_anchor;
 
 	/* Wear-leveling sub-system's stuff */
drivers/mtd/ubi/wl.c +19 -9
index 5d77a38dba54..804c434928aa 100644
@@ -688,20 +688,27 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
 	}
 
 #ifdef CONFIG_MTD_UBI_FASTMAP
+	e1 = find_anchor_wl_entry(&ubi->used);
+	if (e1 && ubi->fm_next_anchor &&
+	    (ubi->fm_next_anchor->ec - e1->ec >= UBI_WL_THRESHOLD)) {
+		ubi->fm_do_produce_anchor = 1;
+		/* fm_next_anchor is no longer considered a good anchor
+		 * candidate.
+		 * NULL assignment also prevents multiple wear level checks
+		 * of this PEB.
+		 */
+		wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+		ubi->fm_next_anchor = NULL;
+		ubi->free_count++;
+	}
+
 	if (ubi->fm_do_produce_anchor) {
-		e1 = find_anchor_wl_entry(&ubi->used);
 		if (!e1)
 			goto out_cancel;
 		e2 = get_peb_for_wl(ubi);
 		if (!e2)
 			goto out_cancel;
 
-		/*
-		 * Anchor move within the anchor area is useless.
-		 */
-		if (e2->pnum < UBI_FM_MAX_START)
-			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);
@@ -1080,8 +1087,11 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
 	if (!err) {
 		spin_lock(&ubi->wl_lock);
 
-		if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
-			ubi->fm_anchor = e;
+		if (!ubi->fm_next_anchor && e->pnum < UBI_FM_MAX_START) {
+			/* Abort anchor production, if needed it will be
+			 * enabled again in the wear leveling started below.
+			 */
+			ubi->fm_next_anchor = e;
 			ubi->fm_do_produce_anchor = 0;
 		} else {
 			wl_tree_add(e, &ubi->free);
Signature · 6 lines
2.11.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

Hi Richard,

Quoted 25 lines · Arne Edholm

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was just deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs gets a high erase count the PEBs will not be used by the pools but remain in ubi->free, even more increasing the likelihood they will be used as anchors.

Getting stuck using only a couple of PEBs continuously will result in an uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available. This is during rebuilding of the fastmap pools, after the unused pool PEBs are added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

Quoted 7 lines

- The anchor candidate for the next fastmap update is the most suited free PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for now. As all other non used anchor area PEBs should be even worse, free up the used anchor area PEB with the lowest erase count.

Do you have any comments on this suggestion?

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#2 lore raw

Arne,

Quoted 29 lines · Arne Edholm

Hi Richard,

Quoted 25 lines · Arne Edholm

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was just deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs gets a high erase count the PEBs will not be used by the pools but remain in ubi->free, even more increasing the likelihood they will be used as anchors.

Getting stuck using only a couple of PEBs continuously will result in an uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available. This is during rebuilding of the fastmap pools, after the unused pool PEBs are added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

Quoted 8 lines
Quoted 7 lines

- The anchor candidate for the next fastmap update is the most suited free PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for now. As all other non used anchor area PEBs should be even worse, free up the used anchor area PEB with the lowest erase count.

Do you have any comments on this suggestion?

Thank you for working on this. On first sight what you describe makes sense but I need to verify it first. Fastmap is tricky. ;-\
Maybe we even can have a xfstests test for it.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#3 lore raw
In reply to Arne Edholm
Quoted 162 lines · Arne Edholm

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was just deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs gets a high erase count the PEBs will not be used by the pools but remain in ubi->free, even more increasing the likelihood they will be used as anchors.

Getting stuck using only a couple of PEBs continuously will result in an uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available. This is during rebuilding of the fastmap pools, after the unused pool PEBs are added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

- The anchor candidate for the next fastmap update is the most suited free PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for now. As all other non used anchor area PEBs should be even worse, free up the used anchor area PEB with the lowest erase count.

---
 drivers/mtd/ubi/fastmap-wl.c | 39 ++++++++++++++++++++++++---------------
 drivers/mtd/ubi/fastmap.c    | 11 +++++++++++
 drivers/mtd/ubi/ubi.h        |  4 +++-
 drivers/mtd/ubi/wl.c         | 28 +++++++++++++++++++---------
 4 files changed, 57 insertions(+), 25 deletions(-)
drivers/mtd/ubi/fastmap-wl.c +24 -15
index 426820ab9afe..97cb57a12440 100644
@@ -110,6 +110,21 @@ void ubi_refill_pools(struct ubi_device *ubi)
        wl_pool->size = 0;
        pool->size = 0;
 
+       if (ubi->fm_anchor) {
+               wl_tree_add(ubi->fm_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+       if (ubi->fm_next_anchor) {
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+
+       /* All available PEBs are in ubi->free, now is the time to get
+        * the best anchor PEBs.
+        */
+       ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1);
+       ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+
        for (;;) {
                enough = 0;
                if (pool->size < pool->max_size) {
@@ -265,26 +280,20 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)
 int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
 {
        struct ubi_work *wrk;
-       struct ubi_wl_entry *anchor;
 
        spin_lock(&ubi->wl_lock);
 
-       /* Do we already have an anchor? */
-       if (ubi->fm_anchor) {
-               spin_unlock(&ubi->wl_lock);
-               return 0;
-       }
-
-       /* See if we can find an anchor PEB on the list of free PEBs */
-       anchor = ubi_wl_get_fm_peb(ubi, 1);
-       if (anchor) {
-               ubi->fm_anchor = anchor;
-               spin_unlock(&ubi->wl_lock);
-               return 0;
+       /* Do we have a next anchor? */
+       if (!ubi->fm_next_anchor) {
+               ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+               if (!ubi->fm_next_anchor)
+                       /* Tell wear leveling to produce a new anchor PEB */
+                       ubi->fm_do_produce_anchor = 1;
        }
 
-       /* No luck, trigger wear leveling to produce a new anchor PEB */
-       ubi->fm_do_produce_anchor = 1;
+       /* Do wear leveling to get a new anchor PEB or check the
+        * existing next anchor candidate.
+        */
        if (ubi->wl_scheduled) {
                spin_unlock(&ubi->wl_lock);
                return 0;
drivers/mtd/ubi/fastmap.c +11 -0
index 1c7be4eb3ba6..02332f9ea996 100644
@@ -1220,6 +1220,17 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
                fm_pos += sizeof(*fec);
                ubi_assert(fm_pos <= ubi->fm_size);
        }
+       if (ubi->fm_next_anchor) {
+               fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+               fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum);
+               set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs);
+               fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec);
+
+               free_peb_count++;
+               fm_pos += sizeof(*fec);
+               ubi_assert(fm_pos <= ubi->fm_size);
+       }
        fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
        ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
drivers/mtd/ubi/ubi.h +3 -1
index 9688b411c930..a12fdb137fa4 100644
@@ -491,7 +491,8 @@ struct ubi_debug_info {
  * @fm_work: fastmap work queue
  * @fm_work_scheduled: non-zero if fastmap work was scheduled
  * @fast_attach: non-zero if UBI was attached by fastmap
- * @fm_anchor: The next anchor PEB to use for fastmap
+ * @fm_anchor: The new anchor PEB used during fastmap update
+ * @fm_next_anchor: An anchor PEB candidate for the next time fastmap is updated
  * @fm_do_produce_anchor: If true produce an anchor PEB in wl
  *
  * @used: RB-tree of used physical eraseblocks
@@ -602,6 +603,7 @@ struct ubi_device {
        int fm_work_scheduled;
        int fast_attach;
        struct ubi_wl_entry *fm_anchor;
+       struct ubi_wl_entry *fm_next_anchor;
        int fm_do_produce_anchor;
 
        /* Wear-leveling sub-system's stuff */
drivers/mtd/ubi/wl.c +8 -0
index 5d77a38dba54..804c434928aa 100644
@@ -688,20 +688,27 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
        }
 
 #ifdef CONFIG_MTD_UBI_FASTMAP
+       e1 = find_anchor_wl_entry(&ubi->used);
+       if (e1 && ubi->fm_next_anchor &&
+           (ubi->fm_next_anchor->ec - e1->ec >= UBI_WL_THRESHOLD)) {
+               ubi->fm_do_produce_anchor = 1;
+               /* fm_next_anchor is no longer considered a good anchor
+                * candidate.
+                * NULL assignment also prevents multiple wear level checks
+                * of this PEB.

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 707

Quoted 10 lines
drivers/mtd/ubi/wl.c +6 -1
+                */
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->fm_next_anchor = NULL;
+               ubi->free_count++;
+       }
+
        if (ubi->fm_do_produce_anchor) {
-               e1 = find_anchor_wl_entry(&ubi->used);
                if (!e1)
                        goto out_cancel;

The logic here is a little strange. Why don't you check for e1 being NULL in the new code block
above?

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 704

Quoted 10 lines
drivers/mtd/ubi/wl.c +0 -6
                e2 = get_peb_for_wl(ubi);
                if (!e2)
                        goto out_cancel;
 
-               /*
-                * Anchor move within the anchor area is useless.
-                */
-               if (e2->pnum < UBI_FM_MAX_START)
-                       goto out_cancel;
-

Are you sure we can drop this optimization?

Other than that I like your approach and would merge it. :-)

Quoted 24 lines
drivers/mtd/ubi/wl.c +5 -3
                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);
@@ -1080,8 +1087,11 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
        if (!err) {
                spin_lock(&ubi->wl_lock);
 
-               if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
-                       ubi->fm_anchor = e;
+               if (!ubi->fm_next_anchor && e->pnum < UBI_FM_MAX_START) {
+                       /* Abort anchor production, if needed it will be
+                        * enabled again in the wear leveling started below.
+                        */
+                       ubi->fm_next_anchor = e;
                        ubi->fm_do_produce_anchor = 0;
                } else {
                        wl_tree_add(e, &ubi->free);
--

2.11.0

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#4 lore raw
Quoted 184 lines · Richard Weinberger
Quoted 10 lines · Arne Edholm

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was just deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs gets a high erase count the PEBs will not be used by the pools but remain in ubi->free, even more increasing the likelihood they will be used as anchors.

Quoted 6 lines

Getting stuck using only a couple of PEBs continuously will result in an uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available.

This is

Quoted 11 lines

   during rebuilding of the fastmap pools, after the unused pool PEBs are added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

- The anchor candidate for the next fastmap update is the most

suited free

Quoted 2 lines

   PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for

now. As

Quoted 6 lines

   all other non used anchor area PEBs should be even worse, free up the used anchor area PEB with the lowest erase count.

---
  drivers/mtd/ubi/fastmap-wl.c | 39

++++++++++++++++++++++++---------------

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry

Quoted 32 lines

  drivers/mtd/ubi/fastmap.c    | 11 +++++++++++ drivers/mtd/ubi/ubi.h        |  4 +++- drivers/mtd/ubi/wl.c         | 28 +++++++++++++++++++---------

  4 files changed, 57 insertions(+), 25 deletions(-)
drivers/mtd/ubi/fastmap-wl.c +15 -0
index 426820ab9afe..97cb57a12440 100644
@@ -110,6 +110,21 @@ void ubi_refill_pools(struct ubi_device *ubi)
          wl_pool->size = 0;
          pool->size = 0;
 
+       if (ubi->fm_anchor) {
+               wl_tree_add(ubi->fm_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+       if (ubi->fm_next_anchor) {
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+
+       /* All available PEBs are in ubi->free, now is the time to get
+        * the best anchor PEBs.
+        */
+       ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1);
+       ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+
          for (;;) {
                  enough = 0;
                  if (pool->size < pool->max_size) {
@@ -265,26 +280,20 @@ static struct ubi_wl_entry 

*get_peb_for_wl(struct ubi_device *ubi)

Quoted 14 lines
drivers/mtd/ubi/fastmap-wl.c +0 -8
   int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
   {
          struct ubi_work *wrk;
-       struct ubi_wl_entry *anchor;
 
          spin_lock(&ubi->wl_lock);
 
-       /* Do we already have an anchor? */
-       if (ubi->fm_anchor) {
-               spin_unlock(&ubi->wl_lock);
-               return 0;
-       }
-
-       /* See if we can find an anchor PEB on the list of free PEBs */

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)

Quoted 10 lines
drivers/mtd/ubi/fastmap-wl.c +5 -5
-       anchor = ubi_wl_get_fm_peb(ubi, 1);
-       if (anchor) {
-               ubi->fm_anchor = anchor;
-               spin_unlock(&ubi->wl_lock);
-               return 0;
+       /* Do we have a next anchor? */
+       if (!ubi->fm_next_anchor) {
+               ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+               if (!ubi->fm_next_anchor)
+                       /* Tell wear leveling to produce a new 

anchor PEB */

drivers/mtd/ubi/fastmap.c static int ubi_write_fastmap(struct

Quoted 16 lines
drivers/mtd/ubi/fastmap-wl.c +4 -2
+                       ubi->fm_do_produce_anchor = 1;
          }
 
-       /* No luck, trigger wear leveling to produce a new anchor PEB */
-       ubi->fm_do_produce_anchor = 1;
+       /* Do wear leveling to get a new anchor PEB or check the
+        * existing next anchor candidate.
+        */
          if (ubi->wl_scheduled) {
                  spin_unlock(&ubi->wl_lock);
                  return 0;
drivers/mtd/ubi/fastmap.c +0 -0
index 1c7be4eb3ba6..02332f9ea996 100644
@@ -1220,6 +1220,17 @@ static int ubi_write_fastmap(struct 

ubi_device *ubi,

Quoted 22 lines
drivers/mtd/ubi/fastmap.c +11 -0
                  fm_pos += sizeof(*fec);
                  ubi_assert(fm_pos <= ubi->fm_size);
          }
+       if (ubi->fm_next_anchor) {
+               fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+               fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum);
+               set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs);
+               fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec);
+
+               free_peb_count++;
+               fm_pos += sizeof(*fec);
+               ubi_assert(fm_pos <= ubi->fm_size);
+       }
          fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
          ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
drivers/mtd/ubi/ubi.h +0 -0
index 9688b411c930..a12fdb137fa4 100644

drivers/mtd/ubi/ubi.h struct ubi_debug_info { · line 495

Quoted 6 lines
drivers/mtd/ubi/ubi.h +2 -1
@@ -491,7 +491,8 @@ struct ubi_debug_info {
    * @fm_work: fastmap work queue
    * @fm_work_scheduled: non-zero if fastmap work was scheduled
    * @fast_attach: non-zero if UBI was attached by fastmap
- * @fm_anchor: The next anchor PEB to use for fastmap
+ * @fm_anchor: The new anchor PEB used during fastmap update
+ * @fm_next_anchor: An anchor PEB candidate for the next time 

fastmap is updated

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct

Quoted 16 lines
drivers/mtd/ubi/ubi.h +1 -0
    * @fm_do_produce_anchor: If true produce an anchor PEB in wl
    *
    * @used: RB-tree of used physical eraseblocks
@@ -602,6 +603,7 @@ struct ubi_device {
          int fm_work_scheduled;
          int fast_attach;
          struct ubi_wl_entry *fm_anchor;
+       struct ubi_wl_entry *fm_next_anchor;
          int fm_do_produce_anchor;
 
          /* Wear-leveling sub-system's stuff */
drivers/mtd/ubi/wl.c +0 -0
index 5d77a38dba54..804c434928aa 100644
@@ -688,20 +688,27 @@ static int wear_leveling_worker(struct 

ubi_device *ubi, struct ubi_work *wrk,

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,

Quoted 10 lines
drivers/mtd/ubi/wl.c +7 -0
          }
 
   #ifdef CONFIG_MTD_UBI_FASTMAP
+       e1 = find_anchor_wl_entry(&ubi->used);
+       if (e1 && ubi->fm_next_anchor &&
+           (ubi->fm_next_anchor->ec - e1->ec >= UBI_WL_THRESHOLD)) {
+               ubi->fm_do_produce_anchor = 1;
+               /* fm_next_anchor is no longer considered a good anchor
+                * candidate.
+                * NULL assignment also prevents multiple wear level 

checks

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 707

Quoted 11 lines
drivers/mtd/ubi/wl.c +7 -1
+                * of this PEB.
+                */
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->fm_next_anchor = NULL;
+               ubi->free_count++;
+       }
+
          if (ubi->fm_do_produce_anchor) {
-               e1 = find_anchor_wl_entry(&ubi->used);
                  if (!e1)
                          goto out_cancel;
Quoted 3 lines

The logic here is a little strange. Why don't you check for e1 being NULL in the new code block
above?

Failing to get e1 is not critical in the new above code, it just means we skip the anchor wl check and continue what used to be done before this change. e1 is required however when specifically tasked with generating a new anchor, hence the placement of the NULL check.

Quoted 5 lines
Quoted 5 lines
drivers/mtd/ubi/wl.c +0 -0
                  e2 = get_peb_for_wl(ubi);
                  if (!e2)
                          goto out_cancel;
 
Quoted 8 lines

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 704

Quoted 6 lines
drivers/mtd/ubi/wl.c +0 -6
-               /*
-                * Anchor move within the anchor area is useless.
-                */
-               if (e2->pnum < UBI_FM_MAX_START)
-                       goto out_cancel;
-

Are you sure we can drop this optimization?

I can't find a problem with this. An anchor area PEB (with high EC) in the wl pool is consumed to make another anchor area PEB (lower EC) in ubi->used available by processing it to ubi->free. This process should be finished before fastmap update needs the PEB thanks to synchronous delete and fm_eba_sem.

On the other hand, keeping your optimization doesn't break the functionality of the new code either, the removal is just a small optimization with regard to wear leveling. So if you are concerned it can be kept. (If it is kept though, it needs to be modified to return e2 to ubi->free as right now it is leaked. But that would be a separate patch as it is not tied to this change right?)

Quoted 2 lines

Other than that I like your approach and would merge it. :-)

Thank you!

Quoted 26 lines

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,

Quoted 4 lines
drivers/mtd/ubi/wl.c +0 -0
                  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);

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device

Quoted 1 line
drivers/mtd/ubi/wl.c +0 -0
@@ -1080,8 +1087,11 @@ static int __erase_worker(struct ubi_device 

*ubi, struct ubi_work *wl_wrk)

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)

Quoted 6 lines
drivers/mtd/ubi/wl.c +1 -2
          if (!err) {
                  spin_lock(&ubi->wl_lock);
 
-               if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
-                       ubi->fm_anchor = e;
+               if (!ubi->fm_next_anchor && e->pnum < 

UBI_FM_MAX_START) {

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device · line 1092

Quoted 2 lines
drivers/mtd/ubi/wl.c +2 -0
+                       /* Abort anchor production, if needed it will be
+                        * enabled again in the wear leveling 

started below.

Quoted 9 lines
drivers/mtd/ubi/wl.c +2 -1
+                        */
+                       ubi->fm_next_anchor = e;
                          ubi->fm_do_produce_anchor = 0;
                  } else {
                          wl_tree_add(e, &ubi->free);
--

2.11.0

Quoted 9 lines
Quoted 3 lines

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 2 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw

Hi Richard,

Quoted 214 lines · Arne Edholm
Quoted 194 lines · Richard Weinberger
Quoted 3 lines · Arne Edholm

There is a risk that the fastmap anchor PEB is alternating between just two PEBs, the current anchor and the previous anchor that was

just

Quoted 3 lines

deleted. As the fastmap pools gets the first take on free PEBs, the pools may leave no free PEBs to be selected as the new anchor, resulting in the two PEBs alternating behaviour. If the anchor PEBs

gets

Quoted 1 line

a high erase count the PEBs will not be used by the pools but

remain in

Quoted 4 lines

ubi->free, even more increasing the likelihood they will be used as anchors.

Getting stuck using only a couple of PEBs continuously will result

in an

Quoted 5 lines

uneven wear, eventually leading to failure.

To fix this:

- Choose the fastmap anchor when the most free PEBs are available.

This is

Quoted 1 line

   during rebuilding of the fastmap pools, after the unused pool

PEBs are

Quoted 10 lines

   added to ubi->free but before the pools are populated again from the free PEBs. Also reserve an additional second best PEB as a candidate for the next time the fast map anchor is updated. If a better PEB is found the next time the fast map anchor is updated, the candidate is made available for building the pools.

- Enable anchor move within the anchor area again as it is useful for distributing wear.

- The anchor candidate for the next fastmap update is the most

suited free

Quoted 2 lines

   PEB. Check this PEB's erase count during wear leveling. If the wear leveling limit is exceeded, the PEB is considered unsuitable for

now. As

Quoted 1 line

   all other non used anchor area PEBs should be even worse, free up

the

Quoted 5 lines

   used anchor area PEB with the lowest erase count.

---
  drivers/mtd/ubi/fastmap-wl.c | 39

++++++++++++++++++++++++---------------

Review

Quoted 6 lines

  drivers/mtd/ubi/fastmap.c    | 11 +++++++++++ drivers/mtd/ubi/ubi.h        |  4 +++- drivers/mtd/ubi/wl.c         | 28 +++++++++++++++++++---------

  4 files changed, 57 insertions(+), 25 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/ubi/fastmap-wl.c

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry

Quoted 26 lines

index 426820ab9afe..97cb57a12440 100644

drivers/mtd/ubi/fastmap-wl.c +15 -0
@@ -110,6 +110,21 @@ void ubi_refill_pools(struct ubi_device *ubi)
          wl_pool->size = 0;
          pool->size = 0;
 
+       if (ubi->fm_anchor) {
+               wl_tree_add(ubi->fm_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+       if (ubi->fm_next_anchor) {
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->free_count++;
+       }
+
+       /* All available PEBs are in ubi->free, now is the time to get
+        * the best anchor PEBs.
+        */
+       ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1);
+       ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+
          for (;;) {
                  enough = 0;
                  if (pool->size < pool->max_size) {
@@ -265,26 +280,20 @@ static struct ubi_wl_entry 

*get_peb_for_wl(struct ubi_device *ubi)

Quoted 4 lines
drivers/mtd/ubi/fastmap-wl.c +0 -1
   int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
   {
          struct ubi_work *wrk;
-       struct ubi_wl_entry *anchor;

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)

Quoted 10 lines
drivers/mtd/ubi/fastmap-wl.c +0 -7
 
          spin_lock(&ubi->wl_lock);
 
-       /* Do we already have an anchor? */
-       if (ubi->fm_anchor) {
-               spin_unlock(&ubi->wl_lock);
-               return 0;
-       }
-
-       /* See if we can find an anchor PEB on the list of free 

PEBs */

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)

Quoted 10 lines
drivers/mtd/ubi/fastmap-wl.c +5 -5
-       anchor = ubi_wl_get_fm_peb(ubi, 1);
-       if (anchor) {
-               ubi->fm_anchor = anchor;
-               spin_unlock(&ubi->wl_lock);
-               return 0;
+       /* Do we have a next anchor? */
+       if (!ubi->fm_next_anchor) {
+               ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1);
+               if (!ubi->fm_next_anchor)
+                       /* Tell wear leveling to produce a new 

anchor PEB */

drivers/mtd/ubi/fastmap-wl.c static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi)

Quoted 4 lines
drivers/mtd/ubi/fastmap-wl.c +1 -1
+                       ubi->fm_do_produce_anchor = 1;
          }
 
-       /* No luck, trigger wear leveling to produce a new anchor 

PEB */

drivers/mtd/ubi/fastmap.c static int ubi_write_fastmap(struct

Quoted 12 lines
drivers/mtd/ubi/fastmap-wl.c +3 -1
-       ubi->fm_do_produce_anchor = 1;
+       /* Do wear leveling to get a new anchor PEB or check the
+        * existing next anchor candidate.
+        */
          if (ubi->wl_scheduled) {
                  spin_unlock(&ubi->wl_lock);
                  return 0;
drivers/mtd/ubi/fastmap.c +0 -0
index 1c7be4eb3ba6..02332f9ea996 100644
@@ -1220,6 +1220,17 @@ static int ubi_write_fastmap(struct 

ubi_device *ubi,

Quoted 22 lines
drivers/mtd/ubi/fastmap.c +11 -0
                  fm_pos += sizeof(*fec);
                  ubi_assert(fm_pos <= ubi->fm_size);
          }
+       if (ubi->fm_next_anchor) {
+               fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+               fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum);
+               set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs);
+               fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec);
+
+               free_peb_count++;
+               fm_pos += sizeof(*fec);
+               ubi_assert(fm_pos <= ubi->fm_size);
+       }
          fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
          ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {
drivers/mtd/ubi/ubi.h +0 -0
index 9688b411c930..a12fdb137fa4 100644

drivers/mtd/ubi/ubi.h struct ubi_debug_info { · line 495

Quoted 6 lines
drivers/mtd/ubi/ubi.h +2 -1
@@ -491,7 +491,8 @@ struct ubi_debug_info {
    * @fm_work: fastmap work queue
    * @fm_work_scheduled: non-zero if fastmap work was scheduled
    * @fast_attach: non-zero if UBI was attached by fastmap
- * @fm_anchor: The next anchor PEB to use for fastmap
+ * @fm_anchor: The new anchor PEB used during fastmap update
+ * @fm_next_anchor: An anchor PEB candidate for the next time 

fastmap is updated

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct

Quoted 16 lines
drivers/mtd/ubi/ubi.h +1 -0
    * @fm_do_produce_anchor: If true produce an anchor PEB in wl
    *
    * @used: RB-tree of used physical eraseblocks
@@ -602,6 +603,7 @@ struct ubi_device {
          int fm_work_scheduled;
          int fast_attach;
          struct ubi_wl_entry *fm_anchor;
+       struct ubi_wl_entry *fm_next_anchor;
          int fm_do_produce_anchor;
 
          /* Wear-leveling sub-system's stuff */
drivers/mtd/ubi/wl.c +0 -0
index 5d77a38dba54..804c434928aa 100644
@@ -688,20 +688,27 @@ static int wear_leveling_worker(struct 

ubi_device *ubi, struct ubi_work *wrk,

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,

Quoted 8 lines
drivers/mtd/ubi/wl.c +5 -0
          }
 
   #ifdef CONFIG_MTD_UBI_FASTMAP
+       e1 = find_anchor_wl_entry(&ubi->used);
+       if (e1 && ubi->fm_next_anchor &&
+           (ubi->fm_next_anchor->ec - e1->ec >= UBI_WL_THRESHOLD)) {
+               ubi->fm_do_produce_anchor = 1;
+               /* fm_next_anchor is no longer considered a good 

anchor

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct · line 697

Quoted 2 lines
drivers/mtd/ubi/wl.c +2 -0
+                * candidate.
+                * NULL assignment also prevents multiple wear 

level checks

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 707

Quoted 11 lines
drivers/mtd/ubi/wl.c +7 -1
+                * of this PEB.
+                */
+               wl_tree_add(ubi->fm_next_anchor, &ubi->free);
+               ubi->fm_next_anchor = NULL;
+               ubi->free_count++;
+       }
+
          if (ubi->fm_do_produce_anchor) {
-               e1 = find_anchor_wl_entry(&ubi->used);
                  if (!e1)
                          goto out_cancel;
Quoted 3 lines

The logic here is a little strange. Why don't you check for e1 being NULL in the new code block
above?

Failing to get e1 is not critical in the new above code, it just means we skip the anchor wl check and continue what used to be done before this change. e1 is required however when specifically tasked with generating a new anchor, hence the placement of the NULL check.

Quoted 5 lines
Quoted 5 lines
drivers/mtd/ubi/wl.c +0 -0
                  e2 = get_peb_for_wl(ubi);
                  if (!e2)
                          goto out_cancel;
 
Quoted 8 lines

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · line 704

Quoted 6 lines
drivers/mtd/ubi/wl.c +0 -6
-               /*
-                * Anchor move within the anchor area is useless.
-                */
-               if (e2->pnum < UBI_FM_MAX_START)
-                       goto out_cancel;
-

Are you sure we can drop this optimization?

Quoted 43 lines

I can't find a problem with this. An anchor area PEB (with high EC) in the wl pool is consumed to make another anchor area PEB (lower EC) in ubi->used available by processing it to ubi->free. This process should be finished before fastmap update needs the PEB thanks to synchronous delete and fm_eba_sem.

On the other hand, keeping your optimization doesn't break the functionality of the new code either, the removal is just a small optimization with regard to wear leveling. So if you are concerned it can be kept. (If it is kept though, it needs to be modified to return e2 to ubi->free as right now it is leaked. But that would be a separate patch as it is not tied to this change right?)

Quoted 2 lines

Other than that I like your approach and would merge it. :-)

Thank you!

Quoted 36 lines

drivers/mtd/ubi/wl.c static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,

Quoted 4 lines
drivers/mtd/ubi/wl.c +0 -0
                  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);

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device

Quoted 1 line
drivers/mtd/ubi/wl.c +0 -0
@@ -1080,8 +1087,11 @@ static int __erase_worker(struct ubi_device 

*ubi, struct ubi_work *wl_wrk)

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)

Quoted 6 lines
drivers/mtd/ubi/wl.c +1 -2
          if (!err) {
                  spin_lock(&ubi->wl_lock);
 
-               if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
-                       ubi->fm_anchor = e;
+               if (!ubi->fm_next_anchor && e->pnum < 

UBI_FM_MAX_START) {

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device · line 1091

Quoted 1 line
drivers/mtd/ubi/wl.c +1 -0
+                       /* Abort anchor production, if needed it 

will be

drivers/mtd/ubi/wl.c static int __erase_worker(struct ubi_device · line 1092

Quoted 1 line
drivers/mtd/ubi/wl.c +1 -0
+                        * enabled again in the wear leveling 

started below.

Quoted 12 lines
drivers/mtd/ubi/wl.c +2 -1
+                        */
+                       ubi->fm_next_anchor = e;
                          ubi->fm_do_produce_anchor = 0;
                  } else {
                          wl_tree_add(e, &ubi->free);
--

2.11.0

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 2 lines
Thanks,
//richard

Are you satisfied with my answers or are there additional information/changes needed?

Arne

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw
Quoted 2 lines · Arne Edholm

Are you satisfied with my answers or are there additional information/changes needed?

Yes. In the meanwhile I did more testing and with your changes the anchor PEB selection
is *much* better. Testing took some time and then I scheduled away to other stuff...
Critical workloads are these where a fastmap is not written due to heavy write load,
but other events like volume change/creation.

A good reproducer seems something stupid like that:
for i in seq 1000 ; do ubimkvol -N test -m /dev/ubi0 >/dev/null && ubirmvol /dev/ubi0 -n 0 ; done
Wearleveling threshold is 50, btw.

Without your patch, the erase counter of the first 64 PEBs:

4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    22   4
4    19   4    4    4    4    4    4
4    4    4    4    8    908  906  1

And with your patch:

95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   94   94   94   94   94
94   94   94   94   94   94   94   95

In tests where the volumes are just filled and erased again, I could not see a difference.

So, your patch will be part of the next merge window. :-)

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#7 lore raw
Quoted 29 lines · Richard Weinberger
Quoted 2 lines · Arne Edholm

Are you satisfied with my answers or are there additional information/changes needed?

Yes. In the meanwhile I did more testing and with your changes the anchor PEB selection
is *much* better. Testing took some time and then I scheduled away to other stuff...
Critical workloads are these where a fastmap is not written due to heavy write load,
but other events like volume change/creation.

A good reproducer seems something stupid like that:
for i in seq 1000 ; do ubimkvol -N test -m /dev/ubi0 >/dev/null && ubirmvol /dev/ubi0 -n 0 ; done
Wearleveling threshold is 50, btw.

Without your patch, the erase counter of the first 64 PEBs:

4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    22   4
4    19   4    4    4    4    4    4
4    4    4    4    8    908  906  1

And with your patch:

Quoted 8 lines
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   94   94   94   94   94
94   94   94   94   94   94   94   95

While observing my own mail on the mailing list I discovered something I didn't notice
last time on my terminal.
If we summarize all numbers in the squares it should be more or less 2000. because the test triggered 2000 fastmap writes.
But 95 times 64 is much more than 2000.

Your patch produces almost a perfect distribution, the overall erase count is three times as much as it is expected.
Hmmm.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#8 lore raw
Quoted 48 lines · Richard Weinberger
Quoted 29 lines · Richard Weinberger
Quoted 2 lines · Arne Edholm

Are you satisfied with my answers or are there additional information/changes needed?

Yes. In the meanwhile I did more testing and with your changes the anchor PEB selection
is *much* better. Testing took some time and then I scheduled away to other stuff...
Critical workloads are these where a fastmap is not written due to heavy write load,
but other events like volume change/creation.

A good reproducer seems something stupid like that:
for i in seq 1000 ; do ubimkvol -N test -m /dev/ubi0 >/dev/null && ubirmvol /dev/ubi0 -n 0 ; done
Wearleveling threshold is 50, btw.

Without your patch, the erase counter of the first 64 PEBs:

4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    22   4
4    19   4    4    4    4    4    4
4    4    4    4    8    908  906  1

And with your patch:

Quoted 8 lines
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   95   95   95   95   95
95   95   95   94   94   94   94   94
94   94   94   94   94   94   94   95

While observing my own mail on the mailing list I discovered something I didn't notice
last time on my terminal.
If we summarize all numbers in the squares it should be more or less 2000. because the test triggered 2000 fastmap writes.
But 95 times 64 is much more than 2000.

Quoted 3 lines

Your patch produces almost a perfect distribution, the overall erase count is three times as much as it is expected.
Hmmm.

I did more tests and can no longer reproduce the problem with too much wear-leveling.
Maybe my initial tests were wonky. So, patch looks good, results too. Let's merge it with 5.8. :-)

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#9 lore raw
Quoted 53 lines · Richard Weinberger
Quoted 5 lines · Richard Weinberger
Quoted 2 lines · Richard Weinberger

On Thu, Apr 30, 2020 at 10:34 AM Arne Edholm

Quoted 36 lines · <[email protected]> wrote:
Quoted 26 lines
Quoted 2 lines

Are you satisfied with my answers or are there additional information/changes needed?

Yes. In the meanwhile I did more testing and with your changes the anchor PEB selection
is *much* better. Testing took some time and then I scheduled away to other stuff...
Critical workloads are these where a fastmap is not written due to heavy write load,
but other events like volume change/creation.

A good reproducer seems something stupid like that:
for i in seq 1000 ; do ubimkvol -N test -m /dev/ubi0 >/dev/null && ubirmvol /dev/ubi0 -n 0 ; done
Wearleveling threshold is 50, btw.

Without your patch, the erase counter of the first 64 PEBs:
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    4    4
4    4    4    4    4    4    22   4
4    19   4    4    4    4    4    4
4    4    4    4    8    908  906  1

Quoted 9 lines

And with your patch:
95   95   95   95   95   95   95   95 95   95   95   95   95   95   95   95 95   95   95   95   95   95   95   95 95   95   95   95   95   95   95   95 95   95   95   95   95   95   95   95 95   95   95   95   95   95   95   95 95   95   95   94   94   94   94   94 94   94   94   94   94   94   94   95

Quoted 4 lines

While observing my own mail on the mailing list I discovered something I didn't notice
last time on my terminal.
If we summarize all numbers in the squares it should be more or less

2000.

Quoted 4 lines

because the test triggered 2000 fastmap writes.
But 95 times 64 is much more than 2000.

Your patch produces almost a perfect distribution, the overall erase

Quoted 9 lines

count

Quoted 2 lines

is three times as much as it is expected.
Hmmm.

I did more tests and can no longer reproduce the problem with too much wear-leveling.
Maybe my initial tests were wonky. So, patch looks good, results too. Let's merge it with 5.8. :-)

Thank you Richard. I have also been trying to reproduce this issue without success.

/Arne

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/