Skip to contentSkip to conversation

rcu: Replace kfree() with kvfree() as callback for kfree_rcu()

PATCH New Kirill Tkhai 1 participant 1 message Feb 13, 2020 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu: Replace kfree() with kvfree() as callback for kfree_rcu()

Like Paul suggested, we start from simple replacing kfree() with kvfree() in kfree_rcu() callbacks:

https://www.spinics.net/lists/kernel/msg2729683.html

kvfree() works both with kmalloc()'ed and vmalloc()'ed memory, so we use it to free both of them via kfree_rcu().

---
 include/linux/rcupdate.h |    2 ++
 kernel/rcu/tiny.c        |    2 +-
 kernel/rcu/tree.c        |    2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
include/linux/rcupdate.h +2 -0
index 2678a37c3169..0a42c443c203 100644
@@ -842,6 +842,8 @@ do {									\
 		__kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
 } while (0)
 
+#define kvfree_rcu(ptr, rhf) kfree_rcu(ptr, rhf)
+
 /*
  * Place this after a lock-acquisition primitive to guarantee that
  * an UNLOCK+LOCK pair acts as a full barrier.  This guarantee applies
kernel/rcu/tiny.c +1 -1
index dd572ce7c747..16930c8f5749 100644
@@ -86,7 +86,7 @@ static inline bool rcu_reclaim_tiny(struct rcu_head *head)
 	rcu_lock_acquire(&rcu_callback_map);
 	if (__is_kfree_rcu_offset(offset)) {
 		trace_rcu_invoke_kfree_callback("", head, offset);
-		kfree((void *)head - offset);
+		kvfree((void *)head - offset);
 		rcu_lock_release(&rcu_callback_map);
 		return true;
 	}
kernel/rcu/tree.c +1 -1
index 16fd113796a7..cbe809bf6f4a 100644
@@ -2879,7 +2879,7 @@ static void kfree_rcu_work(struct work_struct *work)
 		trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset);
 
 		if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset)))
-			kfree((void *)head - offset);
+			kvfree((void *)head - offset);
 
 		rcu_lock_release(&rcu_callback_map);
 		cond_resched_tasks_rcu_qs();