All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] async: Let kfree() out of the critical area of the lock
@ 2019-09-25 12:52 Yunfeng Ye
  2019-09-25 13:38 ` gregkh
  2019-09-25 15:20 ` Alexander Duyck
  0 siblings, 2 replies; 8+ messages in thread
From: Yunfeng Ye @ 2019-09-25 12:52 UTC (permalink / raw)
  To: gregkh, bvanassche, bhelgaas, dsterba, tglx, alexander.h.duyck,
	sakari.ailus
  Cc: linux-kernel

It's not necessary to put kfree() in the critical area of the lock, so
let it out.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/async.c b/kernel/async.c
index 4f9c1d6..1de270d 100644
--- a/kernel/async.c
+++ b/kernel/async.c
@@ -135,12 +135,12 @@ static void async_run_entry_fn(struct work_struct *work)
 	list_del_init(&entry->domain_list);
 	list_del_init(&entry->global_list);

-	/* 3) free the entry */
-	kfree(entry);
 	atomic_dec(&entry_count);
-
 	spin_unlock_irqrestore(&async_lock, flags);

+	/* 3) free the entry */
+	kfree(entry);
+
 	/* 4) wake up any waiters */
 	wake_up(&async_done);
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-25 12:52 [PATCH] async: Let kfree() out of the critical area of the lock Yunfeng Ye
@ 2019-09-25 13:38 ` gregkh
  2019-09-25 13:45   ` Yunfeng Ye
  2019-09-25 15:20 ` Alexander Duyck
  1 sibling, 1 reply; 8+ messages in thread
From: gregkh @ 2019-09-25 13:38 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: bvanassche, bhelgaas, dsterba, tglx, alexander.h.duyck,
	sakari.ailus, linux-kernel

On Wed, Sep 25, 2019 at 08:52:26PM +0800, Yunfeng Ye wrote:
> It's not necessary to put kfree() in the critical area of the lock, so
> let it out.
> 
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  kernel/async.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/async.c b/kernel/async.c
> index 4f9c1d6..1de270d 100644
> --- a/kernel/async.c
> +++ b/kernel/async.c
> @@ -135,12 +135,12 @@ static void async_run_entry_fn(struct work_struct *work)
>  	list_del_init(&entry->domain_list);
>  	list_del_init(&entry->global_list);
> 
> -	/* 3) free the entry */
> -	kfree(entry);
>  	atomic_dec(&entry_count);
> -
>  	spin_unlock_irqrestore(&async_lock, flags);
> 
> +	/* 3) free the entry */
> +	kfree(entry);
> +
>  	/* 4) wake up any waiters */
>  	wake_up(&async_done);
>  }
> -- 
> 2.7.4
> 

Does this result any any measurable performance changes?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-25 13:38 ` gregkh
@ 2019-09-25 13:45   ` Yunfeng Ye
  0 siblings, 0 replies; 8+ messages in thread
From: Yunfeng Ye @ 2019-09-25 13:45 UTC (permalink / raw)
  To: gregkh
  Cc: bvanassche, bhelgaas, dsterba, tglx, alexander.h.duyck,
	sakari.ailus, linux-kernel



On 2019/9/25 21:38, gregkh@linuxfoundation.org wrote:
> On Wed, Sep 25, 2019 at 08:52:26PM +0800, Yunfeng Ye wrote:
>> It's not necessary to put kfree() in the critical area of the lock, so
>> let it out.
>>
>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>> ---
>>  kernel/async.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/async.c b/kernel/async.c
>> index 4f9c1d6..1de270d 100644
>> --- a/kernel/async.c
>> +++ b/kernel/async.c
>> @@ -135,12 +135,12 @@ static void async_run_entry_fn(struct work_struct *work)
>>  	list_del_init(&entry->domain_list);
>>  	list_del_init(&entry->global_list);
>>
>> -	/* 3) free the entry */
>> -	kfree(entry);
>>  	atomic_dec(&entry_count);
>> -
>>  	spin_unlock_irqrestore(&async_lock, flags);
>>
>> +	/* 3) free the entry */
>> +	kfree(entry);
>> +
>>  	/* 4) wake up any waiters */
>>  	wake_up(&async_done);
>>  }
>> -- 
>> 2.7.4
>>
> 
> Does this result any any measurable performance changes?
> 
No performance has been Measured at present, I just want the critical area
to be as short as possible. I think it's good to put it outside.

thanks

> thanks,
> 
> greg k-h
> 
> .
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-25 12:52 [PATCH] async: Let kfree() out of the critical area of the lock Yunfeng Ye
  2019-09-25 13:38 ` gregkh
