From patchwork Wed Jun 1 14:51:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 12866925 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 E13BAC433EF for ; Wed, 1 Jun 2022 14:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351830AbiFAOvP (ORCPT ); Wed, 1 Jun 2022 10:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233844AbiFAOvO (ORCPT ); Wed, 1 Jun 2022 10:51:14 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 954C75DD17 for ; Wed, 1 Jun 2022 07:51:12 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 47BFF1F45B; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1654095071; 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=jMZ1PNxpojIsC+YQ5M2rLw+/1l/41aL02AN8DG2/7DY=; b=iSYGdl+484iG54H7MiExPQtCb7eJDvhOV5eGR5s9VIZLeJN9WBF5uQOMlFOLFzjIzm4Cjp yqybRIsNCQbMbcG4NeZxdFu7IkXUIk79PBV9huCq0iNdq04EpzZbi2sUhl3E6zi1IIhYyw Qm9nmb6zc5yx4ptEFqtyELhdvlJvoeg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1654095071; 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=jMZ1PNxpojIsC+YQ5M2rLw+/1l/41aL02AN8DG2/7DY=; b=DCx755sjFfzu9eSXvJMIgHs6BoEnzGkx8u+CgVXKo9VH+A+bdZjYtCrnmJ2LdOUb60lJFV yDtWQh6SpaGAg1CQ== Received: from quack3.suse.cz (unknown [10.163.28.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 10B7A2C143; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id BC30AA058D; Wed, 1 Jun 2022 16:51:10 +0200 (CEST) From: Jan Kara To: Jens Axboe Cc: , Christoph Hellwig , Damien Le Moal , Jan Kara Subject: [PATCH 1/3] block: Fix handling of tasks without ioprio in ioprio_get(2) Date: Wed, 1 Jun 2022 16:51:04 +0200 Message-Id: <20220601145110.18162-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220601132347.13543-1-jack@suse.cz> References: <20220601132347.13543-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1379; h=from:subject; bh=DrktAva6a1bSdo78uXUizm++kg+STNH7MrZjnF/SJ64=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBil3zY+qO6IH/D5QzAs1m+CKwQiXnsrh3+fBP+wzDS RUrCfmyJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYpd82AAKCRCcnaoHP2RA2Uq9CA CM86kkdGecEe0xpVSNFYXYPu+az7zovviGIyRGTWvVuRvhsnTpUMmZC9SvJyldjjr3XHZlpphc5k3A hiH7xmgB1x1HYEQWyYE4fWAMRV2XrL0jRyFcQDHSnP7rYBwpzZDI2//uJggtTIQcKFHC+e+kDfB6Pi f2QpuPfLa0qI+xKu22UG6rzz2oS8GMNfSeYlyPED0ztQsCK4gY19Q6p/cVBHfHv//LLOeIPbxNY0Nh XcfFC/vK2wBziuZ/QaBjtB2Awzeiw0oH3qbI1EMFATR56fR6keeUXg246WvLFQ1MfQ4jrFVsXkmPBP OfOINL5/bCs2Mf4wqH3V1OYb7BEl9A X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org ioprio_get(2) can be asked to return the best IO priority from several tasks (IOPRIO_WHO_PGRP, IOPRIO_WHO_USER). Currently the call treats tasks without set IO priority as having priority IOPRIO_CLASS_BE/IOPRIO_BE_NORM however this does not really reflect the IO priority the task will get (which depends on task's nice value) and with the following fix it will not even match returned IO priority for a single task. So fix IO priority comparison to treat unset IO priority as the lowest possible one. This way we will return IOPRIO_CLASS_NONE priority only if none of the considered tasks has explicitely set IO priority, otherwise we return the highest set IO priority. This changes userspace visible behavior but hopefully the results are clearer and nothing breaks. Signed-off-by: Jan Kara --- block/ioprio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/block/ioprio.c b/block/ioprio.c index 2fe068fcaad5..62890391fc80 100644 --- a/block/ioprio.c +++ b/block/ioprio.c @@ -157,10 +157,9 @@ static int get_task_ioprio(struct task_struct *p) int ioprio_best(unsigned short aprio, unsigned short bprio) { if (!ioprio_valid(aprio)) - aprio = IOPRIO_DEFAULT; + return bprio; if (!ioprio_valid(bprio)) - bprio = IOPRIO_DEFAULT; - + return aprio; return min(aprio, bprio); } From patchwork Wed Jun 1 14:51:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 12866926 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 437B3CCA473 for ; Wed, 1 Jun 2022 14:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353435AbiFAOvP (ORCPT ); Wed, 1 Jun 2022 10:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343741AbiFAOvO (ORCPT ); Wed, 1 Jun 2022 10:51:14 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96AC45DD1E for ; Wed, 1 Jun 2022 07:51:12 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4A92621AE9; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1654095071; 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=DTz8ZVve7ICu7ezzDrVXZ+LmahVFfCLd1uVrOnwq32w=; b=h/03BKw4627BrOicSvXkUKVIdt+Paj0lQHUP1VALnfUWK2s6YWEHKq29bvWbj+XOwyMn4e cdurL0JSFLoz4yMiqUz2dxXgeyL+bboGaAyYggs2GJJb8FUjnKAqCc8yRXdYAk002DSMf9 boNkMJ/Pj45jYyPQ1KTfhUaHZGvjjPE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1654095071; 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=DTz8ZVve7ICu7ezzDrVXZ+LmahVFfCLd1uVrOnwq32w=; b=JkRgz3vU3RWJfv2LPLvMxRPUFnWlf90+kt4C3ExzHBp8B5I7/qLCjTnOCnoZZp1Vxrfm3p l1XUw6XpU4ZKOvAA== Received: from quack3.suse.cz (unknown [10.163.28.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0D1A62C141; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id C3ED9A0635; Wed, 1 Jun 2022 16:51:10 +0200 (CEST) From: Jan Kara To: Jens Axboe Cc: , Christoph Hellwig , Damien Le Moal , Jan Kara Subject: [PATCH 2/3] block: Make ioprio_best() static Date: Wed, 1 Jun 2022 16:51:05 +0200 Message-Id: <20220601145110.18162-2-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220601132347.13543-1-jack@suse.cz> References: <20220601132347.13543-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1133; h=from:subject; bh=rPhukKpylibo4V7blrFwToaoTXpiIOZKaKcKjvnBkH8=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBil3zZL3CrP+llnmWK8hvTtjpQrXA8t+2r7TnX2j/R XDlm+QKJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYpd82QAKCRCcnaoHP2RA2b/lCA Dr01+n9N+mt1BZVhsQz7922ta3w7crfcaYPGSq41A+LG5zK4Q/0BY3x6V4Cz1jPMtXh6odvu4AGxED sdeBTVISKjcvT9o0l+RZ+FwWfGxh53Bj7zybYGHbudBOLr45fw2Mz7R6K5JwIT3X6yNYsIb6HpbwDI 7u88RvasUZ0vhD2oJQwk0b5zjGR7v99ZTWnxr68yTVC1I2mGAU1GTvOpdVBiOP61gzvCuNBAM3QPOR yreCa4yZZI4ICYqEZsPYjbG66SKOH79xsqU5QCrWgwQ5n95HD63ZOJXu4G1MdTYg1cuBMn4aaDdGdw 4QZqYjkz9/xGwBNaOiIDPh7klJEpqn X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Nobody outside of block/ioprio.c uses it. Signed-off-by: Jan Kara --- block/ioprio.c | 2 +- include/linux/ioprio.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/block/ioprio.c b/block/ioprio.c index 62890391fc80..18f7e16882fe 100644 --- a/block/ioprio.c +++ b/block/ioprio.c @@ -154,7 +154,7 @@ static int get_task_ioprio(struct task_struct *p) return ret; } -int ioprio_best(unsigned short aprio, unsigned short bprio) +static int ioprio_best(unsigned short aprio, unsigned short bprio) { if (!ioprio_valid(aprio)) return bprio; diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h index 3f53bc27a19b..774bb90ad668 100644 --- a/include/linux/ioprio.h +++ b/include/linux/ioprio.h @@ -59,11 +59,6 @@ static inline int get_current_ioprio(void) return IOPRIO_DEFAULT; } -/* - * For inheritance, return the highest of the two given priorities - */ -extern int ioprio_best(unsigned short aprio, unsigned short bprio); - extern int set_task_ioprio(struct task_struct *task, int ioprio); #ifdef CONFIG_BLOCK From patchwork Wed Jun 1 14:51:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 12866927 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 7D4EACCA478 for ; Wed, 1 Jun 2022 14:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346832AbiFAOvQ (ORCPT ); Wed, 1 Jun 2022 10:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233844AbiFAOvP (ORCPT ); Wed, 1 Jun 2022 10:51:15 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 971215DD21 for ; Wed, 1 Jun 2022 07:51:12 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4BC211F8F6; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1654095071; 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=yUduM4lG2q2GY35eSJ4HLE/WEL036XTWEqWZF30BRZA=; b=j6I9ufRf+6qlHq5Ye9C7SShlYxn5Y8nSobvRjrbcQ3JV6LsfZJrKn7oz2LP/uziqTGyXMJ ZWYTR1VtK5K8VOATnlbzcVPumU+ByskpCVfc5idlpoFeY3/OtonXI9zJGLh8Jr8fJ2KxQ3 6oP8W+yqleiMp2wTcEyzZxV0Nm7CI/4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1654095071; 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=yUduM4lG2q2GY35eSJ4HLE/WEL036XTWEqWZF30BRZA=; b=UKQBt1HZTfQJnp4lW3g3OzAaAtC/0kMWmg8YNe2Ugpu47o/OHV1yapNREacYIX0pFl6xZR 4/pZloQc8Q7y4YAw== Received: from quack3.suse.cz (unknown [10.163.28.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 133932C145; Wed, 1 Jun 2022 14:51:11 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id C9F06A0637; Wed, 1 Jun 2022 16:51:10 +0200 (CEST) From: Jan Kara To: Jens Axboe Cc: , Christoph Hellwig , Damien Le Moal , Jan Kara Subject: [PATCH 3/3] block: fix default IO priority handling again Date: Wed, 1 Jun 2022 16:51:06 +0200 Message-Id: <20220601145110.18162-3-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220601132347.13543-1-jack@suse.cz> References: <20220601132347.13543-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2229; h=from:subject; bh=F/+79O3vT4YJ18myuAZmNBRsDmfEk3VfFl9MazpsqGQ=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBil3zaD2Dh0tXPI5QrXiqY5Xj8NIYkL00D+oD9WQcq QdRrANaJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYpd82gAKCRCcnaoHP2RA2QrBCA DNeuqpwzGyaHeIRCxuFM3ewOcoGjZR217e2DveCBDlnv+hu9MnF7o4f/QgqlZH+dJWbXz4JhKt8/Xt 4KPj62xrhpg4YoTWCV5q/t10cgtbvy51Ar8LfGadwrIdVujrVnIS0cfOD0cYQ5Oty/ftjgMlWKMBTJ KY0d517H8N5KfeOUmXSGG+AZYo+4OXXa3ShfDAcYRatFyrv2uIDlBze/fZkIzfd2o129aZwzLafnri dd3QVXbYlHqCNSkvswJskOvHjRHepyiUavLTX5DrNThyqz5l19yu6NT62E9JEf16L1CyYrOTt38Y9B eY4iVxeB+uyLfoteXbbVq29RD4P6rQ X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Commit e70344c05995 ("block: fix default IO priority handling") introduced an inconsistency in get_current_ioprio() that tasks without IO context return IOPRIO_DEFAULT priority while tasks with freshly allocated IO context will return 0 (IOPRIO_CLASS_NONE/0) IO priority. Tasks without IO context used to be rare before 5a9d041ba2f6 ("block: move io_context creation into where it's needed") but after this commit they became common because now only BFQ IO scheduler setups task's IO context. Similar inconsistency is there for get_task_ioprio() so this inconsistency is now exposed to userspace and userspace will see different IO priority for tasks operating on devices with BFQ compared to devices without BFQ. Furthemore the changes done by commit e70344c05995 change the behavior when no IO priority is set for BFQ IO scheduler which is also documented in ioprio_set(2) manpage - namely that tasks without set IO priority will use IO priority based on their nice value. So make sure we default to IOPRIO_CLASS_NONE as used to be the case before commit e70344c05995. Also cleanup alloc_io_context() to explicitely set this IO priority for the allocated IO context. Fixes: e70344c05995 ("block: fix default IO priority handling") Signed-off-by: Jan Kara --- block/blk-ioc.c | 2 ++ include/linux/ioprio.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/block/blk-ioc.c b/block/blk-ioc.c index df9cfe4ca532..63fc02042408 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -247,6 +247,8 @@ static struct io_context *alloc_io_context(gfp_t gfp_flags, int node) INIT_HLIST_HEAD(&ioc->icq_list); INIT_WORK(&ioc->release_work, ioc_release_fn); #endif + ioc->ioprio = IOPRIO_DEFAULT; + return ioc; } diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h index 774bb90ad668..d9dc78a15301 100644 --- a/include/linux/ioprio.h +++ b/include/linux/ioprio.h @@ -11,7 +11,7 @@ /* * Default IO priority. */ -#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM) +#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0) /* * Check that a priority value has a valid class.