Skip to contentSkip to conversation

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

PATCH Superseded Yunfeng Ye 2 participants 4 messages Sep 27, 2019 – Nov 19, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

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

The async_lock is big global lock, and kfree() is not always cheap, it will increase lock contention. it's better let kfree() outside the lock to keep the critical area as short as possible.

---
v1 -> v2:
- update the description
- add "Reviewed-by"

 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
author
#1 lore raw

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

The async_lock is big global lock, and kfree() is not always cheap, it will increase lock contention. it's better let kfree() outside the lock to keep the critical area as short as possible.

---
v1 -> v2:
- update the description
- add "Reviewed-by"

 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
#2 lore raw
Quoted 24 lines · Yunfeng Ye

The async_lock is big global lock, and kfree() is not always cheap, it will increase lock contention. it's better let kfree() outside the lock to keep the critical area as short as possible.

---
v1 -> v2:
- update the description
- add "Reviewed-by"

 kernel/async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/async.c +0 -1
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 */

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

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

The wakeup should happen before the kfree() for the very same reasons.

Thanks,

tglx

author
#3 lore raw
Quoted 33 lines · Thomas Gleixner
Quoted 29 lines · Yunfeng Ye

The async_lock is big global lock, and kfree() is not always cheap, it will increase lock contention. it's better let kfree() outside the lock to keep the critical area as short as possible.

---
v1 -> v2:
- update the description
- add "Reviewed-by"

 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 8 lines

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

Quoted 5 lines
kernel/async.c +3 -0
+	/* 3) free the entry */
+	kfree(entry);
+
 	/* 4) wake up any waiters */
 	wake_up(&async_done);

The wakeup should happen before the kfree() for the very same reasons.

ok, I will modify as your suggest, thanks.

Quoted 6 lines

Thanks,

tglx

.