Couple of minor improvements to build_skb variants
Subsystems (2)
cover Couple of minor improvements to build_skb variants
First patch replaces open-coded occurrences of skb_propagate_pfmemalloc() in build_skb() and build_skb_around(). The secnod patch adds a likely() to the skb allocation in build_skb().
Thanks
Gal Pressman (2):
skbuff: Replace open-coded skb_propagate_pfmemalloc()s
skbuff: Add likely to skb pointer in build_skb()
net/core/skbuff.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/2 skbuff: Replace open-coded skb_propagate_pfmemalloc()s
Use skb_propagate_pfmemalloc() in build_skb()/build_skb_around() instead of open-coding it.
--- net/core/skbuff.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/skbuff.c +2 -4
@@ -422,8 +422,7 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)if (skb && frag_size) { skb->head_frag =1 ; -if (page_is_pfmemalloc (virt_to_head_page (data))) - skb->pfmemalloc =1 ; +skb_propagate_pfmemalloc (virt_to_head_page (data), skb); }return skb; }
@@ -445,8 +444,7 @@ struct sk_buff *build_skb_around(struct sk_buff *skb,if (frag_size) { skb->head_frag =1 ; -if (page_is_pfmemalloc (virt_to_head_page (data))) - skb->pfmemalloc =1 ; +skb_propagate_pfmemalloc (virt_to_head_page (data), skb); }return skb; }
Signature · 1 line
2.39.0
PATCH 2/2 skbuff: Add likely to skb pointer in build_skb()
In reply to Gal PressmanSimilarly to napi_build_skb(), it is likely the skb allocation in build_skb() succeeded.
--- net/core/skbuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
@@ -420,7 +420,7 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) {struct sk_buff *skb =__build_skb (data, frag_size); -if (skb && frag_size) { +if (likely (skb) && frag_size) { skb->head_frag =1 ;skb_propagate_pfmemalloc (virt_to_head_page (data), skb); }
Signature · 1 line
2.39.0
Quoted 4 lines · Gal Pressman
First patch replaces open-coded occurrences of
skb_propagate_pfmemalloc()inbuild_skb()andbuild_skb_around(). The secnod patch adds alikely()to the skb allocation inbuild_skb().
Quoted 9 lines
Thanks
Gal Pressman (2):
skbuff: Replace open-coded skb_propagate_pfmemalloc()s
skbuff: Add likely to skb pointer inbuild_skb()net/core/skbuff.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 3 lines
Signature · 1 line
2.39.0
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()
In reply to Gal Pressmannet/core/skbuff.c struct sk_buff *build_skb(void *data, unsigned int frag_size) · line 423
Quoted 2 lines · On Wed, 15 Feb 2023 14:17:07 +0200 Gal Pressman wrote:
net/core/skbuff.c +1
-1-if (skb && frag_size) { +if (likely (skb) && frag_size) {
Should frag_size also be inside the likely?
See the warning in __build_skb_around().
Paolo Abeni
maintainerRe: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()
In reply to Gal PressmanQuoted 14 lines · Gal Pressman
Similarly to
napi_build_skb(), it is likely the skb allocation inbuild_skb()succeeded.Reviewed-by Tariq Toukan <[email protected]>Signed-off-by Gal Pressman <[email protected]>--- net/core/skbuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/skbuff.c +0
-0
net/core/skbuff.c struct sk_buff *build_skb(void *data, unsigned int frag_size) · line 423
Quoted 5 lines
net/core/skbuff.c +1
-1@@ -420,7 +420,7 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) {struct sk_buff *skb =__build_skb (data, frag_size); -if (skb && frag_size) { +if (likely (skb) && frag_size) {
I concur with Jakub: frag_size != 0 is a likely event. Additionally, without including 'frag_size' into the likely() annotation the compiler could consider the whole branch not likely: I think should be:
if (likely(skb && frag_size)) {Cheers,
Paolo
Re: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()
In reply to Jakub KicinskiQuoted 6 lines · Jakub Kicinski
net/core/skbuff.c struct sk_buff *build_skb(void *data, unsigned int frag_size) · line 423
Quoted 2 lines · On Wed, 15 Feb 2023 14:17:07 +0200 Gal Pressman wrote:
net/core/skbuff.c +1
-1-if (skb && frag_size) { +if (likely (skb) && frag_size) {Should
frag_sizealso be inside the likely?
See the warning in__build_skb_around().
Agree, thanks Jakub and Paolo.
Do you want to fix it up when you take the patch, or should I submit a v2?
Paolo Abeni
maintainerRe: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()
Quoted 11 lines · Gal Pressman
Quoted 6 lines · Jakub Kicinski
net/core/skbuff.c struct sk_buff *build_skb(void *data, unsigned int frag_size) · line 423
Quoted 2 lines · On Wed, 15 Feb 2023 14:17:07 +0200 Gal Pressman wrote:
net/core/skbuff.c +1
-1-if (skb && frag_size) { +if (likely (skb) && frag_size) {Should
frag_sizealso be inside the likely?
See the warning in__build_skb_around().Agree, thanks Jakub and Paolo.
Do you want to fix it up when you take the patch, or should I submit a v2?
The way to address even such small changes is via re-submissions, please send a v2, thanks!
Paolo