mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: Paolo Abeni <pabeni@redhat.com>, <davem@davemloft.net>,
	<kuba@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Alexander Duyck <alexander.duyck@gmail.com>,
	Ayush Sawal <ayush.sawal@chelsio.com>,
	Eric Dumazet <edumazet@google.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Jason Wang <jasowang@redhat.com>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Jakub Sitnicki <jakub@cloudflare.com>,
	David Ahern <dsahern@kernel.org>,
	Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>,
	Geliang Tang <geliang@kernel.org>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>, Boris Pismenny <borisp@nvidia.com>,
	<bpf@vger.kernel.org>, <mptcp@lists.linux.dev>
Subject: Re: [PATCH net-next v18 12/14] net: replace page_frag with page_frag_cache
Date: Wed, 11 Sep 2024 19:31:16 +0800	[thread overview]
Message-ID: <15d963c2-1854-4fb7-a7a4-d8ed8cafead3@huawei.com> (raw)
In-Reply-To: <1884e171-cc87-4238-abd1-0f6be1e0b279@redhat.com>

On 2024/9/10 22:04, Paolo Abeni wrote:
> On 9/6/24 09:36, Yunsheng Lin wrote:
>> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
>> index 49811c9281d4..6190d9bfd618 100644
>> --- a/net/ipv4/ip_output.c
>> +++ b/net/ipv4/ip_output.c
>> @@ -953,7 +953,7 @@ static int __ip_append_data(struct sock *sk,
>>                   struct flowi4 *fl4,
>>                   struct sk_buff_head *queue,
>>                   struct inet_cork *cork,
>> -                struct page_frag *pfrag,
>> +                struct page_frag_cache *nc,
>>                   int getfrag(void *from, char *to, int offset,
>>                       int len, int odd, struct sk_buff *skb),
>>                   void *from, int length, int transhdrlen,
>> @@ -1228,13 +1228,19 @@ static int __ip_append_data(struct sock *sk,
>>               copy = err;
>>               wmem_alloc_delta += copy;
>>           } else if (!zc) {
>> +            struct page_frag page_frag, *pfrag;
>>               int i = skb_shinfo(skb)->nr_frags;
>> +            void *va;
>>                 err = -ENOMEM;
>> -            if (!sk_page_frag_refill(sk, pfrag))
>> +            pfrag = &page_frag;
>> +            va = sk_page_frag_alloc_refill_prepare(sk, nc, pfrag);
>> +            if (!va)
>>                   goto error;
>>                 skb_zcopy_downgrade_managed(skb);
>> +            copy = min_t(int, copy, pfrag->size);
>> +
>>               if (!skb_can_coalesce(skb, i, pfrag->page,
>>                             pfrag->offset)) {
>>                   err = -EMSGSIZE;
>> @@ -1242,18 +1248,18 @@ static int __ip_append_data(struct sock *sk,
>>                       goto error;
>>                     __skb_fill_page_desc(skb, i, pfrag->page,
>> -                             pfrag->offset, 0);
>> +                             pfrag->offset, copy);
>>                   skb_shinfo(skb)->nr_frags = ++i;
>> -                get_page(pfrag->page);
>> +                page_frag_commit(nc, pfrag, copy);
>> +            } else {
>> +                skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1],
>> +                          copy);
>> +                page_frag_commit_noref(nc, pfrag, copy);
>>               }
>> -            copy = min_t(int, copy, pfrag->size - pfrag->offset);
>> -            if (getfrag(from,
>> -                    page_address(pfrag->page) + pfrag->offset,
>> -                    offset, copy, skb->len, skb) < 0)
>> +
>> +            if (getfrag(from, va, offset, copy, skb->len, skb) < 0)
>>                   goto error_efault;
> 
> Should the 'commit' happen only when 'getfrag' is successful?
> 
> Similar question in the ipv6 code.

Good question.
First of all, even it fails, the 'goto' will handle it correctly as the
skb_shinfo(skb)->nr_frags is setup correctly.
And then 'getfrag' being failure is an unlikely case, right?

I thought about moving it when coding, but decided not to mainly get_page()
is also called before 'getfrag' as above, and I guess 'getfrag' might
involve memcpy'ing causing the cache eviction for the above data, so it
might make sense to do the likely case before 'getfrag'.

> 
> Thanks,
> 
> Paolo
> 
> 

  reply	other threads:[~2024-09-11 11:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06  7:36 [PATCH net-next v18 00/14] Replace page_frag with page_frag_cache for sk_page_frag() Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 01/14] mm: page_frag: add a test module for page_frag Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 02/14] mm: move the page fragment allocator from page_alloc into its own file Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 05/14] xtensa: remove the get_order() implementation Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 06/14] mm: page_frag: reuse existing space for 'size' and 'pfmemalloc' Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 07/14] mm: page_frag: some minor refactoring before adding new API Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 08/14] mm: page_frag: use __alloc_pages() to replace alloc_pages_node() Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 09/14] net: rename skb_copy_to_page_nocache() helper Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 10/14] mm: page_frag: introduce prepare/probe/commit API Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 11/14] mm: page_frag: add testing for the newly added prepare API Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 12/14] net: replace page_frag with page_frag_cache Yunsheng Lin
2024-09-10 14:04   ` Paolo Abeni
2024-09-11 11:31     ` Yunsheng Lin [this message]
2024-09-06  7:36 ` [PATCH net-next v18 13/14] mm: page_frag: update documentation for page_frag Yunsheng Lin
2024-09-06  7:36 ` [PATCH net-next v18 14/14] mm: page_frag: add an entry in MAINTAINERS " Yunsheng Lin
2024-09-10 15:11 ` [PATCH net-next v18 00/14] Replace page_frag with page_frag_cache for sk_page_frag() Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15d963c2-1854-4fb7-a7a4-d8ed8cafead3@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=alexander.duyck@gmail.com \
    --cc=ayush.sawal@chelsio.com \
    --cc=borisp@nvidia.com \
    --cc=bpf@vger.kernel.org \
    --cc=bsegall@google.com \
    --cc=davem@davemloft.net \
    --cc=dietmar.eggemann@arm.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=geliang@kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=jasowang@redhat.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=juri.lelli@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®