mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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@kvack.org>
Subject: Re: [PATCH net-next v13 07/14] mm: page_frag: reuse existing space for 'size' and 'pfmemalloc'
Date: Fri, 16 Aug 2024 19:55:56 +0800	[thread overview]
Message-ID: <1a6aab37-2783-45a2-8edd-0990b211ac2d@huawei.com> (raw)
In-Reply-To: <CAKgT0UfUVJ6FmVgFWv+uCV9Q7eX8s+Mf6cPVCLyHwk5TxtuKgg@mail.gmail.com>

On 2024/8/15 23:03, Alexander Duyck wrote:
> On Wed, Aug 14, 2024 at 8:10 PM Yunsheng Lin <linyunsheng@huawei.com> wrote:
>>
>> On 2024/8/15 0:13, Alexander H Duyck wrote:
>>> On Thu, 2024-08-08 at 20:37 +0800, Yunsheng Lin wrote:
>>>> Currently there is one 'struct page_frag' for every 'struct
>>>> sock' and 'struct task_struct', we are about to replace the
>>>> 'struct page_frag' with 'struct page_frag_cache' for them.
>>>> Before begin the replacing, we need to ensure the size of
>>>> 'struct page_frag_cache' is not bigger than the size of
>>>> 'struct page_frag', as there may be tens of thousands of
>>>> 'struct sock' and 'struct task_struct' instances in the
>>>> system.
>>>>
>>>> By or'ing the page order & pfmemalloc with lower bits of
>>>> 'va' instead of using 'u16' or 'u32' for page size and 'u8'
>>>> for pfmemalloc, we are able to avoid 3 or 5 bytes space waste.
>>>> And page address & pfmemalloc & order is unchanged for the
>>>> same page in the same 'page_frag_cache' instance, it makes
>>>> sense to fit them together.
>>>>
>>>> After this patch, the size of 'struct page_frag_cache' should be
>>>> the same as the size of 'struct page_frag'.
>>>>
>>>> CC: Alexander Duyck <alexander.duyck@gmail.com>
>>>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>>>> ---
>>>>  include/linux/mm_types_task.h   | 16 +++++-----
>>>>  include/linux/page_frag_cache.h | 52 +++++++++++++++++++++++++++++++--
>>>>  mm/page_frag_cache.c            | 49 +++++++++++++++++--------------
>>>>  3 files changed, 85 insertions(+), 32 deletions(-)
>>>>
>>>> diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
>>>> index b1c54b2b9308..f2610112a642 100644
>>>> --- a/include/linux/mm_types_task.h
>>>> +++ b/include/linux/mm_types_task.h
>>>> @@ -50,18 +50,18 @@ struct page_frag {
>>>>  #define PAGE_FRAG_CACHE_MAX_SIZE    __ALIGN_MASK(32768, ~PAGE_MASK)
>>>>  #define PAGE_FRAG_CACHE_MAX_ORDER   get_order(PAGE_FRAG_CACHE_MAX_SIZE)
>>>>  struct page_frag_cache {
>>>> -    void *va;
>>>> -#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
>>>> +    /* encoded_va consists of the virtual address, pfmemalloc bit and order
>>>> +     * of a page.
>>>> +     */
>>>> +    unsigned long encoded_va;
>>>> +
>>>
>>> Rather than calling this an "encoded_va" we might want to call this an
>>> "encoded_page" as that would be closer to what we are actually working
>>> with. We are just using the virtual address as the page pointer instead
>>> of the page struct itself since we need quicker access to the virtual
>>> address than we do the page struct.
>>
>> Calling it "encoded_page" seems confusing enough when calling virt_to_page()
>> with "encoded_page" when virt_to_page() is expecting a 'va', no?
> 
> It makes about as much sense as calling it an "encoded_va". What you
> have is essentially a packed page struct that contains the virtual
> address, pfmemalloc flag, and order. So if you want you could call it
> "packed_page" too I suppose. Basically this isn't a valid virtual
> address it is a page pointer with some extra metadata packed in.

I think we are all argeed that is not a valid virtual address by adding
the 'encoded_' part.
I am not really sure if "encoded_page" or "packed_page" is better than
'encoded_va' here, as there is no 'page pointer' that is implied by
"encoded_page" or "packed_page" here. For 'encoded_va', at least there
is 'virtual address' that is implied by 'encoded_va', and that 'virtual
address' just happen to be page pointer.

Yes, you may say the 'pfmemalloc flag and order' part is about page, not
about 'va', I guess there is trade-off we need to make here if there is
not a perfect name for it and 'va' does occupy most bits of 'encoded_va'.

  reply	other threads:[~2024-08-16 11:55 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08 12:37 [PATCH net-next v13 00/14] Replace page_frag with page_frag_cache for sk_page_frag() Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 01/14] mm: page_frag: add a test module for page_frag Yunsheng Lin
2024-08-09 11:08   ` Muhammad Usama Anjum
2024-08-09 12:29     ` Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 02/14] mm: move the page fragment allocator from page_alloc into its own file Yunsheng Lin
2024-08-14 15:33   ` Alexander H Duyck
2024-08-14 20:22   ` Andrew Morton
2024-08-08 12:37 ` [PATCH net-next v13 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 04/14] mm: page_frag: add '_va' suffix to page_frag API Yunsheng Lin
2024-08-14 15:49   ` Alexander H Duyck
2024-08-15  2:59     ` Yunsheng Lin
2024-08-15 15:00       ` Alexander Duyck
2024-08-16 11:55         ` Yunsheng Lin
2024-08-19 15:54           ` Alexander Duyck
2024-08-20 13:07             ` Yunsheng Lin
2024-08-20 16:02               ` Alexander Duyck
2024-08-21 12:30                 ` Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 05/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 06/14] xtensa: remove the get_order() implementation Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 07/14] mm: page_frag: reuse existing space for 'size' and 'pfmemalloc' Yunsheng Lin
2024-08-14 16:13   ` Alexander H Duyck
2024-08-15  3:10     ` Yunsheng Lin
2024-08-15 15:03       ` Alexander Duyck
2024-08-16 11:55         ` Yunsheng Lin [this message]
2024-08-19 16:00           ` Alexander Duyck
2024-08-08 12:37 ` [PATCH net-next v13 08/14] mm: page_frag: some minor refactoring before adding new API Yunsheng Lin
2024-08-14 17:54   ` Alexander H Duyck
2024-08-15  3:04     ` Yunsheng Lin
2024-08-15 15:09       ` Alexander Duyck
2024-08-16 11:58         ` Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 09/14] mm: page_frag: use __alloc_pages() to replace alloc_pages_node() Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 10/14] net: rename skb_copy_to_page_nocache() helper Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 11/14] mm: page_frag: introduce prepare/probe/commit API Yunsheng Lin
2024-08-14 21:00   ` Alexander H Duyck
2024-08-15  3:05     ` Yunsheng Lin
2024-08-15 15:25       ` Alexander Duyck
2024-08-16 12:01         ` Yunsheng Lin
2024-08-19 15:52           ` Alexander Duyck
2024-08-20 13:08             ` Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 12/14] net: replace page_frag with page_frag_cache Yunsheng Lin
2024-08-14 22:01   ` Alexander H Duyck
2024-08-18 14:17     ` Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 13/14] mm: page_frag: update documentation for page_frag Yunsheng Lin
2024-08-08 12:37 ` [PATCH net-next v13 14/14] mm: page_frag: add an entry in MAINTAINERS " Yunsheng Lin
2024-08-13 11:30 ` [PATCH net-next v13 00/14] Replace page_frag with page_frag_cache for sk_page_frag() Yunsheng Lin
2024-08-13 15:11   ` Alexander Duyck
2024-08-14 11:55     ` 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=1a6aab37-2783-45a2-8edd-0990b211ac2d@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

all inboxes | Powered by JetHome®