From patchwork Fri Nov 24 23:14:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10074667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 349B660383 for ; Fri, 24 Nov 2017 23:14:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B1462A210 for ; Fri, 24 Nov 2017 23:14:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 200F72A213; Fri, 24 Nov 2017 23:14:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96EBE2A210 for ; Fri, 24 Nov 2017 23:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753834AbdKXXOo (ORCPT ); Fri, 24 Nov 2017 18:14:44 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:33359 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753817AbdKXXOn (ORCPT ); Fri, 24 Nov 2017 18:14:43 -0500 Received: by mail-pl0-f68.google.com with SMTP id a12so5114196pll.0 for ; Fri, 24 Nov 2017 15:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G7US4QWBwjUYzPm+Cl4fzMueqO2Q33uGTvozcjYyhpE=; b=g3uRpphv4NqScxM7p2UNYjUOVNS9LlcTjCuah6l5fr6toKmRDGLNK+eaeYQBfzr9M9 GnpqosowfS2ZSAm8bV8K+z1DIYkGsaxeBdaHzIHCcK4mmNom+BKbhj6HLezvs54SaoqQ ivnjIeboLpGKtmbhYROao/ALyxepeISqeITojOe0GNSMAllppxHNh4ZfVLaGUi+egeyW 0Eeja1tkDh8cVPjGi22OoQIIHz6542tBIcCk095PrSJnCnfh7PQ5AzjXiBXyMTbV2Bh+ fbCGW8mX7QZVRiz8Q5Li/bpXH9ZZUmY6CqZ6traTVRkLCMyGwZee3W8RLxy8P8bmc/xc dH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G7US4QWBwjUYzPm+Cl4fzMueqO2Q33uGTvozcjYyhpE=; b=ajLmNIYR7GvQ/K1FJK6Bp3VM8qzimGzoHyTWw8CLq9B31ysDEGF4J3LHMZyDEG6uj+ bGh8MljWKmVw/5QyaUDKNXnf7CBSMM83etoI5Zn0tuiwNBvoSg6tKRAahptNPbTdGttn l+pTLgt9Z6ISZo95ldHUARy5yvPZ1rt9pjoTUcT9CdFaG0SOuNw8jERJBpu7oNdArxYh fVjFtMI9qcUVB3z25RDE7bet6deR4UYBn1+z2FbNI17DDlVc88pW756JGXdirUn9+VRX mzaFp/sWQ5m6V8g2N2hZ2lskih71hX2W5cW7jsshANGJsLunp5fkzQAkhvOGNVnanZJK lQEg== X-Gm-Message-State: AJaThX5AgS2RmuHK4RmKe8D7rumNpiY4casFHckibBESjCayBFz0/5lu tg4oRIrKQvPn5EbjSuVz1EBSHZaD X-Google-Smtp-Source: AGs4zMaTyGhIIFkGImYdgCb0MtT7Yyot9eaqXzpAwGbcF6Rk6OpuZ4UGTdJfKFiqfVFYGtrE5ANLxA== X-Received: by 10.84.132.40 with SMTP id 37mr31232750ple.246.1511565282890; Fri, 24 Nov 2017 15:14:42 -0800 (PST) Received: from midnight.lan (68-189-67-104.dhcp.prtv.ca.charter.com. [68.189.67.104]) by smtp.gmail.com with ESMTPSA id y83sm41020277pfd.66.2017.11.24.15.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Nov 2017 15:14:42 -0800 (PST) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: axboe@kernel.dk, Tang Junhui , Michael Lyle Subject: [PATCH 1/4] bcache: add a comment in journal bucket reading Date: Fri, 24 Nov 2017 15:14:24 -0800 Message-Id: <20171124231427.9563-2-mlyle@lyle.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124231427.9563-1-mlyle@lyle.org> References: <20171124231427.9563-1-mlyle@lyle.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tang Junhui 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. [ML: Fixed whitespace & formatting & file permissions] Signed-off-by: Tang Junhui Signed-off-by: Michael Lyle Reviewed-by: Michael Lyle --- drivers/md/bcache/journal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c index 02a98ddb592d..5018c56ebb67 100644 --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c @@ -170,6 +170,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 the scenario that the journal + * bucket is circular buffer which might have wrapped + */ l = (i * 2654435769U) % ca->sb.njournal_buckets; if (test_bit(l, bitmap))