From patchwork Fri Jul 29 11:58:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikhil Kshirsagar X-Patchwork-Id: 1661998 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=s3HJEZay; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LvQyc5hXgz9sGg for ; Fri, 29 Jul 2022 21:58:32 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oHOdM-0005oi-PU; Fri, 29 Jul 2022 11:58:24 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oHOdH-0005n0-0K for kernel-team@lists.ubuntu.com; Fri, 29 Jul 2022 11:58:19 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C58613F124 for ; Fri, 29 Jul 2022 11:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659095898; bh=T+FLc9VAR54ME3BKJBlMPXHMqN0+3HgOB1aisEW9S1I=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s3HJEZayXl8gGSj/zCyr0yLY4zleg9l/YXJDyoH7vWN8lHBdNUIDzXjxbeKaPaj+v LOY46s+PkxFgRC1gSiZrrtl0WOhEwc0Viz6DZ9rpM2aBJ0G/4O2GGJ3Yz0+GQmtvf6 WzJdgmiRklUA7Q1JfYT0XI69xlpmhFQw2EwbvXb04+faS0t47n3va5G5Y77Nqibn9U sv9FWYIjflVNzGBmPUpWHCY96J6+VQOmAtCgmbO5pRqtTSlGoSPJPzsbYcXONWCIb6 PIEgIcSce5tFt9nYyJq3M+2bZv+m5sO629z3VPYao7i+3vopsUX990S48Y41Nn21q+ bzrezWYDrVgBw== Received: by mail-wr1-f71.google.com with SMTP id m2-20020adfc582000000b0021e28acded7so1136987wrg.13 for ; Fri, 29 Jul 2022 04:58:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T+FLc9VAR54ME3BKJBlMPXHMqN0+3HgOB1aisEW9S1I=; b=fsfXfRLRJ5X9U1c2slz3Un3NcyQsXGx5XT9rh8eYMsx1ylhAj1dY6i+wDIaLLrsBfF 9FGRrARgDIe/I7fpQZPMZ+FwIIbyc6i9Nvj5QF9HZ5+uhjXdOFA5ocDtKe+zfe4IcQiC 8/3oMzRvShYFbrbZbSn+7O9M5nhB3EcrokJkCTykn0lufGHnT/aeSYaIRnqONu5tW7wO G8pJ3tiyBW2ce1t+lKtcQy+TSZ3LzSlsXGHVKYU2IfuNQcg/Sc/Dx640snRBvpgowoMU BPVOvdOWCnG/3cqorqsVqIfPGEEkh0M3+PX91oXLsViiDAKhmYSpx3FpYsZswWkwoYCf dbMQ== X-Gm-Message-State: AJIora/Op9ibeHdLWDPb6VFRc7THNTS4R8SKj+xtAKgyQt+0vZ9i5wx9 vFxGTaEkN7vF698xLtV0kcS4TkzofgO7HzM/M+HbHxCyX+p3X7nR7ZsjEiNq5/+ZynIydGnb2iQ oWLieuoLvClTHEiNYlO8qUxzLsLhT0rmzGGsVNjcO4A== X-Received: by 2002:a05:600c:4fc5:b0:3a3:2d73:c147 with SMTP id o5-20020a05600c4fc500b003a32d73c147mr2589948wmq.197.1659095898380; Fri, 29 Jul 2022 04:58:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJ+uI1Ng6GEfS7BAbk41lAxGjWb7Amqv3M5Br06a0Bvs5CP0IEjvBah6hgCJXEoUVJcWh63Q== X-Received: by 2002:a05:600c:4fc5:b0:3a3:2d73:c147 with SMTP id o5-20020a05600c4fc500b003a32d73c147mr2589928wmq.197.1659095898006; Fri, 29 Jul 2022 04:58:18 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c563]) by smtp.gmail.com with ESMTPSA id r126-20020a1c2b84000000b003a2fde6ef62sm4236516wmr.7.2022.07.29.04.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 04:58:17 -0700 (PDT) From: Nikhil Kshirsagar To: dariusz.gadomski@canonical.com, kernel-team@lists.ubuntu.com Subject: [PATCH 1/3] bcache: improve multithreaded bch_btree_check() Date: Fri, 29 Jul 2022 17:28:02 +0530 Message-Id: <20220729115804.2207073-2-nikhil.kshirsagar@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> References: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coly Li Commit 8e7102273f59 ("bcache: make bch_btree_check() to be multithreaded") makes bch_btree_check() to be much faster when checking all btree nodes during cache device registration. But it isn't in ideal shap yet, still can be improved. This patch does the following thing to improve current parallel btree nodes check by multiple threads in bch_btree_check(), - Add read lock to root node while checking all the btree nodes with multiple threads. Although currently it is not mandatory but it is good to have a read lock in code logic. - Remove local variable 'char name[32]', and generate kernel thread name string directly when calling kthread_run(). - Allocate local variable "struct btree_check_state check_state" on the stack and avoid unnecessary dynamic memory allocation for it. - Reduce BCH_BTR_CHKTHREAD_MAX from 64 to 12 which is enough indeed. - Increase check_state->started to count created kernel thread after it succeeds to create. - When wait for all checking kernel threads to finish, use wait_event() to replace wait_event_interruptible(). With this change, the code is more clear, and some potential error conditions are avoided. Fixes: 8e7102273f59 ("bcache: make bch_btree_check() to be multithreaded") Signed-off-by: Coly Li Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220524102336.10684-2-colyli@suse.de Signed-off-by: Jens Axboe (cherry picked from commit f1a27c21fee3a99487c799201ad0221da5a97f5c) Signed-off-by: Nikhil Kshirsagar --- drivers/md/bcache/btree.c | 58 ++++++++++++++++++--------------------- drivers/md/bcache/btree.h | 2 +- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 8eecc9df319b..7b6f8bfef927 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -2006,8 +2006,7 @@ int bch_btree_check(struct cache_set *c) int i; struct bkey *k = NULL; struct btree_iter iter; - struct btree_check_state *check_state; - char name[32]; + struct btree_check_state check_state; /* check and mark root node keys */ for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid) @@ -2018,63 +2017,58 @@ int bch_btree_check(struct cache_set *c) if (c->root->level == 0) return 0; - check_state = kzalloc(sizeof(struct btree_check_state), GFP_KERNEL); - if (!check_state) - return -ENOMEM; - - check_state->c = c; - check_state->total_threads = bch_btree_chkthread_nr(); - check_state->key_idx = 0; - spin_lock_init(&check_state->idx_lock); - atomic_set(&check_state->started, 0); - atomic_set(&check_state->enough, 0); - init_waitqueue_head(&check_state->wait); + check_state.c = c; + check_state.total_threads = bch_btree_chkthread_nr(); + check_state.key_idx = 0; + spin_lock_init(&check_state.idx_lock); + atomic_set(&check_state.started, 0); + atomic_set(&check_state.enough, 0); + init_waitqueue_head(&check_state.wait); + rw_lock(0, c->root, c->root->level); /* * Run multiple threads to check btree nodes in parallel, - * if check_state->enough is non-zero, it means current + * if check_state.enough is non-zero, it means current * running check threads are enough, unncessary to create * more. */ - for (i = 0; i < check_state->total_threads; i++) { - /* fetch latest check_state->enough earlier */ + for (i = 0; i < check_state.total_threads; i++) { + /* fetch latest check_state.enough earlier */ smp_mb__before_atomic(); - if (atomic_read(&check_state->enough)) + if (atomic_read(&check_state.enough)) break; - check_state->infos[i].result = 0; - check_state->infos[i].state = check_state; - snprintf(name, sizeof(name), "bch_btrchk[%u]", i); - atomic_inc(&check_state->started); + check_state.infos[i].result = 0; + check_state.infos[i].state = &check_state; - check_state->infos[i].thread = + check_state.infos[i].thread = kthread_run(bch_btree_check_thread, - &check_state->infos[i], - name); - if (IS_ERR(check_state->infos[i].thread)) { + &check_state.infos[i], + "bch_btrchk[%d]", i); + if (IS_ERR(check_state.infos[i].thread)) { pr_err("fails to run thread bch_btrchk[%d]\n", i); for (--i; i >= 0; i--) - kthread_stop(check_state->infos[i].thread); + kthread_stop(check_state.infos[i].thread); ret = -ENOMEM; goto out; } + atomic_inc(&check_state.started); } /* * Must wait for all threads to stop. */ - wait_event_interruptible(check_state->wait, - atomic_read(&check_state->started) == 0); + wait_event(check_state.wait, atomic_read(&check_state.started) == 0); - for (i = 0; i < check_state->total_threads; i++) { - if (check_state->infos[i].result) { - ret = check_state->infos[i].result; + for (i = 0; i < check_state.total_threads; i++) { + if (check_state.infos[i].result) { + ret = check_state.infos[i].result; goto out; } } out: - kfree(check_state); + rw_unlock(0, c->root); return ret; } diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h index 50482107134f..1b5fdbc0d83e 100644 --- a/drivers/md/bcache/btree.h +++ b/drivers/md/bcache/btree.h @@ -226,7 +226,7 @@ struct btree_check_info { int result; }; -#define BCH_BTR_CHKTHREAD_MAX 64 +#define BCH_BTR_CHKTHREAD_MAX 12 struct btree_check_state { struct cache_set *c; int total_threads; From patchwork Fri Jul 29 11:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikhil Kshirsagar X-Patchwork-Id: 1661997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=kmCgDKcn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LvQyc5Vf6z9sGZ for ; Fri, 29 Jul 2022 21:58:31 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oHOdK-0005nh-JD; Fri, 29 Jul 2022 11:58:22 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oHOdI-0005nO-Nc for kernel-team@lists.ubuntu.com; Fri, 29 Jul 2022 11:58:20 +0000 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7FD8B3F130 for ; Fri, 29 Jul 2022 11:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659095900; bh=G4+3ZUmQCTnhvL5bB8iyOJyVBG99Ve0kTKv1Xa2yeyM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kmCgDKcnZyxCBNWxa0bJ4AXcqRupyatNUQg+XISyiAG9XDTrPCVPrbOXHMG2Xm7Il MPnOXt3KnOHF6r97yWGZb74N3p2tHUnMmbpBXe3CsK0c2jFlzrqnjN0V2PvfZ2mMps O4qVYQM5w5/cPSpvlkGF8tvUPoDZm0po5AOJBJq5qWf3r5yp1TtxPc1xSDi1vVaksf QlzholGnWIDoMvpNh7Krzek8t1KrRGUm/2l6K7FPhhVZXPQRI2WCVeKdgzgP+uu/jH KhJ11Q4a+ZoEZpULsoDIIGXlnUPXH1qthn6vxuXrdO3mu27OzU8I/QLrv/pVo/W1EC aupHKat7dPApA== Received: by mail-wm1-f72.google.com with SMTP id h65-20020a1c2144000000b003a30cae106cso3902457wmh.8 for ; Fri, 29 Jul 2022 04:58:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G4+3ZUmQCTnhvL5bB8iyOJyVBG99Ve0kTKv1Xa2yeyM=; b=siOMU9s8wCd2JsRR+RkWwdXJWTKEipIHekSKaAli+ioJd6AE6doDJf/x3vFE0amYLN hWT2u5YK4lx+VrqDVynnCOXwXWMUt6gDy/W/fl+oDKNzX+bSvUAjjXwik/SQjWWKr3bd hU5Dx2SfERg9B3VojVbEgghPHvWfHMK8YAF+JXHM8jBYuc5xbgTSHJW4qzgGTsiUEe93 QA2eJpeW4v3L8xtSpGZTdh7n4TObKDMfliXIrKEUfzfdMQGxTTqBl995g41T+mf6SeuL XlVrq9fFmS8+mjnFpto6i7skZhLvXWQ4G+Kq+C5X0IHMRsGeRXM02yDB4mYr13rxweWG Twtg== X-Gm-Message-State: AJIora9Zul9IAVAQd7YcPGlQ7DPhYKHPCD5Xe/R1WCnzPiZWwxpqDZuT knC2Onx7ifmcj/ULnUkA50C1R7CW0R4FSct7haTbwWvVduFmGKoGu1phVAene7OlrVi8ibV78dy Md3cDlO6ofFnqAVj79jQJU31DfFkhxstBBXQPa4tKIw== X-Received: by 2002:a7b:cbce:0:b0:3a3:2d78:f066 with SMTP id n14-20020a7bcbce000000b003a32d78f066mr2322353wmi.66.1659095900179; Fri, 29 Jul 2022 04:58:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tI7ScJTkOWGtq0AuIYK7ToYfT2AZPFfYnxqmhG1cSsPV81d9/3WM6TA2L4Kl4+y1c9ZcAwRA== X-Received: by 2002:a7b:cbce:0:b0:3a3:2d78:f066 with SMTP id n14-20020a7bcbce000000b003a32d78f066mr2322325wmi.66.1659095899623; Fri, 29 Jul 2022 04:58:19 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c563]) by smtp.gmail.com with ESMTPSA id r126-20020a1c2b84000000b003a2fde6ef62sm4236516wmr.7.2022.07.29.04.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 04:58:19 -0700 (PDT) From: Nikhil Kshirsagar To: dariusz.gadomski@canonical.com, kernel-team@lists.ubuntu.com Subject: [PATCH 2/3] bcache: improve multithreaded bch_sectors_dirty_init() Date: Fri, 29 Jul 2022 17:28:03 +0530 Message-Id: <20220729115804.2207073-3-nikhil.kshirsagar@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> References: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coly Li Commit b144e45fc576 ("bcache: make bch_sectors_dirty_init() to be multithreaded") makes bch_sectors_dirty_init() to be much faster when counting dirty sectors by iterating all dirty keys in the btree. But it isn't in ideal shape yet, still can be improved. This patch does the following changes to improve current parallel dirty keys iteration on the btree, - Add read lock to root node when multiple threads iterating the btree, to prevent the root node gets split by I/Os from other registered bcache devices. - Remove local variable "char name[32]" and generate kernel thread name string directly when calling kthread_run(). - Allocate "struct bch_dirty_init_state state" directly on stack and avoid the unnecessary dynamic memory allocation for it. - Decrease BCH_DIRTY_INIT_THRD_MAX from 64 to 12 which is enough indeed. - Increase &state->started to count created kernel thread after it succeeds to create. - When wait for all dirty key counting threads to finish, use wait_event() to replace wait_event_interruptible(). With the above changes, the code is more clear, and some potential error conditions are avoided. Fixes: b144e45fc576 ("bcache: make bch_sectors_dirty_init() to be multithreaded") Signed-off-by: Coly Li Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220524102336.10684-3-colyli@suse.de Signed-off-by: Jens Axboe (cherry picked from commit 93e096c33e4fa7728d63ced0053edd389a5683c7) Signed-off-by: Nikhil Kshirsagar --- drivers/md/bcache/writeback.c | 62 ++++++++++++++--------------------- drivers/md/bcache/writeback.h | 2 +- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 1c03a3b72f8a..aac3d0ca4c25 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -945,10 +945,10 @@ void bch_sectors_dirty_init(struct bcache_device *d) struct btree_iter iter; struct sectors_dirty_init op; struct cache_set *c = d->c; - struct bch_dirty_init_state *state; - char name[32]; + struct bch_dirty_init_state state; /* Just count root keys if no leaf node */ + rw_lock(0, c->root, c->root->level); if (c->root->level == 0) { bch_btree_op_init(&op.op, -1); op.inode = d->id; @@ -958,54 +958,42 @@ void bch_sectors_dirty_init(struct bcache_device *d) for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid) sectors_dirty_init_fn(&op.op, c->root, k); + rw_unlock(0, c->root); return; } - state = kzalloc(sizeof(struct bch_dirty_init_state), GFP_KERNEL); - if (!state) { - pr_warn("sectors dirty init failed: cannot allocate memory\n"); - return; - } - - state->c = c; - state->d = d; - state->total_threads = bch_btre_dirty_init_thread_nr(); - state->key_idx = 0; - spin_lock_init(&state->idx_lock); - atomic_set(&state->started, 0); - atomic_set(&state->enough, 0); - init_waitqueue_head(&state->wait); - - for (i = 0; i < state->total_threads; i++) { - /* Fetch latest state->enough earlier */ + state.c = c; + state.d = d; + state.total_threads = bch_btre_dirty_init_thread_nr(); + state.key_idx = 0; + spin_lock_init(&state.idx_lock); + atomic_set(&state.started, 0); + atomic_set(&state.enough, 0); + init_waitqueue_head(&state.wait); + + for (i = 0; i < state.total_threads; i++) { + /* Fetch latest state.enough earlier */ smp_mb__before_atomic(); - if (atomic_read(&state->enough)) + if (atomic_read(&state.enough)) break; - state->infos[i].state = state; - atomic_inc(&state->started); - snprintf(name, sizeof(name), "bch_dirty_init[%d]", i); - - state->infos[i].thread = - kthread_run(bch_dirty_init_thread, - &state->infos[i], - name); - if (IS_ERR(state->infos[i].thread)) { + state.infos[i].state = &state; + state.infos[i].thread = + kthread_run(bch_dirty_init_thread, &state.infos[i], + "bch_dirtcnt[%d]", i); + if (IS_ERR(state.infos[i].thread)) { pr_err("fails to run thread bch_dirty_init[%d]\n", i); for (--i; i >= 0; i--) - kthread_stop(state->infos[i].thread); + kthread_stop(state.infos[i].thread); goto out; } + atomic_inc(&state.started); } - /* - * Must wait for all threads to stop. - */ - wait_event_interruptible(state->wait, - atomic_read(&state->started) == 0); - out: - kfree(state); + /* Must wait for all threads to stop. */ + wait_event(state.wait, atomic_read(&state.started) == 0); + rw_unlock(0, c->root); } void bch_cached_dev_writeback_init(struct cached_dev *dc) diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h index 02b2f9df73f6..31df716951f6 100644 --- a/drivers/md/bcache/writeback.h +++ b/drivers/md/bcache/writeback.h @@ -20,7 +20,7 @@ #define BCH_WRITEBACK_FRAGMENT_THRESHOLD_MID 57 #define BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH 64 -#define BCH_DIRTY_INIT_THRD_MAX 64 +#define BCH_DIRTY_INIT_THRD_MAX 12 /* * 14 (16384ths) is chosen here as something that each backing device * should be a reasonable fraction of the share, and not to blow up From patchwork Fri Jul 29 11:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikhil Kshirsagar X-Patchwork-Id: 1662000 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=b7Y2Nr4h; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LvQyf1BpCz9sGZ for ; Fri, 29 Jul 2022 21:58:33 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oHOdP-0005qP-5b; Fri, 29 Jul 2022 11:58:27 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oHOdK-0005nb-GN for kernel-team@lists.ubuntu.com; Fri, 29 Jul 2022 11:58:22 +0000 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4ACD93F124 for ; Fri, 29 Jul 2022 11:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659095902; bh=+AVWQHXaIDTYLD+/3L8M7tTVgTuovLrOYUQvYRml89E=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b7Y2Nr4h9veNuO3RIXGVLxNFUVDNyG/rWBfT0v0tUxmKJ438V32eDniaWQvHKckWA jJawjLQ6KunvFFce7tzwkjPMgJoM59X2Gx6XY+TsWtYiUgOWf3ckFpzcio1UJOqkW2 mldDKJiBfV+ljnnV0cMeuwsuIckc0pi9m26j/MHw0ob9qahWMUEJkhKNcy0VZrYudC 85BsJBUogRd7RasxfApe/brTc3lTqZb8ZidiZGj16w1STI9D0BNa9HMj+d7okskYXn NptESyNBaym2v9o5Dzs7mYIHgyeXMw6A/7RM/+HJynYXtBbloJhq1RU3/hIYA5FFCW R1J1d6O4a82gg== Received: by mail-wm1-f72.google.com with SMTP id ay19-20020a05600c1e1300b003a315c2c1c0so3905104wmb.7 for ; Fri, 29 Jul 2022 04:58:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+AVWQHXaIDTYLD+/3L8M7tTVgTuovLrOYUQvYRml89E=; b=gP5p7dH/anI6WSnYdVQC4EpuywnCit3yJAeTua9/DYnzRNYEkCL3gfe6ZFIevsj+lE pQdQ55AVSIVEJFioHIAMqOUBJesv+DrRzG6She5a7pub3N9m7RyZAmI9NEufzhFyTnnZ 4hqCKAvN+J8bLw/u+wPzGzdx7Ar3t0SNcSvlojaKrkLSucJFw+nutDl7v97WpjXpVcom T6Oqjop/5jtuTuAnPYz1ScQQ1sYr62BTTw+irwe1WuxIw2W/Jp4xvMZJF/cM69lxRu2O Zb6jG33ZYJfFrbMLkH7qSq2G+ouqN6Yc+cdYFXSeICncer4VTWYEqpuTPse+fxmixI2/ 4+MA== X-Gm-Message-State: ACgBeo2VgB0kiOr4OXB82HtuhX8NpA99VIy6Ol1rxBiynf6nkuAaLI1D TM3PgDQRGVt8ixI6gZe6bY97EynCyyDEAAxAiqg73NUnCpdUaY8xAz+O9CennS3zvtHNcZq4FcU ifgVupr1Mpc5kSxSFKd+jGV+t5WBU0Un998SAFP7nIA== X-Received: by 2002:a5d:59af:0:b0:21d:7f0c:a1ed with SMTP id p15-20020a5d59af000000b0021d7f0ca1edmr2250065wrr.211.1659095901518; Fri, 29 Jul 2022 04:58:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5nCBd4utUMYVhHLtRz9iqC9dJxWxGOhIGabI0kQJs36Z77ukzjMbKjPEljKwWBjZa1CmQuMw== X-Received: by 2002:a5d:59af:0:b0:21d:7f0c:a1ed with SMTP id p15-20020a5d59af000000b0021d7f0ca1edmr2250059wrr.211.1659095901324; Fri, 29 Jul 2022 04:58:21 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c563]) by smtp.gmail.com with ESMTPSA id r126-20020a1c2b84000000b003a2fde6ef62sm4236516wmr.7.2022.07.29.04.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 04:58:20 -0700 (PDT) From: Nikhil Kshirsagar To: dariusz.gadomski@canonical.com, kernel-team@lists.ubuntu.com Subject: [PATCH 3/3] bcache: memset on stack variables in bch_btree_check() and bch_sectors_dirty_init() Date: Fri, 29 Jul 2022 17:28:04 +0530 Message-Id: <20220729115804.2207073-4-nikhil.kshirsagar@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> References: <20220729115804.2207073-1-nikhil.kshirsagar@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coly Li The local variables check_state (in bch_btree_check()) and state (in bch_sectors_dirty_init()) should be fully filled by 0, because before allocating them on stack, they were dynamically allocated by kzalloc(). Signed-off-by: Coly Li Link: https://lore.kernel.org/r/20220527152818.27545-2-colyli@suse.de Signed-off-by: Jens Axboe (cherry picked from commit 0adc9f217e2d3b6949b7c2d1d4291da6c8172215) Signed-off-by: Nikhil Kshirsagar --- drivers/md/bcache/btree.c | 1 + drivers/md/bcache/writeback.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 7b6f8bfef927..98daa9d200f7 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -2017,6 +2017,7 @@ int bch_btree_check(struct cache_set *c) if (c->root->level == 0) return 0; + memset(&check_state, 0, sizeof(struct btree_check_state)); check_state.c = c; check_state.total_threads = bch_btree_chkthread_nr(); check_state.key_idx = 0; diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index aac3d0ca4c25..2cd68fb39054 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -962,6 +962,7 @@ void bch_sectors_dirty_init(struct bcache_device *d) return; } + memset(&state, 0, sizeof(struct bch_dirty_init_state)); state.c = c; state.d = d; state.total_threads = bch_btre_dirty_init_thread_nr();