From: Haiyang Zhang <haiyangz@microsoft.com>
To: Yunsheng Lin <linyunsheng@huawei.com>,
"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"corbet@lwn.net" <corbet@lwn.net>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>,
KY Srinivasan <kys@microsoft.com>,
Paul Rosswurm <paulros@microsoft.com>,
"olaf@aepfle.de" <olaf@aepfle.de>,
"vkuznets@redhat.com" <vkuznets@redhat.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"wei.liu@kernel.org" <wei.liu@kernel.org>,
Long Li <longli@microsoft.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [EXTERNAL] Re: [PATCH 1/2] mm: page_frag: Check fragsz at the beginning of __page_frag_alloc_align()
Date: Wed, 16 Apr 2025 14:11:58 +0000 [thread overview]
Message-ID: <MN0PR21MB3437AFFB3A7205C994F5551CCABD2@MN0PR21MB3437.namprd21.prod.outlook.com> (raw)
In-Reply-To: <d06a75d7-c503-4aa1-a846-d23ef5c48d3c@huawei.com>
> -----Original Message-----
> From: Yunsheng Lin <linyunsheng@huawei.com>
> Sent: Wednesday, April 16, 2025 3:38 AM
> To: Haiyang Zhang <haiyangz@microsoft.com>; linux-hyperv@vger.kernel.org;
> akpm@linux-foundation.org; corbet@lwn.net; linux-mm@kvack.org; linux-
> doc@vger.kernel.org
> Cc: Dexuan Cui <decui@microsoft.com>; KY Srinivasan <kys@microsoft.com>;
> Paul Rosswurm <paulros@microsoft.com>; olaf@aepfle.de;
> vkuznets@redhat.com; davem@davemloft.net; wei.liu@kernel.org; Long Li
> <longli@microsoft.com>; linux-kernel@vger.kernel.org
> Subject: [EXTERNAL] Re: [PATCH 1/2] mm: page_frag: Check fragsz at the
> beginning of __page_frag_alloc_align()
>
> On 2025/4/4 5:21, Haiyang Zhang wrote:
> > Frag allocator is not designed for fragsz > PAGE_SIZE. So, check and
> return
> > the error at the beginning of __page_frag_alloc_align(), instead of
> > succeed for a few times, then fail due to not refilling the cache.
> >
> > Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
> > ---
> > mm/page_frag_cache.c | 22 +++++++++-------------
> > 1 file changed, 9 insertions(+), 13 deletions(-)
> >
> > diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c
> > index d2423f30577e..d6bf022087e7 100644
> > --- a/mm/page_frag_cache.c
> > +++ b/mm/page_frag_cache.c
> > @@ -98,6 +98,15 @@ void *__page_frag_alloc_align(struct page_frag_cache
> *nc,
> > unsigned int size, offset;
> > struct page *page;
> >
> > + if (unlikely(fragsz > PAGE_SIZE)) {
> > + /*
> > + * The caller is trying to allocate a fragment
> > + * with fragsz > PAGE_SIZE which is not supported
> > + * by design. So we simply return NULL here.
> > + */
> > + return NULL;
> > + }
>
> The checking is done at below to avoid doing the checking for the
> likely case of cache being enough as the frag API is mostly used
> to allocate small memory.
>
> And it seems my recent refactoring to frag API have made two
> frag API misuse more obvious if I recalled it correctly. If more
> explicit about that for all the codepath is really helpful, perhaps
> VM_BUG_ON() is an option to make it more explicit while avoiding
> the checking as much as possible.
Thanks, I will use VM_BUG_ON() instead of a checking here. Also, will
keep the checking below unchanged.
> > +
> > if (unlikely(!encoded_page)) {
> > refill:
> > page = __page_frag_cache_refill(nc, gfp_mask);
> > @@ -119,19 +128,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))
next prev parent reply other threads:[~2025-04-16 14:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 21:21 [PATCH 0/2] mm: Explicitly check & doc fragsz limit Haiyang Zhang
2025-04-03 21:21 ` [PATCH 1/2] mm: page_frag: Check fragsz at the beginning of __page_frag_alloc_align() Haiyang Zhang
2025-04-16 7:37 ` Yunsheng Lin
2025-04-16 14:11 ` Haiyang Zhang [this message]
2025-04-03 21:21 ` [PATCH 2/2] docs/mm: Specify page frag size is not bigger than PAGE_SIZE Haiyang Zhang
2025-04-15 21:40 ` [PATCH 0/2] mm: Explicitly check & doc fragsz limit Haiyang Zhang
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=MN0PR21MB3437AFFB3A7205C994F5551CCABD2@MN0PR21MB3437.namprd21.prod.outlook.com \
--to=haiyangz@microsoft.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-doc@vger.kernel.org \
--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=olaf@aepfle.de \
--cc=paulros@microsoft.com \
--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