@ 2019-09-25 15:20 ` Alexander Duyck
  2019-09-26  7:58   ` Yunfeng Ye
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Duyck @ 2019-09-25 15:20 UTC (permalink / raw)
  To: Yunfeng Ye, gregkh, bvanassche, bhelgaas, dsterba, tglx, sakari.ailus
  Cc: linux-kernel

On Wed, 2019-09-25 at 20:52 +0800, Yunfeng Ye wrote:
> It's not necessary to put kfree() in the critical area of the lock, so
> let it out.
> 
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  kernel/async.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/async.c b/kernel/async.c
> index 4f9c1d6..1de270d 100644
> --- a/kernel/async.c
> +++ b/kernel/async.c
> @@ -135,12 +135,12 @@ static void async_run_entry_fn(struct work_struct *work)
>  	list_del_init(&entry->domain_list);
>  	list_del_init(&entry->global_list);
> 
> -	/* 3) free the entry */
> -	kfree(entry);
>  	atomic_dec(&entry_count);
> -
>  	spin_unlock_irqrestore(&async_lock, flags);
> 
> +	/* 3) free the entry */
> +	kfree(entry);
> +
>  	/* 4) wake up any waiters */
>  	wake_up(&async_done);
>  }

It probably wouldn't hurt to update the patch description to mention that
async_schedule_node_domain does the allocation outside of the lock, then
takes the lock and does the list addition and entry_count increment inside
the critical section so this is just updating the code to match that it
seems.

Otherwise the change itself looks safe to me, though I am not sure there
is a performance gain to be had so this is mostly just a cosmetic patch.

Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-25 15:20 ` Alexander Duyck
@ 2019-09-26  7:58   ` Yunfeng Ye
  2019-09-26 11:06     ` David Sterba
  0 siblings, 1 reply; 8+ messages in thread
From: Yunfeng Ye @ 2019-09-26  7:58 UTC (permalink / raw)
  To: Alexander Duyck, gregkh, bvanassche, bhelgaas, dsterba, tglx,
	sakari.ailus
  Cc: linux-kernel



On 2019/9/25 23:20, Alexander Duyck wrote:
> On Wed, 2019-09-25 at 20:52 +0800, Yunfeng Ye wrote:
>> It's not necessary to put kfree() in the critical area of the lock, so
>> let it out.
>>
>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>> ---
>>  kernel/async.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/async.c b/kernel/async.c
>> index 4f9c1d6..1de270d 100644
>> --- a/kernel/async.c
>> +++ b/kernel/async.c
>> @@ -135,12 +135,12 @@ static void async_run_entry_fn(struct work_struct *work)
>>  	list_del_init(&entry->domain_list);
>>  	list_del_init(&entry->global_list);
>>
>> -	/* 3) free the entry */
>> -	kfree(entry);
>>  	atomic_dec(&entry_count);
>> -
>>  	spin_unlock_irqrestore(&async_lock, flags);
>>
>> +	/* 3) free the entry */
>> +	kfree(entry);
>> +
>>  	/* 4) wake up any waiters */
>>  	wake_up(&async_done);
>>  }
> 
> It probably wouldn't hurt to update the patch description to mention that
> async_schedule_node_domain does the allocation outside of the lock, then
> takes the lock and does the list addition and entry_count increment inside
> the critical section so this is just updating the code to match that it
> seems.
> 
> Otherwise the change itself looks safe to me, though I am not sure there
> is a performance gain to be had so this is mostly just a cosmetic patch.
> 
The async_lock is big global lock, I think it's good to put kfree() outside
to keep the critical area as short as possible.

thanks.

> Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
> 
> 
> .
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-26  7:58   ` Yunfeng Ye
@ 2019-09-26 11:06     ` David Sterba
  2019-09-26 15:18       ` Bart Van Assche
  0 siblings, 1 reply; 8+ messages in thread
