From patchwork Mon Sep 19 01:49:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12979638 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 ADCA3C54EE9 for ; Mon, 19 Sep 2022 01:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbiISBix (ORCPT ); Sun, 18 Sep 2022 21:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiISBiw (ORCPT ); Sun, 18 Sep 2022 21:38:52 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37764186C3; Sun, 18 Sep 2022 18:38:50 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MW6jH6ccqz6S2ym; Mon, 19 Sep 2022 09:36:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgA3inMmyCdjeiM6BA--.44102S5; Mon, 19 Sep 2022 09:38:48 +0800 (CST) From: Yu Kuai To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH -next 1/3] wbt: don't show valid wbt_lat_usec in sysfs while wbt is disabled Date: Mon, 19 Sep 2022 09:49:37 +0800 Message-Id: <20220919014939.175497-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220919014939.175497-1-yukuai1@huaweicloud.com> References: <20220919014939.175497-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgA3inMmyCdjeiM6BA--.44102S5 X-Coremail-Antispam: 1UD129KBjvJXoW7trWxZw1rtr4kCFy8Xr4rAFb_yoW8Kw45pa y7G34akF12gF47XFyxJrsrW3y3Kw48KrWxK3y8Gw4Yvrya9r12va1vkFWxXF95ZrWfCFsx Wrn0yrZ8ZF4jgFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUyKZAUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yu Kuai Currently, if wbt is initialized and then disabled by wbt_disable_default(), sysfs will still show valid wbt_lat_usec, which will confuse users that wbt is still enabled. This patch shows wbt_lat_usec as zero and forbid to set it while wbt is disabled. Signed-off-by: Yu Kuai Reported-and-tested-by: Holger Hoffstätte Reported-by: kernel test robot Reported-by: kernel test robot --- block/blk-sysfs.c | 9 ++++++++- block/blk-wbt.c | 7 +++++++ block/blk-wbt.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index e1f009aba6fd..1955bb6a284d 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -467,10 +467,14 @@ static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page, static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) { + u64 lat; + if (!wbt_rq_qos(q)) return -EINVAL; - return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); + lat = wbt_disabled(q) ? 0 : div_u64(wbt_get_min_lat(q), 1000); + + return sprintf(page, "%llu\n", lat); } static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, @@ -493,6 +497,9 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, return ret; } + if (wbt_disabled(q)) + return -EINVAL; + if (val == -1) val = wbt_default_latency_nsec(q); else if (val >= 0) diff --git a/block/blk-wbt.c b/block/blk-wbt.c index a9982000b667..68851c2c02d2 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -422,6 +422,13 @@ static void wbt_update_limits(struct rq_wb *rwb) rwb_wake_all(rwb); } +bool wbt_disabled(struct request_queue *q) +{ + struct rq_qos *rqos = wbt_rq_qos(q); + + return !rqos || RQWB(rqos)->enable_state == WBT_STATE_OFF_DEFAULT; +} + u64 wbt_get_min_lat(struct request_queue *q) { struct rq_qos *rqos = wbt_rq_qos(q); diff --git a/block/blk-wbt.h b/block/blk-wbt.h index 7e44eccc676d..018d3a14cc30 100644 --- a/block/blk-wbt.h +++ b/block/blk-wbt.h @@ -94,6 +94,7 @@ void wbt_enable_default(struct request_queue *); u64 wbt_get_min_lat(struct request_queue *q); void wbt_set_min_lat(struct request_queue *q, u64 val); +bool wbt_disabled(struct request_queue *); void wbt_set_write_cache(struct request_queue *, bool); From patchwork Mon Sep 19 01:49:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12979639 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 0F285C6FA90 for ; Mon, 19 Sep 2022 01:38:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbiISBiz (ORCPT ); Sun, 18 Sep 2022 21:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiISBiw (ORCPT ); Sun, 18 Sep 2022 21:38:52 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37E8A186C9; Sun, 18 Sep 2022 18:38:50 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MW6jJ209Nz6S2yL; Mon, 19 Sep 2022 09:36:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgA3inMmyCdjeiM6BA--.44102S6; Mon, 19 Sep 2022 09:38:48 +0800 (CST) From: Yu Kuai To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH -next 2/3] block: add a helper to check elevator name Date: Mon, 19 Sep 2022 09:49:38 +0800 Message-Id: <20220919014939.175497-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220919014939.175497-1-yukuai1@huaweicloud.com> References: <20220919014939.175497-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgA3inMmyCdjeiM6BA--.44102S6 X-Coremail-Antispam: 1UD129KBjvdXoWrKr4rur18CF45WFyxtr1UKFg_yoWxtrb_G3 y8Kw1kZ398Jr1Fyr1UtFyYqry0gws3JryfWw17tF1kAF4rWF1Fy3yxAr1UCrnrJFWjk3W5 Cr48ur18Zr1jgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb-kFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY02 0Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUj8nY7UUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yu Kuai The helper will be used in later patch to make sure wbt is not enabled if default io scheduler is bfq. Signed-off-by: Yu Kuai --- block/elevator.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/elevator.h b/block/elevator.h index 3f0593b3bf9d..ccded343cf27 100644 --- a/block/elevator.h +++ b/block/elevator.h @@ -104,6 +104,11 @@ struct elevator_queue DECLARE_HASHTABLE(hash, ELV_HASH_BITS); }; +static inline bool check_elevator_name(struct elevator_queue *elevator, + const char *name) +{ + return !strcmp(elevator->type->elevator_name, name); +} /* * block elevator interface */ From patchwork Mon Sep 19 01:49:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12979640 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 04F7DECAAD8 for ; Mon, 19 Sep 2022 01:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbiISBiy (ORCPT ); Sun, 18 Sep 2022 21:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbiISBiw (ORCPT ); Sun, 18 Sep 2022 21:38:52 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A64C9186CD; Sun, 18 Sep 2022 18:38:50 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MW6jd1nW6zlCC0; Mon, 19 Sep 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgA3inMmyCdjeiM6BA--.44102S7; Mon, 19 Sep 2022 09:38:48 +0800 (CST) From: Yu Kuai To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH -next 3/3] blk-wbt: don't enable throttling if default elevator is bfq Date: Mon, 19 Sep 2022 09:49:39 +0800 Message-Id: <20220919014939.175497-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220919014939.175497-1-yukuai1@huaweicloud.com> References: <20220919014939.175497-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgA3inMmyCdjeiM6BA--.44102S7 X-Coremail-Antispam: 1UD129KBjvJXoWxAw1kCw15ZFW3Ar47Kw1Dtrb_yoW5uw47p3 yUGF4FkFW2gF409FWxJrnrXw43Gw4kCry7Gry8C3yFqry2krZFva1vkF1UZF1vvrZ7CFsF vr48trZrXF40gw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU4q2_UUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yu Kuai Commit b5dc5d4d1f4f ("block,bfq: Disable writeback throttling") tries to disable wbt for bfq, it's done by calling wbt_disable_default() in bfq_init_queue(). However, wbt is still enabled if default elevator is bfq: device_add_disk elevator_init_mq bfq_init_queue wbt_disable_default -> done nothing blk_register_queue wbt_enable_default -> wbt is enabled Fix the problem by checking elevator name if wbt_enable_default() is called from blk_register_queue(). Signed-off-by: Yu Kuai --- block/bfq-iosched.c | 2 +- block/blk-sysfs.c | 2 +- block/blk-wbt.c | 7 ++++++- block/blk-wbt.h | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 7ea427817f7f..f769c90744fd 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -7045,7 +7045,7 @@ static void bfq_exit_queue(struct elevator_queue *e) #endif blk_stat_disable_accounting(bfqd->queue); - wbt_enable_default(bfqd->queue); + wbt_enable_default(bfqd->queue, false); kfree(bfqd); } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 1955bb6a284d..3e8adb95ff02 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -850,7 +850,7 @@ int blk_register_queue(struct gendisk *disk) goto put_dev; blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q); - wbt_enable_default(q); + wbt_enable_default(q, true); blk_throtl_register_queue(q); /* Now everything is ready and send out KOBJ_ADD uevent */ diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 68851c2c02d2..54acde63538d 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -27,6 +27,7 @@ #include "blk-wbt.h" #include "blk-rq-qos.h" +#include "elevator.h" #define CREATE_TRACE_POINTS #include @@ -643,10 +644,14 @@ void wbt_set_write_cache(struct request_queue *q, bool write_cache_on) /* * Enable wbt if defaults are configured that way */ -void wbt_enable_default(struct request_queue *q) +void wbt_enable_default(struct request_queue *q, bool check_elevator) { struct rq_qos *rqos = wbt_rq_qos(q); + if (check_elevator && q->elevator && + check_elevator_name(q->elevator, "bfq")) + return; + /* Throttling already enabled? */ if (rqos) { if (RQWB(rqos)->enable_state == WBT_STATE_OFF_DEFAULT) diff --git a/block/blk-wbt.h b/block/blk-wbt.h index 018d3a14cc30..4252b8077257 100644 --- a/block/blk-wbt.h +++ b/block/blk-wbt.h @@ -90,7 +90,7 @@ static inline unsigned int wbt_inflight(struct rq_wb *rwb) int wbt_init(struct request_queue *); void wbt_disable_default(struct request_queue *); -void wbt_enable_default(struct request_queue *); +void wbt_enable_default(struct request_queue *, bool); u64 wbt_get_min_lat(struct request_queue *q); void wbt_set_min_lat(struct request_queue *q, u64 val); @@ -109,7 +109,8 @@ static inline int wbt_init(struct request_queue *q) static inline void wbt_disable_default(struct request_queue *q) { } -static inline void wbt_enable_default(struct request_queue *q) +static inline void wbt_enable_default(struct request_queue *q, + bool check_elevator) { } static inline void wbt_set_write_cache(struct request_queue *q, bool wc)