linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] skbuff: Add helper function for head_frag and pfmemalloc
@ 2021-11-15  8:57 Yajun Deng
  2021-11-15 12:27 ` Alexander Lobakin
  0 siblings, 1 reply; 2+ messages in thread
From: Yajun Deng @ 2021-11-15  8:57 UTC (permalink / raw)
  To: davem, kuba; +Cc: linux-kernel, netdev, Yajun Deng

This series of build_skb() has the same code, add skb_set_head_frag_pfmemalloc()
for it, at the same time, in-line skb_propagate_pfmemalloc().

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 include/linux/skbuff.h | 19 ++++++++++++-------
 net/core/skbuff.c      | 19 +++++--------------
 2 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 0bd6520329f6..3e26b80bde29 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3007,15 +3007,20 @@ static inline bool dev_page_is_reusable(const struct page *page)
 }
 
 /**
- *	skb_propagate_pfmemalloc - Propagate pfmemalloc if skb is allocated after RX page
- *	@page: The page that was allocated from skb_alloc_page
- *	@skb: The skb that may need pfmemalloc set
+ *	skb_set_head_frag_pfmemalloc - Set head_frag and pfmemalloc
+ *	@skb: The skb that may need head_frag and pfmemalloc set
+ *      @data: data buffer provided by caller
+ *      @frag_size: size of data, or 0 if head was kmalloced
  */
-static inline void skb_propagate_pfmemalloc(const struct page *page,
-					    struct sk_buff *skb)
+static inline void skb_set_head_frag_pfmemalloc(struct sk_buff *skb, void *data,
+						unsigned int frag_size)
 {
-	if (page_is_pfmemalloc(page))
-		skb->pfmemalloc = true;
+
+	if (likely(skb) && frag_size) {
+		skb->head_frag = 1;
+		if (page_is_pfmemalloc(virt_to_head_page(data)))
+			skb->pfmemalloc = 1;
+	}
 }
 
 /**
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 67a9188d8a49..7b3d2bf746ae 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -255,11 +255,8 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
 {
 	struct sk_buff *skb = __build_skb(data, frag_size);
 
-	if (skb && frag_size) {
-		skb->head_frag = 1;
-		if (page_is_pfmemalloc(virt_to_head_page(data)))
-			skb->pfmemalloc = 1;
-	}
+	skb_set_head_frag_pfmemalloc(skb, data, frag_size);
+
 	return skb;
 }
 EXPORT_SYMBOL(build_skb);
@@ -278,11 +275,8 @@ struct sk_buff *build_skb_around(struct sk_buff *skb,
 
 	__build_skb_around(skb, data, frag_size);
 
-	if (frag_size) {
-		skb->head_frag = 1;
-		if (page_is_pfmemalloc(virt_to_head_page(data)))
-			skb->pfmemalloc = 1;
-	}
+	skb_set_head_frag_pfmemalloc(skb, data, frag_size);
+
 	return skb;
 }
 EXPORT_SYMBOL(build_skb_around);
@@ -325,10 +319,7 @@ struct sk_buff *napi_build_skb(void *data, unsigned int frag_size)
 {
 	struct sk_buff *skb = __napi_build_skb(data, frag_size);
 
-	if (likely(skb) && frag_size) {
-		skb->head_frag = 1;
-		skb_propagate_pfmemalloc(virt_to_head_page(data), skb);
-	}
+	skb_set_head_frag_pfmemalloc(skb, data, frag_size);
 
 	return skb;
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] skbuff: Add helper function for head_frag and pfmemalloc
  2021-11-15  8:57 [PATCH net-next] skbuff: Add helper function for head_frag and pfmemalloc Yajun Deng
@ 2021-11-15 12:27 ` Alexander Lobakin
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Lobakin @ 2021-11-15 12:27 UTC (permalink / raw)
  To: Yajun Deng; +Cc: Alexander Lobakin, davem, kuba, linux-kernel, netdev

From: Yajun Deng <yajun.deng@linux.dev>
Date: Mon, 15 Nov 2021 16:57:08 +0800

> This series of build_skb() has the same code, add skb_set_head_frag_pfmemalloc()
> for it, at the same time, in-line skb_propagate_pfmemalloc().
> 
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
> ---
>  include/linux/skbuff.h | 19 ++++++++++++-------
>  net/core/skbuff.c      | 19 +++++--------------
>  2 files changed, 17 insertions(+), 21 deletions(-)

build_skb(), build_skb_around() and napi_build_skb() are 3-liners,
and all of their code is here in linux/skbuff.h. Would it make
sense to make them static inlines, and export their "__"
counterparts instead?

Thanks,
Al

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-15 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  8:57 [PATCH net-next] skbuff: Add helper function for head_frag and pfmemalloc Yajun Deng
2021-11-15 12:27 ` Alexander Lobakin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).