diff mbox series

[net-next,v9,09/13] net: introduce the skb_copy_to_va_nocache() helper

Message ID 20240625135216.47007-10-linyunsheng@huawei.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series First try to replace page_frag with page_frag_cache | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 863 this patch: 863
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 890 this patch: 890
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3486 this patch: 3486
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 4 this patch: 4
netdev/source_inline success Was 0 now: 0

Commit Message

Yunsheng Lin June 25, 2024, 1:52 p.m. UTC
introduce the skb_copy_to_va_nocache() helper to avoid
calling virt_to_page() and skb_copy_to_page_nocache().

CC: Alexander Duyck <alexander.duyck@gmail.com>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
 include/net/sock.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Alexander Duyck July 2, 2024, 3:52 p.m. UTC | #1
On Tue, 2024-06-25 at 21:52 +0800, Yunsheng Lin wrote:
> introduce the skb_copy_to_va_nocache() helper to avoid
> calling virt_to_page() and skb_copy_to_page_nocache().
> 
> CC: Alexander Duyck <alexander.duyck@gmail.com>
> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> ---
>  include/net/sock.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/include/net/sock.h b/include/net/sock.h
> index cce23ac4d514..7ad235465485 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2201,6 +2201,21 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
>  	return 0;
>  }
>  
> +static inline int skb_copy_to_va_nocache(struct sock *sk, struct iov_iter *from,
> +					 struct sk_buff *skb, char *va, int copy)
> +{
> +	int err;
> +
> +	err = skb_do_copy_data_nocache(sk, skb, from, va, copy, skb->len);
> +	if (err)
> +		return err;
> +
> +	skb_len_add(skb, copy);
> +	sk_wmem_queued_add(sk, copy);
> +	sk_mem_charge(sk, copy);
> +	return 0;
> +}
> +
>  /**
>   * sk_wmem_alloc_get - returns write allocations
>   * @sk: socket

One minor nit. Rather than duplicate skb_copy_to_page_nocache you would
be better served to implement this one before it, and then just update
skb_copy_to_page_nocache to be:
	return skb_copy_to_va_nocache(sk, from, skb,
				      page_address(page) + off, copy);

We can save ourselves at least a few lines of code that way and it
creates one spot to do any changes.
Yunsheng Lin July 3, 2024, 12:36 p.m. UTC | #2
On 2024/7/2 23:52, Alexander H Duyck wrote:
> On Tue, 2024-06-25 at 21:52 +0800, Yunsheng Lin wrote:
>> introduce the skb_copy_to_va_nocache() helper to avoid
>> calling virt_to_page() and skb_copy_to_page_nocache().
>>
>> CC: Alexander Duyck <alexander.duyck@gmail.com>
>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>> ---
>>  include/net/sock.h | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/include/net/sock.h b/include/net/sock.h
>> index cce23ac4d514..7ad235465485 100644
>> --- a/include/net/sock.h
>> +++ b/include/net/sock.h
>> @@ -2201,6 +2201,21 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
>>  	return 0;
>>  }
>>  
>> +static inline int skb_copy_to_va_nocache(struct sock *sk, struct iov_iter *from,
>> +					 struct sk_buff *skb, char *va, int copy)
>> +{
>> +	int err;
>> +
>> +	err = skb_do_copy_data_nocache(sk, skb, from, va, copy, skb->len);
>> +	if (err)
>> +		return err;
>> +
>> +	skb_len_add(skb, copy);
>> +	sk_wmem_queued_add(sk, copy);
>> +	sk_mem_charge(sk, copy);
>> +	return 0;
>> +}
>> +
>>  /**
>>   * sk_wmem_alloc_get - returns write allocations
>>   * @sk: socket
> 
> One minor nit. Rather than duplicate skb_copy_to_page_nocache you would
> be better served to implement this one before it, and then just update
> skb_copy_to_page_nocache to be:
> 	return skb_copy_to_va_nocache(sk, from, skb,
> 				      page_address(page) + off, copy);
> 
> We can save ourselves at least a few lines of code that way and it
> creates one spot to do any changes.

Looking at more closely, it seems we may be able to just rename
skb_copy_to_page_nocache() to skb_copy_to_va_nocache() as there
is no caller for skb_copy_to_page_nocache() after this patchset.

> 				
> .
>
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index cce23ac4d514..7ad235465485 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2201,6 +2201,21 @@  static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
 	return 0;
 }
 
+static inline int skb_copy_to_va_nocache(struct sock *sk, struct iov_iter *from,
+					 struct sk_buff *skb, char *va, int copy)
+{
+	int err;
+
+	err = skb_do_copy_data_nocache(sk, skb, from, va, copy, skb->len);
+	if (err)
+		return err;
+
+	skb_len_add(skb, copy);
+	sk_wmem_queued_add(sk, copy);
+	sk_mem_charge(sk, copy);
+	return 0;
+}
+
 /**
  * sk_wmem_alloc_get - returns write allocations
  * @sk: socket