All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bcache: add a comment in journal bucket reading
@ 2017-11-02  3:08 tang.junhui
  2017-11-02 16:31 ` Michael Lyle
  0 siblings, 1 reply; 2+ messages in thread
From: tang.junhui @ 2017-11-02  3:08 UTC (permalink / raw)
  To: colyli, mlyle; +Cc: linux-bcache, linux-block, tang.junhui

From: Tang Junhui <tang.junhui@zte.com.cn>

Journal bucket is a circular buffer, the bucket
can be like YYYNNNYY, which means the first valid journal in
the 7th bucket, and the latest valid journal in third bucket, in
this case, if we do not try we the zero index first, We
may get a valid journal in the 7th bucket, then we call
find_next_bit(bitmap,ca->sb.njournal_buckets, l + 1) to get the
first invalid bucket after the 7th bucket, because all these
buckets is valid, so no bit 1 in bitmap, thus find_next_bit()
function would return with ca->sb.njournal_buckets (8). So, after
that, bcache only read journal in 7th and 8the bucket,
the first to the third buckets are lost.

So, it is important to let developer know that, we need to try
the zero index at first in the hash-search, and avoid any breaks
in future's code modification.

Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
---
 drivers/md/bcache/journal.c | 5 +++++
 1 file changed, 5 insertions(+)
 mode change 100644 => 100755 drivers/md/bcache/journal.c

diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
old mode 100644
new mode 100755
index 0352d05..4b6e651
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -169,6 +169,11 @@ int bch_journal_read(struct cache_set *c, struct list_head *list)
 		 * find a sequence of buckets with valid journal entries
 		 */
 		for (i = 0; i < ca->sb.njournal_buckets; i++) {
+			/*
+			 * We must try the index l with ZERO first for correctness due to  
+			 * exist scenario that the journal bucket is circular buffer which
+			 * maybe have wrapped
+			 */
 			l = (i * 2654435769U) % ca->sb.njournal_buckets;
 
 			if (test_bit(l, bitmap))
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bcache: add a comment in journal bucket reading
  2017-11-02  3:08 [PATCH] bcache: add a comment in journal bucket reading tang.junhui
@ 2017-11-02 16:31 ` Michael Lyle
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Lyle @ 2017-11-02 16:31 UTC (permalink / raw)
  To: tang.junhui, colyli; +Cc: linux-bcache, linux-block

Tang--

On 11/01/2017 08:08 PM, tang.junhui@zte.com.cn wrote:
> From: Tang Junhui <tang.junhui@zte.com.cn>
> 
> Journal bucket is a circular buffer, the bucket
> can be like YYYNNNYY, which means the first valid journal in
> the 7th bucket, and the latest valid journal in third bucket, in
> this case, if we do not try we the zero index first, We
> may get a valid journal in the 7th bucket, then we call
> find_next_bit(bitmap,ca->sb.njournal_buckets, l + 1) to get the
> first invalid bucket after the 7th bucket, because all these
> buckets is valid, so no bit 1 in bitmap, thus find_next_bit()
> function would return with ca->sb.njournal_buckets (8). So, after
> that, bcache only read journal in 7th and 8the bucket,
> the first to the third buckets are lost.
> 
> So, it is important to let developer know that, we need to try
> the zero index at first in the hash-search, and avoid any breaks
> in future's code modification.
> 
> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>

Fixed a small whitespace error at end of line.

Reviewed-by: Michael Lyle <mlyle@lyle.org>

Thank you for making this much more clear.

Mike

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-02 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-02  3:08 [PATCH] bcache: add a comment in journal bucket reading tang.junhui
2017-11-02 16:31 ` Michael Lyle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.