From patchwork Fri Nov 18 12:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinlong Chen X-Patchwork-Id: 22288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp158358wrr; Fri, 18 Nov 2022 04:13:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7oyIO+Lzjpw87/+7AHzBqWIOAGk6uKGnsWuo6vPTk8zfO5SV+53B8EYu4PJbcAd6DpiIEl X-Received: by 2002:a17:906:6b95:b0:781:e01e:951f with SMTP id l21-20020a1709066b9500b00781e01e951fmr5954747ejr.283.1668773596437; Fri, 18 Nov 2022 04:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668773596; cv=none; d=google.com; s=arc-20160816; b=nnHuLxHClq3g1owzjC1lVRdIKupQLEZ59XH2wTfE4Kav4sYOLmjrPFDr6fq7ENUD+U 235IZh258L9/bNcRMqgrb+fPEUtqyMAwTBAcltr5xdMwczfKhC4lNPtxYtShldwz4mJX F6WjR4DVRzGY0x8Z4lQfbooDLo8vBBsYj8Pt9IXhpXQ0SNrb/+0X2dVQrF4B59UoIsYL BZF9cgtOmwPkp6j4j5N0REJN3c+WV2TwM5sy5TMzCLAlF2Y+6Z4/TNM12HzHDRrPK52Q vvc/aInd1wQTfs0vyoi4JS1uC+pGYwaP/Y/9Q5gi3RV6SodHiwKgGx0vrLtutTBdOSwV vNUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jWNxsGs+BlW2YJl23xCLSN1By/NAFiwdQonaC5Dl6/0=; b=F246ONx767HeRd6m5g1odAX6xDkMYhF6ZUg1u/fHjHxqEaEY5Ppn+tpRU2PlNirdo/ bAXBUAdTZFj0cuE7cj3yFPXpf1G4UA34Si8wlChRXFMtj2VQjbbTBYd/vcv1/+Qi2Fem kheNclrHi7EixcGV4S+dUWWxSxDc41rzSMPa0kGWLHufmaMV13KKvLbV1PwbOOU1KOpW 5SoOm6H1qPMaQw5sVBqDR1ezwmsCZi8zV1G/nigIStVRvz/AiZ7eD6Dg+OPd/nipwtVL 8b0yfCdkZvMsuvnXV1Oh4kneEpCCuAyGIsjwrMmqDmgVq7/BWJ16If6/btlQ2s5XZT+u KUbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fy15-20020a1709069f0f00b007ae0e8f5993si2455008ejc.252.2022.11.18.04.12.51; Fri, 18 Nov 2022 04:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241659AbiKRMKX (ORCPT + 99 others); Fri, 18 Nov 2022 07:10:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241312AbiKRMKP (ORCPT ); Fri, 18 Nov 2022 07:10:15 -0500 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA7458FF96; Fri, 18 Nov 2022 04:10:13 -0800 (PST) Received: from localhost.localdomain (unknown [10.14.30.251]) by mail-app4 (Coremail) with SMTP id cS_KCgDX2MwUdndjSIwaCA--.39489S3; Fri, 18 Nov 2022 20:10:09 +0800 (CST) From: Jinlong Chen To: axboe@kernel.dk Cc: hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nickyc975@zju.edu.cn Subject: [RFC PATCH 1/2] elevator: add a helper for applying scheduler to request_queue Date: Fri, 18 Nov 2022 20:09:53 +0800 Message-Id: <5abfd81ae73b4e86ff260475b28a218e78eaad4a.1668772991.git.nickyc975@zju.edu.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: cS_KCgDX2MwUdndjSIwaCA--.39489S3 X-Coremail-Antispam: 1UD129KBjvJXoW7GF47Cw1rAr4fJw48CFW8Xrb_yoW8JF1DpF Z5GwsIkr1Fqr4xXa13Zw17X345J34v9ry3ZrWxA34IkFnFyrW3Ka18CF12qF45Grs7AFsa vF48ta9rCFyj9rJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvS1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI 7VAKI48JMxAIw28IcVCjz48v1sIEY20_GFWkJr1UJwCFx2IqxVCFs4IE7xkEbVWUJVW8Jw C20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAF wI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjx v20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2 jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43 ZEXa7VUbHa0DUUUUU== X-CM-SenderInfo: qssqjiaqqzq6lmxovvfxof0/1tbiAgAPB1ZdtcbINgAGsK X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749835942763341187?= X-GMAIL-MSGID: =?utf-8?q?1749835942763341187?= Prepare for supporting fallback in elevator_switch. Signed-off-by: Jinlong Chen --- block/elevator.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index a5bdc3b1e7e5..517857a9a68f 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -649,6 +649,21 @@ void elevator_init_mq(struct request_queue *q) elevator_put(e); } +static int __elevator_apply(struct request_queue *q, struct elevator_type *e) +{ + int ret; + + ret = blk_mq_init_sched(q, e); + if (ret) + return ret; + + ret = elv_register_queue(q, true); + if (ret) + elevator_exit(q); + + return ret; +} + /* * switch to new_e io scheduler. be careful not to introduce deadlocks - * we don't free the old io scheduler, before we have allocated what we @@ -669,15 +684,10 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) elevator_exit(q); } - ret = blk_mq_init_sched(q, new_e); + ret = __elevator_apply(q, new_e); if (ret) goto out_unfreeze; - ret = elv_register_queue(q, true); - if (ret) { - elevator_exit(q); - goto out_unfreeze; - } blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); out_unfreeze: From patchwork Fri Nov 18 12:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinlong Chen X-Patchwork-Id: 22289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp158545wrr; Fri, 18 Nov 2022 04:13:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YX56fK93ui+CML+Yl5YR7SOHjuhH1c+iqeTRR+823hio+AOjVpDTwRnV1fJCw3CZQLngg X-Received: by 2002:a05:6a00:216e:b0:56e:7b62:bba with SMTP id r14-20020a056a00216e00b0056e7b620bbamr7533441pff.55.1668773625647; Fri, 18 Nov 2022 04:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668773625; cv=none; d=google.com; s=arc-20160816; b=GItzvk4L/BH6I5ZHg7Cf8/OnDt9TjQ5wO1HdMjKVyJBi08/j18OdQRnSlndmRtRa4X NerFgLYVeD+hDSQ0OVSgMiPkq5F89yTInB/cHVXmMaANN5hys2dSIgbgT2ORIMYruOP6 w5N3yecVxlWms67trWxA4MueWyeOIYVjD2KQVRsSaXbQJQgrkYvSe0fdTg0EJtzT3zHx W4LvMSQqqjCn6ik2sjAkHTbf8Q4KTjZhlHxHVEtYi7dE85kal6G/0YoO268wsAZDQp5i zpLg7zw1CMvZdly9LOqn0EWiLojQscbQihXMVnhB5iucOfVamj8dO5IB0ShHuMj02y9C 7E4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5ck1b6v2qcs3j/xUIVXz0quLdXwFCsdWY/CiTKEi7T0=; b=Gq8xzGYZONGrJ9av/LZu1utTPCvJI8HCC3xcnWi6/swFx811tc809n6ndbJE5UK4KA q3MOwRtZnpOZJnHJnpSauORhMVIE2TqRQJhXXQfJZQx+DM3/yJejAwff6QVBsOvgKKww 2HpaATunfbn3CuaQDoE/S15yyXCFC3JlZlmHsCgfhvapcMX6C7Qbn0B7DVOYLZKJ/kxB Q2LZkJefP6OJgUb0IeQAylRnrRHbnFiAY18CxlNJIcl4qCRLd2wewM5sw6sFRK+HaoJQ stsCx2hkmzJ/HUT0Fm9bKnfBHJ3SbS0Kwn0C9YNDCXlSAb5Is9z/hzgIqGf1xqv0o6hm 7O3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170902c94600b00172f6726d91si3744743pla.565.2022.11.18.04.13.31; Fri, 18 Nov 2022 04:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241710AbiKRMK2 (ORCPT + 99 others); Fri, 18 Nov 2022 07:10:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241441AbiKRMKP (ORCPT ); Fri, 18 Nov 2022 07:10:15 -0500 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E6DE8FF8B; Fri, 18 Nov 2022 04:10:13 -0800 (PST) Received: from localhost.localdomain (unknown [10.14.30.251]) by mail-app4 (Coremail) with SMTP id cS_KCgDX2MwUdndjSIwaCA--.39489S4; Fri, 18 Nov 2022 20:10:11 +0800 (CST) From: Jinlong Chen To: axboe@kernel.dk Cc: hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nickyc975@zju.edu.cn Subject: [RFC PATCH 2/2] elevator: restore the old io scheduler if failed to switch to the new one Date: Fri, 18 Nov 2022 20:09:54 +0800 Message-Id: <29281ffcdd756bdbdfcee8769cd8b2eb867b74e2.1668772991.git.nickyc975@zju.edu.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: cS_KCgDX2MwUdndjSIwaCA--.39489S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Kry7JFWDAryUGr45Zw4Dtwb_yoW8AF1xpF 4rGwsxKrsrJr47X3W3Cw17Z345tF9agrW3XrWxC34FkFn3tr47Ja1UGF1IvF4DJrW8JFsI vr48tFWDGa4UurJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvq1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI 7VAKI48JMxAIw28IcVCjz48v1sIEY20_GFWkJr1UJwCFx2IqxVCFs4IE7xkEbVWUJVW8Jw C20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAF wI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjx v20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2 jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0x ZFpf9x0JUQZ23UUUUU= X-CM-SenderInfo: qssqjiaqqzq6lmxovvfxof0/1tbiAg0SB1ZdtcfEpQAAsC X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749835973283102423?= X-GMAIL-MSGID: =?utf-8?q?1749835973283102423?= If we failed to switch to the new io scheduler, we should try to restore the old one instead of just switching to none. This also makes elevator_switch match its document. Signed-off-by: Jinlong Chen --- block/elevator.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index 517857a9a68f..b7bd0b8468bd 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -672,6 +672,7 @@ static int __elevator_apply(struct request_queue *q, struct elevator_type *e) */ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) { + struct elevator_type *old_e = NULL; int ret; lockdep_assert_held(&q->sysfs_lock); @@ -680,17 +681,37 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) blk_mq_quiesce_queue(q); if (q->elevator) { + old_e = q->elevator->type; + /* + * Keep a reference so we can fallback on failure. + */ + __elevator_get(old_e); elv_unregister_queue(q); elevator_exit(q); } ret = __elevator_apply(q, new_e); - if (ret) - goto out_unfreeze; + if (likely(!ret)) { + blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); + } else if (old_e) { + int err; + + err = __elevator_apply(q, old_e); + if (unlikely(err)) { + blk_add_trace_msg(q, + "elv switch failed: %s (%d), fallback failed: %s (%d)", + new_e->elevator_name, ret, old_e->elevator_name, err + ); + } + } - blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); + if (old_e) { + /* + * Done, release the reference we kept. + */ + elevator_put(old_e); + } -out_unfreeze: blk_mq_unquiesce_queue(q); blk_mq_unfreeze_queue(q); return ret;