diff mbox series

aio: Save a few cycles in 'lookup_ioctx()'

Message ID 0c3fcdaec33bb12b2367860dfab7ed4224ea000c.1635974999.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New, archived
Headers show
Series aio: Save a few cycles in 'lookup_ioctx()' | expand

Commit Message

Christophe JAILLET Nov. 3, 2021, 9:31 p.m. UTC
Use 'percpu_ref_tryget_live_rcu()' instead of 'percpu_ref_tryget_live()' to
save a few cycles when it is known that the rcu lock is already
taken/released.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 fs/aio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christophe JAILLET Aug. 12, 2022, 4:54 a.m. UTC | #1
Le 03/11/2021 à 22:31, Christophe JAILLET a écrit :
> Use 'percpu_ref_tryget_live_rcu()' instead of 'percpu_ref_tryget_live()' to
> save a few cycles when it is known that the rcu lock is already
> taken/released.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   fs/aio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/aio.c b/fs/aio.c
> index 9c81cf611d65..d189ea13e10a 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -1062,7 +1062,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
>   	id = array_index_nospec(id, table->nr);
>   	ctx = rcu_dereference(table->table[id]);
>   	if (ctx && ctx->user_id == ctx_id) {
> -		if (percpu_ref_tryget_live(&ctx->users))
> +		if (percpu_ref_tryget_live_rcu(&ctx->users))
>   			ret = ctx;
>   	}
>   out:


Hi,
gentle reminder.

Is this patch useful?
When I first posted it, percpu_ref_tryget_live_rcu() was really new.
Now it is part of linux since 5.16.

Saving a few cycles in a function with "lookup" in its name looks always 
good to me.

CJ
Jeff Moyer Aug. 15, 2022, 6:10 p.m. UTC | #2
Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes:

> Le 03/11/2021 à 22:31, Christophe JAILLET a écrit :
>> Use 'percpu_ref_tryget_live_rcu()' instead of 'percpu_ref_tryget_live()' to
>> save a few cycles when it is known that the rcu lock is already
>> taken/released.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   fs/aio.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/aio.c b/fs/aio.c
>> index 9c81cf611d65..d189ea13e10a 100644
>> --- a/fs/aio.c
>> +++ b/fs/aio.c
>> @@ -1062,7 +1062,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
>>   	id = array_index_nospec(id, table->nr);
>>   	ctx = rcu_dereference(table->table[id]);
>>   	if (ctx && ctx->user_id == ctx_id) {
>> -		if (percpu_ref_tryget_live(&ctx->users))
>> +		if (percpu_ref_tryget_live_rcu(&ctx->users))
>>   			ret = ctx;
>>   	}
>>   out:
>
>
> Hi,
> gentle reminder.
>
> Is this patch useful?
> When I first posted it, percpu_ref_tryget_live_rcu() was really new.
> Now it is part of linux since 5.16.
>
> Saving a few cycles in a function with "lookup" in its name looks
> always good to me.

The patch looks fine to me.

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
diff mbox series

Patch

diff --git a/fs/aio.c b/fs/aio.c
index 9c81cf611d65..d189ea13e10a 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1062,7 +1062,7 @@  static struct kioctx *lookup_ioctx(unsigned long ctx_id)
 	id = array_index_nospec(id, table->nr);
 	ctx = rcu_dereference(table->table[id]);
 	if (ctx && ctx->user_id == ctx_id) {
-		if (percpu_ref_tryget_live(&ctx->users))
+		if (percpu_ref_tryget_live_rcu(&ctx->users))
 			ret = ctx;
 	}
 out: