Skip to contentSkip to conversation

Couple of minor improvements to build_skb variants

PATCH Superseded Gal Pressman 4 participants 8 messages Feb 15, 2023 – Feb 16, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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
index 13ea10cf8544..069604b9ff9d 100644
@@ -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
#2 lore raw

PATCH 2/2 skbuff: Add likely to skb pointer in build_skb()

In reply to Gal Pressman

Similarly 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
index 069604b9ff9d..3aa9687d7546 100644
@@ -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
maintainer
#3 lore raw

Re: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()

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_size also be inside the likely?
See the warning in __build_skb_around().

#4 lore raw

Re: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()

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_size also 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?

maintainer
#5 lore raw

Re: [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_size also 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

maintainer
#6 lore raw

Re: [PATCH net-next 2/2] skbuff: Add likely to skb pointer in build_skb()

In reply to Gal Pressman
Quoted 14 lines · Gal Pressman

Similarly 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 +0 -0
index 069604b9ff9d..3aa9687d7546 100644

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

Reviewed-by on the v1 series
#7 lore raw
In reply to Gal Pressman
Quoted 4 lines · Gal Pressman

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().

Quoted 9 lines

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(-)
Quoted 3 lines
Signature · 1 line
2.39.0