From: Jason Wang <jasowang@redhat.com>
To: Barry Song <21cnbao@gmail.com>
Cc: "Tetsuo Handa" <penguin-kernel@i-love.sakura.ne.jp>,
akpm@linux-foundation.org, linux-mm@kvack.org,
42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com,
hch@infradead.org, iamjoonsoo.kim@lge.com, lstoakes@gmail.com,
mhocko@suse.com, penberg@kernel.org, rientjes@google.com,
roman.gushchin@linux.dev, torvalds@linux-foundation.org,
urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz,
virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Maxime Coquelin" <maxime.coquelin@redhat.com>,
"Yongji Xie" <xieyongji@bytedance.com>
Subject: Re: [PATCH RFT v2 1/4] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL
Date: Mon, 5 Aug 2024 16:19:07 +0800 [thread overview]
Message-ID: <CACGkMEvjCZW65CssoBseZJg1R-eobb4Tvdwik8yhLyGUqm1OxA@mail.gmail.com> (raw)
In-Reply-To: <CAGsJ_4yJ1XO0_9OUW+jhosi02=6bC6yPFhRQ=P5tSckikSV3bg@mail.gmail.com>
On Mon, Aug 5, 2024 at 9:32 AM Barry Song <21cnbao@gmail.com> wrote:
>
> On Thu, Aug 1, 2024 at 2:37 PM Jason Wang <jasowang@redhat.com> wrote:
> >
> > On Wed, Jul 31, 2024 at 6:21 PM Tetsuo Handa
> > <penguin-kernel@i-love.sakura.ne.jp> wrote:
> > >
> > > On 2024/07/31 14:05, Barry Song wrote:
> > > > Jason,
> > > > Thank you very much. Also, Tetsuo reminded me that kmalloc_array() might be
> > > > problematic if the count is too large:
> > > > pages = kmalloc_array(count, sizeof(*pages), GFP_KERNEL | __GFP_NOFAIL);
> > >
> > > If "count" is guaranteed to be count <= 16, this might be tolerable.
> >
> > It's not unfortunately, the maximum bounce buffer size is:
> >
> > #define VDUSE_MAX_BOUNCE_SIZE (1024 * 1024 * 1024)
> >
> > >
> > > Consider a situation where current thread was chosen as an global OOM victim.
> > > Trying to allocate "count" pages using
> > >
> > > for (i = 0; i < count; i++)
> > > pages[i] = alloc_page(GFP_KERNEL | __GFP_NOFAIL);
> > >
> > > is not good.
> >
> > Right, I wonder if we need to add a shrink to reclaim the pages that
> > belong to VDUSE bounce pages.
> >
> > >
> > > >
> > > > You might want to consider using vmalloc_array() or kvmalloc_array() instead
> > > > when you send a new version.
> > >
> > > There is a limitation at https://elixir.bootlin.com/linux/v6.11-rc1/source/mm/page_alloc.c#L3033
> > > that you must satisfy count <= PAGE_SIZE * 2 / sizeof(*pages) if you use __GFP_NOFAIL.
> > >
> > > But as already explained above, allocating 1024 pages (assuming PAGE_SIZE is 4096 and
> > > pointer size is 8) when current thread was chosen as an OOM victim is not recommended.
> > > You should implement proper error handling instead of using __GFP_NOFAIL if count can
> > > become large.
> >
> > I think I need to consider a way to avoid __GFP_NOFAIL. A easy way is
> > not to free the kernel bounce pages, then we don't need to allocate
> > them again.
>
> Let's try to do a fix for this patch as we are waiting for your official patch
> in mm.
Will post this soon. One note here is that I don't have handy
usersapce that uses userspace bounce pages (neither libvduse nor DPDK
did that).
I hope YongJi can review and give a test on that.
Thanks
>
> I guess, further optimization can be a separate patch later in the driver's
> tree :-)
>
> >
> > Thanks
> >
> > >
> > >
> >
>
next prev parent reply other threads:[~2024-08-05 8:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 0:01 [PATCH v2 0/4] mm: clarify nofail memory allocation Barry Song
2024-07-31 0:01 ` [PATCH RFT v2 1/4] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL Barry Song
2024-07-31 3:09 ` Jason Wang
2024-07-31 3:15 ` Barry Song
2024-07-31 3:58 ` Jason Wang
2024-07-31 4:11 ` Barry Song
2024-07-31 4:13 ` Jason Wang
2024-07-31 5:05 ` Barry Song
2024-07-31 10:20 ` Tetsuo Handa
2024-08-01 2:37 ` Jason Wang
2024-08-05 1:32 ` Barry Song
2024-08-05 8:19 ` Jason Wang [this message]
2024-08-01 2:30 ` Jason Wang
2024-07-31 0:01 ` [PATCH v2 2/4] mm: Document __GFP_NOFAIL must be blockable Barry Song
2024-07-31 10:18 ` Vlastimil Babka
2024-07-31 16:26 ` Christoph Hellwig
2024-07-31 0:01 ` [PATCH v2 3/4] mm: BUG_ON to avoid NULL deference while __GFP_NOFAIL fails Barry Song
2024-07-31 7:11 ` Michal Hocko
2024-07-31 10:29 ` Vlastimil Babka
2024-07-31 10:44 ` Tetsuo Handa
2024-07-31 10:48 ` Vlastimil Babka
2024-07-31 10:57 ` Barry Song
2024-07-31 16:28 ` Christoph Hellwig
2024-07-31 0:01 ` [PATCH v2 4/4] mm: prohibit NULL deference exposed for unsupported non-blockable __GFP_NOFAIL Barry Song
2024-07-31 7:15 ` Michal Hocko
2024-07-31 10:55 ` Vlastimil Babka
2024-07-31 11:08 ` Barry Song
2024-07-31 11:31 ` Michal Hocko
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=CACGkMEvjCZW65CssoBseZJg1R-eobb4Tvdwik8yhLyGUqm1OxA@mail.gmail.com \
--to=jasowang@redhat.com \
--cc=21cnbao@gmail.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=eperezma@redhat.com \
--cc=hailong.liu@oppo.com \
--cc=hch@infradead.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=maxime.coquelin@redhat.com \
--cc=mhocko@suse.com \
--cc=mst@redhat.com \
--cc=penberg@kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=torvalds@linux-foundation.org \
--cc=urezki@gmail.com \
--cc=v-songbaohua@oppo.com \
--cc=vbabka@suse.cz \
--cc=virtualization@lists.linux.dev \
--cc=xieyongji@bytedance.com \
--cc=xuanzhuo@linux.alibaba.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