staging: fwserial: Switch to kfree_rcu() API
PATCH v4 1/1 staging: fwserial: Switch to kfree_rcu() API
Instead of invoking a synchronize_rcu() to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.
---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: use kfree_rcu() instead of kvfree_rcu() for clarity
v4: resend v2 as v4 to avoid versioning confusion
--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/fwserial/fwserial.c +1 -2
@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kfree_rcu (peer); }/**
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 20 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/fwserial/fwserial.c +0
-0
drivers/staging/fwserial/fwserial.c static void fwserial_remove_peer(struct fwtty_peer *peer) · line 2120
Quoted 6 lines
drivers/staging/fwserial/fwserial.c +1
-2@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kfree_rcu (peer);
What is "more efficient" about this change?
And do you have the hardware for this device to test with? It would be good to finally get this out of staging, or to just remove it entirely if no one uses it.
thanks,
greg k-h
Quoted 24 lines · Greg KH
Quoted 23 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/fwserial/fwserial.c +0
-0@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true);
Quoted 3 lines
drivers/staging/fwserial/fwserial.c static void fwserial_remove_peer(struct fwtty_peer *peer) · line 2120
Quoted 3 lines
drivers/staging/fwserial/fwserial.c +1
-2-synchronize_rcu (); -kfree (peer); +kfree_rcu (peer);
The kfree_rcu(peer) should be kfree_rcu(peer, rcu), due to the rcu_head member named rcu in fwtty_peer.
This will be fixed in v5, sorry.
Quoted 1 line
What is "more efficient" about this change?
kfree_rcu() will call kvfree_call_rcu, due to the note in kernel/rcu/tree.c:
/Each kvfree_call_rcu() request is added to a batch. The batch will be drained every KFREE_DRAIN_JIFFIES number of jiffies. All the objects in the batch will be free'd in workqueue context. This allows us to: batch requests together to reduce the number of grace periods during heavy kfree_rcu()/kvfree_rcu() load. ///
which is the reason I use "more efficient".
Quoted 4 lines
And do you have the hardware for this device to test with? It would be good to finally get this out of staging, or to just remove it entirely if no one uses it.
Actually, not. I just found the code here may be optimized.
Quoted 4 lines
thanks,
greg k-h
Thanks,
Shang XiaoJing
Quoted 18 lines · shangxiaojing
Quoted 16 lines · Greg KH
Quoted 15 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 13 lines
Quoted 10 lines
drivers/staging/fwserial/fwserial.c static void fwserial_remove_peer(struct fwtty_peer *peer) · line 2119
Quoted 10 lines
drivers/staging/fwserial/fwserial.c +1
-2@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kfree_rcu (peer);The
kfree_rcu(peer)should bekfree_rcu(peer, rcu), due to thercu_headmember named rcu infwtty_peer.
Oh, huh. What happens if you don't pas the "rcu" parameter? I see there is a similar instance in ext4_apply_quota_options().
kfree_rcu(qname);
regards,
dan carpenter
Quoted 30 lines · Dan Carpenter
Quoted 17 lines · shangxiaojing
Quoted 16 lines · Greg KH
Quoted 15 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 12 lines
Quoted 10 lines
drivers/staging/fwserial/fwserial.c static void fwserial_remove_peer(struct fwtty_peer *peer) · line 2119
Quoted 10 lines
drivers/staging/fwserial/fwserial.c +1
-2@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kfree_rcu (peer);The
kfree_rcu(peer)should bekfree_rcu(peer, rcu), due to thercu_headmember named rcu infwtty_peer.
Quoted 4 lines
Oh, huh. What happens if you don't pas the "rcu" parameter? I see there is a similar instance in
ext4_apply_quota_options().kfree_rcu(qname);
We assume for the condition that CONFIG_KASAN_GENERIC does not defined and system has no pressure (bacause kvfree_call_rcu maintains 3 path):
The input parameter "head" of kvfree_call_rcu will be NULL if we don't pass the rcu, which will run like:
might_sleep(); synchronize_rcu(); kvfree((void *) func);
instead of:
if (head) { call_rcu(head, func); return;
}
where the difference is synchronize_rcu vs call_rcu.
call_rcu() will not block, having a wider range of use compared with synchronize_rcu().
Quoted 3 lines
regards,
dan carpenter
Thanks,
Shang XiaoJing
Quoted 30 lines · Dan Carpenter
Quoted 17 lines · shangxiaojing
Quoted 16 lines · Greg KH
Quoted 15 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion--- drivers/staging/fwserial/fwserial.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 12 lines
Quoted 10 lines
drivers/staging/fwserial/fwserial.c static void fwserial_remove_peer(struct fwtty_peer *peer) · line 2119
Quoted 10 lines
drivers/staging/fwserial/fwserial.c +1
-2@@ -2117,8 +2117,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kfree_rcu (peer);The
kfree_rcu(peer)should bekfree_rcu(peer, rcu), due to thercu_headmember named rcu infwtty_peer.
Quoted 4 lines
Oh, huh. What happens if you don't pas the "rcu" parameter? I see there is a similar instance in
ext4_apply_quota_options().kfree_rcu(qname);
In order to keep the code logic unchanged, "kfree_rcu(peer);" is better than "kfree_rcu(peer, rcu);"
I'm sorry for this repeated revision.
Thanks,
Shang XiaoJing
Quoted 11 lines · Shang XiaoJing
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period, we can directly make use of a new API that does the same but in a more efficient way.Signed-off-by Shang XiaoJing <[email protected]>---
Changelog:
v3: the first version of the PATCH
v1: v3 resent as v1
v2: usekfree_rcu()instead ofkvfree_rcu()for clarity
v4: resend v2 as v4 to avoid versioning confusion
LOL... I was still very confused about the versioning but I think the patch is correct now.
regards,
dan carpenter