From patchwork Mon Sep 19 16:16:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12980712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BC1FC6FA86 for ; Mon, 19 Sep 2022 16:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbiISQRb (ORCPT ); Mon, 19 Sep 2022 12:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiISQRa (ORCPT ); Mon, 19 Sep 2022 12:17:30 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559C62A41A; Mon, 19 Sep 2022 09:17:26 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 44B1B1F898; Mon, 19 Sep 2022 16:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663604244; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JqhEOb/kQQutjav9ogK3MpMbym9wqCbIlY6eT4QQ/ZQ=; b=HaQq64g8llGqgj8YQvR1UeAuIRtYsJ2LSJkYJ8EjM+jmKKTzhZA3ecCKjM3ldP6q676qta QG19z4aOPv9gxNh59/d0lEyRPLPAU2OOfNqqEWLqPSm6Ixq7AMbbZL/7w/jCjsxOWG54Rk ChPMI1+zjsp9BqgCIfD+MaIRpy9WK7U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663604244; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JqhEOb/kQQutjav9ogK3MpMbym9wqCbIlY6eT4QQ/ZQ=; b=u3VeEByyi1Q/avOZq89T3TJ6vUq+Yhwz6sPMbEBHJqexMq7ms5A0XPzrpHTq6i/VKW0Gq3 Px8KFS9egjI+p4Dg== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 3FCE42C141; Mon, 19 Sep 2022 16:17:20 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Li Lei , Coly Li Subject: [PATCH 1/5] bcache: remove unnecessary flush_workqueue Date: Tue, 20 Sep 2022 00:16:43 +0800 Message-Id: <20220919161647.81238-2-colyli@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919161647.81238-1-colyli@suse.de> References: <20220919161647.81238-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Li Lei All pending works will be drained by destroy_workqueue(), no need to call flush_workqueue() explicitly. Signed-off-by: Li Lei Signed-off-by: Coly Li --- drivers/md/bcache/writeback.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 3f0ff3aab6f2..647661005176 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -801,10 +801,9 @@ static int bch_writeback_thread(void *arg) } } - if (dc->writeback_write_wq) { - flush_workqueue(dc->writeback_write_wq); + if (dc->writeback_write_wq) destroy_workqueue(dc->writeback_write_wq); - } + cached_dev_put(dc); wait_for_kthread_stop(); From patchwork Mon Sep 19 16:16:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12980713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98640ECAAD3 for ; Mon, 19 Sep 2022 16:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbiISQRg (ORCPT ); Mon, 19 Sep 2022 12:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229776AbiISQRe (ORCPT ); Mon, 19 Sep 2022 12:17:34 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5B553AB10; Mon, 19 Sep 2022 09:17:29 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0BD0621D30; Mon, 19 Sep 2022 16:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663604248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HUgloJG6yvDvYlqAJRIqdPRh1vFVa1WNGQeqOuVBkKU=; b=NO2qojPNBcr5/Duj8vwkudVshPzzCGqz2RPTMA4EF51ec//lLgrofyZQqAns3KVBMCGnGC AtF/AAFmzY+aFSSpOtWZbIsnvib5TW4CusgZlYLQvBROhmPW+a5D83AyeypdMz80x1SSq9 hnVcohx5z49t5nrRW6l4otuwV+UQSEo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663604248; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HUgloJG6yvDvYlqAJRIqdPRh1vFVa1WNGQeqOuVBkKU=; b=Nfi+gjF/YJmpKvbFd9jRMjuNR9+G7iaeLwGztG8+Ge542PKWZCpJ/h/f5TOHQGKcR3hs9z ImA/0yb1Aci+LgAA== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 0AE992C141; Mon, 19 Sep 2022 16:17:24 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Lin Feng , Coly Li Subject: [PATCH 2/5] bcache: remove unused bch_mark_cache_readahead function def in stats.h Date: Tue, 20 Sep 2022 00:16:44 +0800 Message-Id: <20220919161647.81238-3-colyli@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919161647.81238-1-colyli@suse.de> References: <20220919161647.81238-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Lin Feng This is a cleanup for commit 1616a4c2ab1a ("bcache: remove bcache device self-defined readahead")', currently no user for bch_mark_cache_readahead() since that commit. Signed-off-by: Lin Feng Signed-off-by: Coly Li --- drivers/md/bcache/stats.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/md/bcache/stats.h b/drivers/md/bcache/stats.h index ca4f435f7216..bd3afc856d53 100644 --- a/drivers/md/bcache/stats.h +++ b/drivers/md/bcache/stats.h @@ -54,7 +54,6 @@ void bch_cache_accounting_destroy(struct cache_accounting *acc); void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d, bool hit, bool bypass); -void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d); void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d); void bch_mark_sectors_bypassed(struct cache_set *c, From patchwork Mon Sep 19 16:16:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12980714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA0B0C6FA86 for ; Mon, 19 Sep 2022 16:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbiISQRk (ORCPT ); Mon, 19 Sep 2022 12:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbiISQRj (ORCPT ); Mon, 19 Sep 2022 12:17:39 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2932F31DFF; Mon, 19 Sep 2022 09:17:34 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 14E9621F33; Mon, 19 Sep 2022 16:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663604252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rTTzeWtVjoMpEkFi4NHFASN9aM2ScMujKGpSxc8XlEk=; b=olTp75L7jrMIQRG6iKMxSvHw/sBah1SEHk7HYQFZmcia951OBGpvflOsraDYsYgdSJmZVE 5mTW0z6a+gQNRLW8mdsQek/wBaIskr4o23KTSsMiQXeMw9LBHUlXyjgITzo+gNDdDiFTQQ AXUsbIxkPrNSwlPotluE9J+KQDTkNRc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663604252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rTTzeWtVjoMpEkFi4NHFASN9aM2ScMujKGpSxc8XlEk=; b=AkmG3OP7Fg4syKa91O2n1Dn53YgsfWfNq1MI7W5FqmCCuORfi3hflSEOqOnDlO5NcKs2aT 6/0EIH6j3euwx4DQ== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id C39022C142; Mon, 19 Sep 2022 16:17:28 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Jules Maselbas , Kent Overstreet , Coly Li Subject: [PATCH 3/5] bcache: bset: Fix comment typos Date: Tue, 20 Sep 2022 00:16:45 +0800 Message-Id: <20220919161647.81238-4-colyli@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919161647.81238-1-colyli@suse.de> References: <20220919161647.81238-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jules Maselbas Remove the redundant word `by`, correct the typo `creaated`. CC: Kent Overstreet CC: linux-bcache@vger.kernel.org Signed-off-by: Jules Maselbas Signed-off-by: Coly Li --- drivers/md/bcache/bset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index 94d38e8a59b3..2bba4d6aaaa2 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c @@ -1264,7 +1264,7 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter, * * Don't worry event 'out' is allocated from mempool, it can * still be swapped here. Because state->pool is a page mempool - * creaated by by mempool_init_page_pool(), which allocates + * created by mempool_init_page_pool(), which allocates * pages by alloc_pages() indeed. */ From patchwork Mon Sep 19 16:16:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12980715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF65C6FA86 for ; Mon, 19 Sep 2022 16:17:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbiISQRo (ORCPT ); Mon, 19 Sep 2022 12:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbiISQRm (ORCPT ); Mon, 19 Sep 2022 12:17:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D9239BA2; Mon, 19 Sep 2022 09:17:37 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C49F721F41; Mon, 19 Sep 2022 16:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663604255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bpOfGkXJ0KMqdbtRY5ERKrzxiTg8bYQXFUwSQ1PnUus=; b=NlmhLpWAOAWD6fQeZSU0SA1w5GU5FWgK8E4iIItMZmM9phlEjslkqsDIFvrYr5/sXxM9n5 UZ81YlC5nvsp5cvgT0wdYAqdjT7gMabsL/iJmjC8VfGyVB2D76I01VedVrhHb8v5/HW6yt 8UeDWdmYC8IXIlFzVcte/2lHnU1XA3E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663604255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bpOfGkXJ0KMqdbtRY5ERKrzxiTg8bYQXFUwSQ1PnUus=; b=qq84YO/UN9M7syK+NX/MUXrTHgaha+wQP2anzfyV2U9KhNDKX6SzoRpAnG/F34WhQoC2mQ +ZRxOXZnUDJ9xiDA== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id CD2BD2C141; Mon, 19 Sep 2022 16:17:32 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Jilin Yuan , Coly Li Subject: [PATCH 4/5] bcache:: fix repeated words in comments Date: Tue, 20 Sep 2022 00:16:46 +0800 Message-Id: <20220919161647.81238-5-colyli@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919161647.81238-1-colyli@suse.de> References: <20220919161647.81238-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jilin Yuan Delete the redundant word 'we'. Signed-off-by: Jilin Yuan Signed-off-by: Coly Li --- drivers/md/bcache/bcache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 2acda9cea0f9..aebb7ef10e63 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -107,7 +107,7 @@ * * BTREE NODES: * - * Our unit of allocation is a bucket, and we we can't arbitrarily allocate and + * Our unit of allocation is a bucket, and we can't arbitrarily allocate and * free smaller than a bucket - so, that's how big our btree nodes are. * * (If buckets are really big we'll only use part of the bucket for a btree node From patchwork Mon Sep 19 16:16:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12980716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8A9EC6FA86 for ; Mon, 19 Sep 2022 16:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbiISQRu (ORCPT ); Mon, 19 Sep 2022 12:17:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiISQRr (ORCPT ); Mon, 19 Sep 2022 12:17:47 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAAE83AB0B; Mon, 19 Sep 2022 09:17:42 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id DA69621AC2; Mon, 19 Sep 2022 16:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663604260; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yavwVdcOwkRxq1Ojd2Q5m3eBvPT2tJIyu1OTolveTFg=; b=Id/6pHorgKV/uVLtSDuL6dNJbNYvLeDHqBhywBS5tKkRIvASI71aDhom3pbjo9ZlbUso33 YFxLZ9bowWDIbenZWMf6NvZ8oJOSbzaOmYYp7PaSJw8fUEWospbUaeBafMfc0j4fPYUXHG IX7MfvOfFDAxf4NH5/nBPN3kanZ1neI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663604260; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yavwVdcOwkRxq1Ojd2Q5m3eBvPT2tJIyu1OTolveTFg=; b=QpPl8hDmepPD/m4FEGIjeV7ha0adbbyB5ysqmZUh+DyuE8cTfFWNUdpcihQ/CshDOK2Sl0 cSppWng/hMtfpuCA== Received: from localhost.localdomain (colyli.tcp.ovpn1.nue.suse.de [10.163.16.22]) by relay2.suse.de (Postfix) with ESMTP id 83DEE2C141; Mon, 19 Sep 2022 16:17:36 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Coly Li , Mingzhe Zou Subject: [PATCH 5/5] bcache: fix set_at_max_writeback_rate() for multiple attached devices Date: Tue, 20 Sep 2022 00:16:47 +0800 Message-Id: <20220919161647.81238-6-colyli@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919161647.81238-1-colyli@suse.de> References: <20220919161647.81238-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Inside set_at_max_writeback_rate() the calculation in following if() check is wrong, if (atomic_inc_return(&c->idle_counter) < atomic_read(&c->attached_dev_nr) * 6) Because each attached backing device has its own writeback thread running and increasing c->idle_counter, the counter increates much faster than expected. The correct calculation should be, (counter / dev_nr) < dev_nr * 6 which equals to, counter < dev_nr * dev_nr * 6 This patch fixes the above mistake with correct calculation, and helper routine idle_counter_exceeded() is added to make code be more clear. Reported-by: Mingzhe Zou Signed-off-by: Coly Li Acked-by: Mingzhe Zou --- drivers/md/bcache/writeback.c | 73 +++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 647661005176..c186bf55fe61 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -157,6 +157,53 @@ static void __update_writeback_rate(struct cached_dev *dc) dc->writeback_rate_target = target; } +static bool idle_counter_exceeded(struct cache_set *c) +{ + int counter, dev_nr; + + /* + * If c->idle_counter is overflow (idel for really long time), + * reset as 0 and not set maximum rate this time for code + * simplicity. + */ + counter = atomic_inc_return(&c->idle_counter); + if (counter <= 0) { + atomic_set(&c->idle_counter, 0); + return false; + } + + dev_nr = atomic_read(&c->attached_dev_nr); + if (dev_nr == 0) + return false; + + /* + * c->idle_counter is increased by writeback thread of all + * attached backing devices, in order to represent a rough + * time period, counter should be divided by dev_nr. + * Otherwise the idle time cannot be larger with more backing + * device attached. + * The following calculation equals to checking + * (counter / dev_nr) < (dev_nr * 6) + */ + if (counter < (dev_nr * dev_nr * 6)) + return false; + + return true; +} + +/* + * Idle_counter is increased every time when update_writeback_rate() is + * called. If all backing devices attached to the same cache set have + * identical dc->writeback_rate_update_seconds values, it is about 6 + * rounds of update_writeback_rate() on each backing device before + * c->at_max_writeback_rate is set to 1, and then max wrteback rate set + * to each dc->writeback_rate.rate. + * In order to avoid extra locking cost for counting exact dirty cached + * devices number, c->attached_dev_nr is used to calculate the idle + * throushold. It might be bigger if not all cached device are in write- + * back mode, but it still works well with limited extra rounds of + * update_writeback_rate(). + */ static bool set_at_max_writeback_rate(struct cache_set *c, struct cached_dev *dc) { @@ -167,21 +214,8 @@ static bool set_at_max_writeback_rate(struct cache_set *c, /* Don't set max writeback rate if gc is running */ if (!c->gc_mark_valid) return false; - /* - * Idle_counter is increased everytime when update_writeback_rate() is - * called. If all backing devices attached to the same cache set have - * identical dc->writeback_rate_update_seconds values, it is about 6 - * rounds of update_writeback_rate() on each backing device before - * c->at_max_writeback_rate is set to 1, and then max wrteback rate set - * to each dc->writeback_rate.rate. - * In order to avoid extra locking cost for counting exact dirty cached - * devices number, c->attached_dev_nr is used to calculate the idle - * throushold. It might be bigger if not all cached device are in write- - * back mode, but it still works well with limited extra rounds of - * update_writeback_rate(). - */ - if (atomic_inc_return(&c->idle_counter) < - atomic_read(&c->attached_dev_nr) * 6) + + if (!idle_counter_exceeded(c)) return false; if (atomic_read(&c->at_max_writeback_rate) != 1) @@ -195,13 +229,10 @@ static bool set_at_max_writeback_rate(struct cache_set *c, dc->writeback_rate_change = 0; /* - * Check c->idle_counter and c->at_max_writeback_rate agagain in case - * new I/O arrives during before set_at_max_writeback_rate() returns. - * Then the writeback rate is set to 1, and its new value should be - * decided via __update_writeback_rate(). + * In case new I/O arrives during before + * set_at_max_writeback_rate() returns. */ - if ((atomic_read(&c->idle_counter) < - atomic_read(&c->attached_dev_nr) * 6) || + if (!idle_counter_exceeded(c) || !atomic_read(&c->at_max_writeback_rate)) return false;