summaryrefslogtreecommitdiff
path: root/include/linux/ioprio.h
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-01-08 11:50:16 -0700
committerJens Axboe <axboe@kernel.dk>2024-01-08 12:27:39 -0700
commit3b7cb745473aec7255d66e3854abaa9c3f46f952 (patch)
tree900d7e95798bb1202b13838e3f1981f9127d87f3 /include/linux/ioprio.h
parent587371ed783b046f22ba7a5e1cc9a19ae35123b4 (diff)
block: move __get_task_ioprio() into header file
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. Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/ioprio.h')
-rw-r--r--include/linux/ioprio.h25
1 files changed, 24 insertions, 1 deletions
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)
{