From: Jason Wang <jasowang@redhat.com>
To: Yongji Xie <xieyongji@bytedance.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Eugenio Perez Martin <eperezma@redhat.com>,
virtualization@lists.linux.dev,
linux-kernel <linux-kernel@vger.kernel.org>,
21cnbao@gmail.com, penguin-kernel@i-love.sakura.ne.jp,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: Re: [PATCH] vduse: avoid using __GFP_NOFAIL
Date: Mon, 12 Aug 2024 14:59:42 +0800 [thread overview]
Message-ID: <CACGkMEs1EG=1UJNJ9fuN3rpq0ruQE7imhRurq4o_7pjSgvApXQ@mail.gmail.com> (raw)
In-Reply-To: <CACycT3u-v+XkWzSPq39Mk9sdQftuNZvZqZyzDvhTecH3uyuk8w@mail.gmail.com>
On Thu, Aug 8, 2024 at 7:09 PM Yongji Xie <xieyongji@bytedance.com> wrote:
>
> On Thu, Aug 8, 2024 at 1:50 PM Jason Wang <jasowang@redhat.com> wrote:
> >
> > On Wed, Aug 7, 2024 at 2:54 PM Yongji Xie <xieyongji@bytedance.com> wrote:
> > >
> > > On Wed, Aug 7, 2024 at 12:38 PM Jason Wang <jasowang@redhat.com> wrote:
> > > >
> > > > On Wed, Aug 7, 2024 at 11:13 AM Yongji Xie <xieyongji@bytedance.com> wrote:
> > > > >
> > > > > On Wed, Aug 7, 2024 at 10:39 AM Jason Wang <jasowang@redhat.com> wrote:
> > > > > >
> > > > > > On Tue, Aug 6, 2024 at 11:10 AM Yongji Xie <xieyongji@bytedance.com> wrote:
> > > > > > >
> > > > > > > On Tue, Aug 6, 2024 at 10:28 AM Jason Wang <jasowang@redhat.com> wrote:
> > > > > > > >
> > > > > > > > On Mon, Aug 5, 2024 at 6:42 PM Yongji Xie <xieyongji@bytedance.com> wrote:
> > > > > > > > >
> > > > > > > > > On Mon, Aug 5, 2024 at 4:24 PM Jason Wang <jasowang@redhat.com> wrote:
> > > > > > > > > >
> > > > > > > > > > On Mon, Aug 5, 2024 at 4:21 PM Jason Wang <jasowang@redhat.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Barry said [1]:
> > > > > > > > > > >
> > > > > > > > > > > """
> > > > > > > > > > > mm doesn't support non-blockable __GFP_NOFAIL allocation. Because
> > > > > > > > > > > __GFP_NOFAIL without direct reclamation may just result in a busy
> > > > > > > > > > > loop within non-sleepable contexts.
> > > > > > > > > > > ""“
> > > > > > > > > > >
> > > > > > > > > > > Unfortuantely, we do that under read lock. A possible way to fix that
> > > > > > > > > > > is to move the pages allocation out of the lock into the caller, but
> > > > > > > > > > > having to allocate a huge number of pages and auxiliary page array
> > > > > > > > > > > seems to be problematic as well per Tetsuon [2]:
> > > > > > > > > > >
> > > > > > > > > > > """
> > > > > > > > > > > You should implement proper error handling instead of using
> > > > > > > > > > > __GFP_NOFAIL if count can become large.
> > > > > > > > > > > """
> > > > > > > > > > >
> > > > > > > > >
> > > > > > > > > I think the problem is it's hard to do the error handling in
> > > > > > > > > fops->release() currently.
> > > > > > > >
> > > > > > > > vduse_dev_dereg_umem() should be the same, it's very hard to allow it to fail.
> > > > > > > >
> > > > > > > > >
> > > > > > > > > So can we temporarily hold the user page refcount, and release it when
> > > > > > > > > vduse_dev_open()/vduse_domain_release() is executed. The kernel page
> > > > > > > > > allocation and memcpy can be done in vduse_dev_open() which allows
> > > > > > > > > some error handling.
> > > > > > > >
> > > > > > > > Just to make sure I understand this, the free is probably not the big
> > > > > > > > issue but the allocation itself.
> > > > > > > >
> > > > > > >
> > > > > > > Yes, so defer the allocation might be a solution.
> > > > > >
> > > > > > Would you mind posting a patch for this?
> > > > > >
> > > > > > >
> > > > > > > > And if we do the memcpy() in open(), it seems to be a subtle userspace
> > > > > > > > noticeable change? (Or I don't get how copying in vduse_dev_open() can
> > > > > > > > help here).
> > > > > > > >
> > > > > > >
> > > > > > > Maybe we don't need to do the copy in open(). We can hold the user
> > > > > > > page refcount until the inflight I/O is completed. That means the
> > > > > > > allocation of new kernel pages can be done in
> > > > > > > vduse_domain_map_bounce_page() and the release of old user pages can
> > > > > > > be done in vduse_domain_unmap_bounce_page().
> > > > > >
> > > > > > This seems to be a subtle userspace noticeable behaviour?
> > > > > >
> > > > >
> > > > > Yes, userspace needs to ensure that it does not reuse the old user
> > > > > pages for other purposes before vduse_dev_dereg_umem() returns
> > > > > successfully. The vduse_dev_dereg_umem() will only return successfully
> > > > > when there is no inflight I/O which means we don't need to allocate
> > > > > extra kernel pages to store data. If we can't accept this, then your
> > > > > current patch might be the most suitable.
> > > >
> > > > It might be better to not break.
> > > >
> > > > Actually during my testing, the read_lock in the do_bounce path slows
> > > > down the performance. Remove read_lock or use rcu_read_lock() to give
> > > > 20% improvement of PPS.
> > > >
> > >
> > > Looks like rcu_read_lock() should be OK here.
> >
> > The tricky part is that we may still end up behaviour changes (or lose
> > some of the synchronization between kernel and bounce pages):
> >
> > RCU allows the read to be executed in parallel with the writer. So
> > bouncing could be done in parallel with
> > vduse_domain_add_user_bounce_pages(), there would be a race in two
> > memcpy.
> >
>
> Hmm...this is a problem. We may still need some userspace noticeable
> behaviour, e.g. only allowing reg_umem/dereg_umem when the device is
> not started.
Exactly, maybe have a new userspace flag.
Thanks
>
> Thanks,
> Yongji
>
next prev parent reply other threads:[~2024-08-12 7:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 8:21 Jason Wang
2024-08-05 8:23 ` Jason Wang
2024-08-05 10:42 ` Yongji Xie
2024-08-06 2:28 ` Jason Wang
2024-08-06 3:10 ` Yongji Xie
[not found] ` <CACGkMEue9RU+MMgOC0t4Yuk5wRHfTdnJeZZs38g2h+gyZv+3VQ@mail.gmail.com>
[not found] ` <CACycT3sHT-izwAKzxAWPbqGFgyf82WxkHHOrp1SjWa+HE01mCg@mail.gmail.com>
[not found] ` <CACGkMEvsMQS-5Oy7rTyA5a2u1xYRf0beBHbZ16geHJCZTE0jLw@mail.gmail.com>
[not found] ` <CACycT3sfUhz1PjK3Q=pA7GEm7=fsL0XT16ccwCQ2m2LF+TTD7Q@mail.gmail.com>
[not found] ` <CACGkMEu+RrD2JdO=F9BySwhVY5uPr6kKWWdkcdG4XX6GN5b=Bg@mail.gmail.com>
[not found] ` <CACycT3u-v+XkWzSPq39Mk9sdQftuNZvZqZyzDvhTecH3uyuk8w@mail.gmail.com>
2024-08-12 6:59 ` Jason Wang [this message]
2024-08-05 8:25 ` Michael S. Tsirkin
2024-08-06 2:26 ` Jason Wang
2024-08-06 2:30 ` Barry Song
[not found] ` <CACycT3uM1jSdqFT0LGqy1zXZkWF8BNQN=8EMKYMoyP_wjRtsng@mail.gmail.com>
[not found] ` <CACGkMEtYE1OY+okxHAj=cVfW-Qz45an28oO=Wv15yOtpD6UqdQ@mail.gmail.com>
[not found] ` <CACycT3vAv1K0yBKgc_8GBLpEPwASTCCPZYAxMyUROQsyntQdOw@mail.gmail.com>
2024-08-12 7:00 ` Jason Wang
2024-08-12 7:21 ` Yongji Xie
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='CACGkMEs1EG=1UJNJ9fuN3rpq0ruQE7imhRurq4o_7pjSgvApXQ@mail.gmail.com' \
--to=jasowang@redhat.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=eperezma@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maxime.coquelin@redhat.com \
--cc=mst@redhat.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--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