From: Yunsheng Lin <linyunsheng@huawei.com>
To: Alexander Duyck <alexander.duyck@gmail.com>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <pabeni@redhat.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linux-MM <linux-mm@kvack.org>, Jonathan Corbet <corbet@lwn.net>,
<linux-doc@vger.kernel.org>
Subject: Re: [PATCH RFC 04/10] mm: page_frag: introduce page_frag_alloc_abort() related API
Date: Tue, 29 Oct 2024 17:39:58 +0800 [thread overview]
Message-ID: <f934af41-2902-429f-9b1b-2c469075fc23@huawei.com> (raw)
In-Reply-To: <CAKgT0UfouCZpX04yzvCrB_UBmy47p+=xm5qViYowerR9dPcCbg@mail.gmail.com>
On 2024/10/29 1:53, Alexander Duyck wrote:
> On Mon, Oct 28, 2024 at 5:05 AM Yunsheng Lin <linyunsheng@huawei.com> wrote:
>>
>> For some case as tun_build_skb() without the needing of
>> using complicated prepare & commit API, add the abort API to
>> abort the operation of page_frag_alloc_*() related API for
>> error handling knowing that no one else is taking extra
>> reference to the just allocated fragment, and add abort_ref
>> API to only abort the reference counting of the allocated
>> fragment if it is already referenced by someone else.
>>
...
>> +
>> +/**
>> + * page_frag_alloc_abort_ref - Abort the reference of allocated fragment.
>> + * @nc: page_frag cache to which the page fragment is aborted back
>> + * @va: virtual address of page fragment to be aborted
>> + * @fragsz: size of the page fragment to be aborted
>> + *
>> + * It is expected to be called from the same context as the allocation API.
>> + * Mostly used for error handling cases to abort the reference of allocated
>> + * fragment if the fragment has been referenced for other usages, to aovid the
>> + * atomic operation of page_frag_free() API.
>> + */
>> +void page_frag_alloc_abort_ref(struct page_frag_cache *nc, void *va,
>> + unsigned int fragsz)
>> +{
>> + VM_BUG_ON(va + fragsz !=
>> + encoded_page_decode_virt(nc->encoded_page) + nc->offset);
>> +
>> + nc->pagecnt_bias++;
>> +}
>> +EXPORT_SYMBOL(page_frag_alloc_abort_ref);
>
> It isn't clear to me why you split this over two functions. It seems
> like you could just update the offset in this lower function rather
> than do it in the upper one since you are passing all the arguments
> here anyway.
For the usecase in tun_build_skb(), There seems to be XDP_REDIRECT and
XDP_TX case that the allocated fragment has been referenced for other
usages even when xdp_do_redirect() or tun_xdp_tx() return error, so that
caller can call page_frag_alloc_abort_ref() to abort its reference
of the allocated fragment, but not abort the whole fragment for later
reuse.
As the doc mentioned above page_frag_alloc_abort_ref(), it is mainly to
avoid the atomic operation of page_frag_free() API when the caller has the
allocation context and has the all the arguments page_frag_alloc_abort_ref()
needs even though it might be a unlikely case if page_frag_alloc_abort() API
is already provided.
next prev parent reply other threads:[~2024-10-29 9:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241028115850.3409893-1-linyunsheng@huawei.com>
2024-10-28 11:58 ` [PATCH RFC 01/10] mm: page_frag: some minor refactoring before adding new API Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 02/10] net: rename skb_copy_to_page_nocache() helper Yunsheng Lin
2024-10-28 17:49 ` Alexander Duyck
2024-10-28 11:58 ` [PATCH RFC 03/10] mm: page_frag: update documentation for page_frag Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 04/10] mm: page_frag: introduce page_frag_alloc_abort() related API Yunsheng Lin
2024-10-28 17:53 ` Alexander Duyck
2024-10-29 9:39 ` Yunsheng Lin [this message]
2024-10-28 11:58 ` [PATCH RFC 05/10] mm: page_frag: introduce refill prepare & commit API Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 06/10] mm: page_frag: introduce alloc_refill " Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 07/10] mm: page_frag: introduce probe related API Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 08/10] mm: page_frag: add testing for the newly added API Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 09/10] net: replace page_frag with page_frag_cache Yunsheng Lin
2024-10-28 11:58 ` [PATCH RFC 10/10] mm: page_frag: add an entry in MAINTAINERS for page_frag Yunsheng Lin
2024-10-28 23:27 ` Jakub Kicinski
2024-10-29 9:40 ` Yunsheng Lin
2024-10-29 14:33 ` Jakub Kicinski
2024-10-30 11:32 ` Yunsheng Lin
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=f934af41-2902-429f-9b1b-2c469075fc23@huawei.com \
--to=linyunsheng@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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