From: David Sterba @ 2019-09-26 11:06 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: bvanassche, bhelgaas, tglx, Alexander Duyck, sakari.ailus,
	gregkh, David Sterba, linux-kernel

On Thu, Sep 26, 2019 at 03:58:36PM +0800, Yunfeng Ye wrote:
> On 2019/9/25 23:20, Alexander Duyck wrote:
> > On Wed, 2019-09-25 at 20:52 +0800, Yunfeng Ye wrote:
> > It probably wouldn't hurt to update the patch description to mention that
> > async_schedule_node_domain does the allocation outside of the lock, then
> > takes the lock and does the list addition and entry_count increment inside
> > the critical section so this is just updating the code to match that it
> > seems.
> > 
> > Otherwise the change itself looks safe to me, though I am not sure there
> > is a performance gain to be had so this is mostly just a cosmetic patch.
> > 
> The async_lock is big global lock, I think it's good to put kfree() outside
> to keep the critical area as short as possible.

Agreed, kfree is not always cheap. We had patches in btrfs moving kfree
out of critical section(s) after causing softlockups due to increased lock
contention.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-26 11:06     ` David Sterba
@ 2019-09-26 15:18       ` Bart Van Assche
  2019-09-27  1:00         ` Yunfeng Ye
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2019-09-26 15:18 UTC (permalink / raw)
  To: dsterba, Yunfeng Ye, bhelgaas, tglx, Alexander Duyck,
	sakari.ailus, gregkh, David Sterba, linux-kernel

On 9/26/19 4:06 AM, David Sterba wrote:
> On Thu, Sep 26, 2019 at 03:58:36PM +0800, Yunfeng Ye wrote:
>> The async_lock is big global lock, I think it's good to put kfree() outside
>> to keep the critical area as short as possible.
> 
> Agreed, kfree is not always cheap. We had patches in btrfs moving kfree
> out of critical section(s) after causing softlockups due to increased lock
> contention.

The above would be a great addition for the commit description. Anyway:

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] async: Let kfree() out of the critical area of the lock
  2019-09-26 15:18       ` Bart Van Assche
@ 2019-09-27  1:00         ` Yunfeng Ye
  0 siblings, 0 replies; 8+ messages in thread
From: Yunfeng Ye @ 2019-09-27  1:00 UTC (permalink / raw)
  To: Bart Van Assche, dsterba, bhelgaas, tglx, Alexander Duyck,
	sakari.ailus, gregkh, David Sterba, linux-kernel



On 2019/9/26 23:18, Bart Van Assche wrote:
> On 9/26/19 4:06 AM, David Sterba wrote:
>> On Thu, Sep 26, 2019 at 03:58:36PM +0800, Yunfeng Ye wrote:
>>> The async_lock is big global lock, I think it's good to put kfree() outside
>>> to keep the critical area as short as possible.
>>
>> Agreed, kfree is not always cheap. We had patches in btrfs moving kfree
>> out of critical section(s) after causing softlockups due to increased lock
>> contention.
> 
> The above would be a great addition for the commit description. Anyway:
> 
ok, I will update the description, thanks.

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-09-27  1:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 12:52 [PATCH] async: Let kfree() out of the critical area of the lock Yunfeng Ye
2019-09-25 13:38 ` gregkh
2019-09-25 13:45   ` Yunfeng Ye
2019-09-25 15:20 ` Alexander Duyck
2019-09-26  7:58   ` Yunfeng Ye
2019-09-26 11:06     ` David Sterba
2019-09-26 15:18       ` Bart Van Assche
2019-09-27  1:00         ` Yunfeng Ye

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.