diff mbox series

[2/2] block: make __get_task_ioprio() easier to read

Message ID 20240108190113.1264200-3-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 don't need to do any gymnastics if we don't have an io_context
assigned at all, so just return early with our default priority.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 include/linux/ioprio.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Bart Van Assche Jan. 8, 2024, 7:22 p.m. UTC | #1
On 1/8/24 10:59, Jens Axboe wrote:
> We don't need to do any gymnastics if we don't have an io_context
> assigned at all, so just return early with our default priority.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>   include/linux/ioprio.h | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
> index d6a9b5b7ed16..db1249cd9692 100644
> --- a/include/linux/ioprio.h
> +++ b/include/linux/ioprio.h
> @@ -59,13 +59,13 @@ static inline int __get_task_ioprio(struct task_struct *p)
>   	struct io_context *ioc = p->io_context;
>   	int prio;
>   
> +	if (!ioc)
> +		return IOPRIO_DEFAULT;
> +
>   	if (p != current)
>   		lockdep_assert_held(&p->alloc_lock);
> -	if (ioc)
> -		prio = ioc->ioprio;
> -	else
> -		prio = IOPRIO_DEFAULT;
>   
> +	prio = ioc->ioprio;
>   	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
>   		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
>   					 task_nice_ioprio(p));

Shouldn't it be mentioned in the subject that this patch is a performance
optimization? Anyway:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Jens Axboe Jan. 8, 2024, 7:26 p.m. UTC | #2
On 1/8/24 12:22 PM, Bart Van Assche wrote:
> On 1/8/24 10:59, Jens Axboe wrote:
>> We don't need to do any gymnastics if we don't have an io_context
>> assigned at all, so just return early with our default priority.
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>> ---
>>   include/linux/ioprio.h | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
>> index d6a9b5b7ed16..db1249cd9692 100644
>> --- a/include/linux/ioprio.h
>> +++ b/include/linux/ioprio.h
>> @@ -59,13 +59,13 @@ static inline int __get_task_ioprio(struct task_struct *p)
>>       struct io_context *ioc = p->io_context;
>>       int prio;
>>   +    if (!ioc)
>> +        return IOPRIO_DEFAULT;
>> +
>>       if (p != current)
>>           lockdep_assert_held(&p->alloc_lock);
>> -    if (ioc)
>> -        prio = ioc->ioprio;
>> -    else
>> -        prio = IOPRIO_DEFAULT;
>>   +    prio = ioc->ioprio;
>>       if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
>>           prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
>>                        task_nice_ioprio(p));
> 
> Shouldn't it be mentioned in the subject that this patch is a performance
> optimization? Anyway:

I doubt this matters for performance really, it's more of a readability
thing for me.

> Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Thanks!
Chaitanya Kulkarni Jan. 9, 2024, 3:23 a.m. UTC | #3
On 1/8/24 10:59, Jens Axboe wrote:
> We don't need to do any gymnastics if we don't have an io_context
> assigned at all, so just return early with our default priority.
>
> 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/include/linux/ioprio.h b/include/linux/ioprio.h
index d6a9b5b7ed16..db1249cd9692 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -59,13 +59,13 @@  static inline int __get_task_ioprio(struct task_struct *p)
 	struct io_context *ioc = p->io_context;
 	int prio;
 
+	if (!ioc)
+		return IOPRIO_DEFAULT;
+
 	if (p != current)
 		lockdep_assert_held(&p->alloc_lock);
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
 
+	prio = ioc->ioprio;
 	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
 		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
 					 task_nice_ioprio(p));