From: Yunsheng Lin <yunshenglin0825@gmail.com>
To: Haiyang Zhang <haiyangz@microsoft.com>,
linux-hyperv@vger.kernel.org, akpm@linux-foundation.org,
linux-mm@kvack.org
Cc: decui@microsoft.com, kys@microsoft.com, paulros@microsoft.com,
olaf@aepfle.de, vkuznets@redhat.com, davem@davemloft.net,
wei.liu@kernel.org, longli@microsoft.com,
linux-kernel@vger.kernel.org, linyunsheng@huawei.com,
stable@vger.kernel.org, netdev@vger.kernel.org,
Alexander Duyck <alexander.duyck@gmail.com>
Subject: Re: [PATCH] mm: page_frag: Fix refill handling in __page_frag_alloc_align()
Date: Sat, 1 Mar 2025 21:49:55 +0800 [thread overview]
Message-ID: <cc3034c6-2589-4e9a-97af-a7879998d7d8@gmail.com> (raw)
In-Reply-To: <1740794613-30500-1-git-send-email-haiyangz@microsoft.com>
+cc netdev ML & Alexander
On 3/1/2025 10:03 AM, Haiyang Zhang wrote:
> In commit 8218f62c9c9b ("mm: page_frag: use initial zero offset for
> page_frag_alloc_align()"), the check for fragsz is moved earlier.
> So when the cache is used up, and if the fragsz > PAGE_SIZE, it won't
> try to refill, and just return NULL.
> I tested it with fragsz:8192, cache-size:32768. After the initial four
> successful allocations, it failed, even there is plenty of free memory
> in the system.
Hi, Haiyang
It seems the PAGE_SIZE is 4K for the tested system?
Which drivers or subsystems are passing the fragsz being bigger than
PAGE_SIZE to page_frag_alloc_align() related API?
> To fix, revert the refill logic like before: the refill is attempted
> before the check & return NULL.
page_frag API is not really for allocating memory being bigger than
PAGE_SIZE as __page_frag_cache_refill() will not try hard enough to
allocate order 3 compound page when calling __alloc_pages() and will
fail back to allocate base page as the discussed in below:
https://lore.kernel.org/all/ead00fb7-8538-45b3-8322-8a41386e7381@huawei.com/
>
> Cc: linyunsheng@huawei.com
> Cc: stable@vger.kernel.org
> Fixes: 8218f62c9c9b ("mm: page_frag: use initial zero offset for page_frag_alloc_align()")
> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
> ---
> mm/page_frag_cache.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c
> index d2423f30577e..82935d7e53de 100644
> --- a/mm/page_frag_cache.c
> +++ b/mm/page_frag_cache.c
> @@ -119,19 +119,6 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc,
> size = PAGE_SIZE << encoded_page_decode_order(encoded_page);
> offset = __ALIGN_KERNEL_MASK(nc->offset, ~align_mask);
> if (unlikely(offset + fragsz > size)) {
> - if (unlikely(fragsz > PAGE_SIZE)) {
> - /*
> - * The caller is trying to allocate a fragment
> - * with fragsz > PAGE_SIZE but the cache isn't big
> - * enough to satisfy the request, this may
> - * happen in low memory conditions.
> - * We don't release the cache page because
> - * it could make memory pressure worse
> - * so we simply return NULL here.
> - */
> - return NULL;
> - }
> -
> page = encoded_page_decode_page(encoded_page);
>
> if (!page_ref_sub_and_test(page, nc->pagecnt_bias))
> @@ -149,6 +136,19 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc,
> /* reset page count bias and offset to start of new frag */
> nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
> offset = 0;
> +
> + if (unlikely(fragsz > size)) {
> + /*
> + * The caller is trying to allocate a fragment
> + * with fragsz > size but the cache isn't big
> + * enough to satisfy the request, this may
> + * happen in low memory conditions.
> + * We don't release the cache page because
> + * it could make memory pressure worse
> + * so we simply return NULL here.
> + */
> + return NULL;
> + }
> }
>
> nc->pagecnt_bias--;
next prev parent reply other threads:[~2025-03-01 13:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 2:03 Haiyang Zhang
2025-03-01 13:49 ` Yunsheng Lin [this message]
2025-03-01 17:00 ` [EXTERNAL] " Haiyang Zhang
2025-03-01 23:16 ` Haiyang Zhang
2025-03-02 2:22 ` 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=cc3034c6-2589-4e9a-97af-a7879998d7d8@gmail.com \
--to=yunshenglin0825@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linyunsheng@huawei.com \
--cc=longli@microsoft.com \
--cc=netdev@vger.kernel.org \
--cc=olaf@aepfle.de \
--cc=paulros@microsoft.com \
--cc=stable@vger.kernel.org \
--cc=vkuznets@redhat.com \
--cc=wei.liu@kernel.org \
/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