Skip to contentSkip to conversation

async: Let kfree() out of the critical area of the lock

PATCH Superseded Yunfeng Ye 5 participants 8 messages Sep 25, 2019 – Sep 27, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

PATCH 1/1 async: Let kfree() out of the critical area of the lock

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

---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +3 -3
index 4f9c1d6..1de270d 100644
@@ -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);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 31 lines · Yunfeng Ye

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

---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +3 -3
index 4f9c1d6..1de270d 100644
@@ -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);
 }
Signature · 1 line
2.7.4

Does this result any any measurable performance changes?

thanks,

greg k-h

author
#2 lore raw
Quoted 23 lines · On 2019/9/25 21:38, [email protected] wrote:
Quoted 22 lines · Yunfeng Ye

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

---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +0 -3
index 4f9c1d6..1de270d 100644
@@ -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);
 
Quoted 12 lines
Quoted 9 lines
kernel/async.c +3 -0
+	/* 3) free the entry */
+	kfree(entry);
+
 	/* 4) wake up any waiters */
 	wake_up(&async_done);
 }
Signature · 1 line
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

Quoted 6 lines

thanks,

greg k-h

.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yunfeng Ye
Quoted 18 lines · Yunfeng Ye

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

---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +0 -2
index 4f9c1d6..1de270d 100644
@@ -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);

kernel/async.c static void async_run_entry_fn(struct work_struct *work) · line 146

Quoted 10 lines
kernel/async.c +3 -1
 	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.

author
#4 lore raw
Quoted 36 lines · Alexander Duyck
Quoted 18 lines · Yunfeng Ye

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

---
 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +0 -2
index 4f9c1d6..1de270d 100644
@@ -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);

kernel/async.c static void async_run_entry_fn(struct work_struct *work) · line 146

Quoted 10 lines
kernel/async.c +3 -1
 	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.

Quoted 3 lines

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.

Quoted 5 lines

.

#5 lore raw
Quoted 8 lines · Yunfeng Ye
Quoted 7 lines · Alexander Duyck

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.

Quoted 5 lines
Quoted 3 lines

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.

Reviewed-by
#6 lore raw
Quoted 7 lines · David Sterba
Quoted 2 lines · Yunfeng Ye

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:

author
#7 lore raw
Quoted 11 lines · Bart Van Assche
Quoted 7 lines · David Sterba
Quoted 2 lines · Yunfeng Ye

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.

Quoted 4 lines

.