diff mbox series

[1/2] block: move __get_task_ioprio() into header file

Message ID 20240108190113.1264200-2-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series Optimize get_current_ioprio() a bit | expand

Commit Message

Jens Axboe Jan. 8, 2024, 6:59 p.m. UTC
We call this once per IO, which can be millions of times per second.
Since nobody really uses io priorities, or at least it isn't very
common, this is all wasted time and can amount to as much as 3% of
the total kernel time.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 block/ioprio.c         | 26 --------------------------
 include/linux/ioprio.h | 25 ++++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 27 deletions(-)

Comments

Bart Van Assche Jan. 8, 2024, 7:24 p.m. UTC | #1
On 1/8/24 10:59, Jens Axboe wrote:
> We call this once per IO, which can be millions of times per second.
> Since nobody really uses io priorities, or at least it isn't very
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We have plans to set an I/O priority for most Android processes in the
near future. According to what Damien wrote on linux-block, there is
probably a significant number of hard disks for which I/O priority is
configured.

> common, this is all wasted time and can amount to as much as 3% of
> the total kernel time.

Anyway:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Jens Axboe Jan. 8, 2024, 7:27 p.m. UTC | #2
On 1/8/24 12:24 PM, Bart Van Assche wrote:
> On 1/8/24 10:59, Jens Axboe wrote:
>> We call this once per IO, which can be millions of times per second.
>> Since nobody really uses io priorities, or at least it isn't very
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> We have plans to set an I/O priority for most Android processes in the
> near future. According to what Damien wrote on linux-block, there is
> probably a significant number of hard disks for which I/O priority is
> configured.

The rates at which Android does IO means this won't really make any
difference, should probably have qualified the statement with "nobody
uses io priorities and does fast IO".

>> common, this is all wasted time and can amount to as much as 3% of
>> the total kernel time.
> 
> Anyway:
> 
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Thanks!
Chaitanya Kulkarni Jan. 9, 2024, 3:20 a.m. UTC | #3
On 1/8/24 10:59, Jens Axboe wrote:
> We call this once per IO, which can be millions of times per second.
> Since nobody really uses io priorities, or at least it isn't very
> common, this is all wasted time and can amount to as much as 3% of
> the total kernel time.
>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
diff mbox series

Patch

diff --git a/block/ioprio.c b/block/ioprio.c
index b5a942519a79..73301a261429 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -139,32 +139,6 @@  SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
-/*
- * If the task has set an I/O priority, use that. Otherwise, return
- * the default I/O priority.
- *
- * Expected to be called for current task or with task_lock() held to keep
- * io_context stable.
- */
-int __get_task_ioprio(struct task_struct *p)
-{
-	struct io_context *ioc = p->io_context;
-	int prio;
-
-	if (p != current)
-		lockdep_assert_held(&p->alloc_lock);
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
-
-	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
-		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
-					 task_nice_ioprio(p));
-	return prio;
-}
-EXPORT_SYMBOL_GPL(__get_task_ioprio);
-
 static int get_task_ioprio(struct task_struct *p)
 {
 	int ret;
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index 7578d4f6a969..d6a9b5b7ed16 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -47,7 +47,30 @@  static inline int task_nice_ioclass(struct task_struct *task)
 }
 
 #ifdef CONFIG_BLOCK
-int __get_task_ioprio(struct task_struct *p);
+/*
+ * If the task has set an I/O priority, use that. Otherwise, return
+ * the default I/O priority.
+ *
+ * Expected to be called for current task or with task_lock() held to keep
+ * io_context stable.
+ */
+static inline int __get_task_ioprio(struct task_struct *p)
+{
+	struct io_context *ioc = p->io_context;
+	int prio;
+
+	if (p != current)
+		lockdep_assert_held(&p->alloc_lock);
+	if (ioc)
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
+					 task_nice_ioprio(p));
+	return prio;
+}
 #else
 static inline int __get_task_ioprio(struct task_struct *p)
 {