From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAB66C4CEC5 for ; Fri, 13 Sep 2019 13:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C086214DE for ; Fri, 13 Sep 2019 13:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380794; bh=xeJPOiQaOi1s+9JeA7eunTKWAgu9A6ggmpWUwR/faOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UnvDNqzB0CltKLIbuEgD+QKqWdVF01n+d0M/ySYywmZJNL3YuFyz4KhZXXQtAGhjr DeHZM+fuhD4E6i1ehiW5MAGBAUogMcX7XeLIpzg2sl4YyOZgT4aI+yvvgL0T0PyNI1 L0YY1hoWULWiDWoqBYNeRV4mFmtIaKldQJPuT2OI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390448AbfIMNTt (ORCPT ); Fri, 13 Sep 2019 09:19:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:48192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390444AbfIMNTt (ORCPT ); Fri, 13 Sep 2019 09:19:49 -0400 Received: from localhost (unknown [104.132.45.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C08920640; Fri, 13 Sep 2019 13:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380788; bh=xeJPOiQaOi1s+9JeA7eunTKWAgu9A6ggmpWUwR/faOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e9nY8OIKTo6FgydW6sEtncjB4yjbBYUre3NxZVGW4v5T8JsgMhD2dYyXxc1B0+iRI /JI5wCp0qg6ZqogW2Y7wQlMXCZayUag/TXk8F4bb1euP4HgoxVDSKPK45FthrzOcYp xnYyI65UAGPKcvfQWYUiiDfpeW2RYoV+LZTRCvg4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 178/190] bcache: add comments for mutex_lock(&b->write_lock) Date: Fri, 13 Sep 2019 14:07:13 +0100 Message-Id: <20190913130614.001157669@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 41508bb7d46b74dba631017e5a702a86caf1db8c ] When accessing or modifying BTREE_NODE_dirty bit, it is not always necessary to acquire b->write_lock. In bch_btree_cache_free() and mca_reap() acquiring b->write_lock is necessary, and this patch adds comments to explain why mutex_lock(&b->write_lock) is necessary for checking or clearing BTREE_NODE_dirty bit there. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/btree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 8c80833e73a9a..e0468fd41b6ea 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -649,6 +649,11 @@ static int mca_reap(struct btree *b, unsigned int min_order, bool flush) up(&b->io_mutex); } + /* + * BTREE_NODE_dirty might be cleared in btree_flush_btree() by + * __bch_btree_node_write(). To avoid an extra flush, acquire + * b->write_lock before checking BTREE_NODE_dirty bit. + */ mutex_lock(&b->write_lock); if (btree_node_dirty(b)) __bch_btree_node_write(b, &cl); @@ -772,6 +777,11 @@ void bch_btree_cache_free(struct cache_set *c) while (!list_empty(&c->btree_cache)) { b = list_first_entry(&c->btree_cache, struct btree, list); + /* + * This function is called by cache_set_free(), no I/O + * request on cache now, it is unnecessary to acquire + * b->write_lock before clearing BTREE_NODE_dirty anymore. + */ if (btree_node_dirty(b)) { btree_complete_write(b, btree_current_write(b)); clear_bit(BTREE_NODE_dirty, &b->flags); -- 2.20.1