From: Yunsheng Lin <linyunsheng@huawei.com>
To: Alexander H Duyck <alexander.duyck@gmail.com>,
<davem@davemloft.net>, <kuba@kernel.org>, <pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>, <linux-mm@kvack.org>
Subject: Re: [PATCH net-next v2 10/15] mm: page_frag: reuse existing bit field of 'va' for pagecnt_bias
Date: Wed, 17 Apr 2024 21:23:06 +0800 [thread overview]
Message-ID: <292c98e5-e58e-3474-f214-44fe6a83e6c5@huawei.com> (raw)
In-Reply-To: <68d1c7d3dfcd780fa3bed0bb71e41d7fb0a8c15d.camel@gmail.com>
On 2024/4/17 0:33, Alexander H Duyck wrote:
> On Mon, 2024-04-15 at 21:19 +0800, Yunsheng Lin wrote:
>> As alignment of 'va' is always aligned with the order of the
>> page allocated, we can reuse the LSB bits for the pagecount
>> bias, and remove the orginal space needed by 'pagecnt_bias'.
>> Also limit the 'fragsz' to be at least the size of
>> 'usigned int' to match the limited pagecnt_bias.
>>
>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>
> What is the point of this? You are trading off space for size on a data
> structure that is only something like 24B in size and only allocated a
> few times.
As we are going to replace page_frag with page_frag_cache in patch 13,
it is not going to only be allocated a few times as mentioned.
>
>> ---
>> include/linux/page_frag_cache.h | 20 +++++++----
>> mm/page_frag_cache.c | 63 +++++++++++++++++++--------------
>> 2 files changed, 50 insertions(+), 33 deletions(-)
>>
>> diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h
>> index 40a7d6da9ef0..a97a1ac017d6 100644
>> --- a/include/linux/page_frag_cache.h
>> +++ b/include/linux/page_frag_cache.h
>> @@ -9,7 +9,18 @@
>> #define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
>>
>> struct page_frag_cache {
>> - void *va;
>> + union {
>> + void *va;
>> + /* we maintain a pagecount bias, so that we dont dirty cache
>> + * line containing page->_refcount every time we allocate a
>> + * fragment. As 'va' is always aligned with the order of the
>> + * page allocated, we can reuse the LSB bits for the pagecount
>> + * bias, and its bit width happens to be indicated by the
>> + * 'size_mask' below.
>> + */
>> + unsigned long pagecnt_bias;
>> +
>> + };
>
> Both va and pagecnt_bias are frequently accessed items. If pagecnt_bias
> somehow ends up exceeding the alignment of the page we run the risk of
> corrupting data or creating an page fault.
>
> In my opinion this is not worth the risk especially since with the
> previous change your new change results in 0 size savings on 64b
> systems as the structure will be aligned to the size of the pointer.
But aren't we going to avoid a register usage and loading if reusing
the lower bits of 'va' for the 64b systems? And added benefit is the
memory saving for 32b systems as mentioned in previous patch.
>
>> #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
>> __u16 offset;
>> __u16 size_mask:15;
>> @@ -18,10 +29,6 @@ struct page_frag_cache {
>> __u32 offset:31;
>> __u32 pfmemalloc:1;
>> #endif
>> - /* we maintain a pagecount bias, so that we dont dirty cache line
>> - * containing page->_refcount every time we allocate a fragment.
>> - */
>> - unsigned int pagecnt_bias;
>> };
>>
>> static inline void page_frag_cache_init(struct page_frag_cache *nc)
>> @@ -56,7 +63,8 @@ static inline void *page_frag_alloc_va_align(struct page_frag_cache *nc,
>> gfp_t gfp_mask,
>> unsigned int align)
>> {
>> - WARN_ON_ONCE(!is_power_of_2(align) || align >= PAGE_SIZE);
>> + WARN_ON_ONCE(!is_power_of_2(align) || align >= PAGE_SIZE ||
>> + fragsz < sizeof(unsigned int));
>
> What is the reason for this change? Seems like it is to account for an
> issue somewhere.
If the fragsz is one, we might not have enough pagecnt_bias for it,
as we are using the lower bits of 'va' now.
>
>>
>> return __page_frag_alloc_va_align(nc, fragsz, gfp_mask, align);
next prev parent reply other threads:[~2024-04-17 13:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240415131941.51153-1-linyunsheng@huawei.com>
2024-04-15 13:19 ` [PATCH net-next v2 01/15] mm: page_frag: add a test module for page_frag Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 03/15] mm: page_frag: use free_unref_page() to free page fragment Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 04/15] mm: move the page fragment allocator from page_alloc into its own file Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 05/15] mm: page_frag: use initial zero offset for page_frag_alloc_align() Yunsheng Lin
2024-04-15 23:55 ` Alexander H Duyck
2024-04-16 13:11 ` Yunsheng Lin
2024-04-16 15:51 ` Alexander H Duyck
2024-04-17 13:17 ` Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 06/15] mm: page_frag: change page_frag_alloc_* API to accept align param Yunsheng Lin
2024-04-16 16:08 ` Alexander Duyck
2024-04-17 13:18 ` Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 07/15] mm: page_frag: add '_va' suffix to page_frag API Yunsheng Lin
2024-04-16 16:12 ` Alexander H Duyck
2024-04-17 13:18 ` Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 08/15] mm: page_frag: add two inline helper for " Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 09/15] mm: page_frag: reuse MSB of 'size' field for pfmemalloc Yunsheng Lin
2024-04-16 16:22 ` Alexander H Duyck
2024-04-17 13:19 ` Yunsheng Lin
2024-04-17 15:11 ` Alexander H Duyck
2024-04-18 9:39 ` Yunsheng Lin
2024-04-26 9:38 ` Yunsheng Lin
2024-04-29 14:49 ` Alexander Duyck
2024-04-30 12:05 ` Yunsheng Lin
2024-04-30 14:54 ` Alexander Duyck
2024-05-06 12:33 ` Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 10/15] mm: page_frag: reuse existing bit field of 'va' for pagecnt_bias Yunsheng Lin
2024-04-16 16:33 ` Alexander H Duyck
2024-04-17 13:23 ` Yunsheng Lin [this message]
2024-04-15 13:19 ` [PATCH net-next v2 12/15] mm: page_frag: introduce prepare/commit API for page_frag Yunsheng Lin
2024-04-15 13:19 ` [PATCH net-next v2 14/15] mm: page_frag: update documentation " Yunsheng Lin
2024-04-16 6:13 ` Bagas Sanjaya
2024-04-16 13:11 ` 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=292c98e5-e58e-3474-f214-44fe6a83e6c5@huawei.com \
--to=linyunsheng@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=davem@davemloft.net \
--cc=kuba@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).