Skip to contentSkip to conversation

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

PATCH Superseded Yunfeng Ye 1 participant 2 messages Nov 19, 2019 – Dec 17, 2019

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

PATCH v3 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.

---
v2 -> v3:
- move kfree() after wake_up(&async_done)

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

 kernel/async.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/async.c +4 -4
index 4f9c1d614016..d2ab75e8b1ab 100644
@@ -135,14 +135,14 @@ 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);
 
-	/* 4) wake up any waiters */
+	/* 3) wake up any waiters */
 	wake_up(&async_done);
+
+	/* 4) free the entry */
+	kfree(entry);
 }
 
 /**
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v3 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.

---
v2 -> v3:
- move kfree() after wake_up(&async_done)

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

 kernel/async.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/async.c +4 -4
index 4f9c1d614016..d2ab75e8b1ab 100644
@@ -135,14 +135,14 @@ 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);
 
-	/* 4) wake up any waiters */
+	/* 3) wake up any waiters */
 	wake_up(&async_done);
+
+	/* 4) free the entry */
+	kfree(entry);
 }
 
 /**
Signature · 1 line
2.7.4